Skip to content

Commit

Permalink
Merge branch 'develop' into etna-rosetta
Browse files Browse the repository at this point in the history
Conflicts:
	etna/records/tests/test_urls.py

Changes to be committed:
	modified:   .platform.app.yaml
	modified:   config/settings/base.py
	modified:   config/settings/dev.py
	new file:   config/settings/util.py
	modified:   etna/ciim/tests/test_utils.py
	modified:   etna/collections/tests/test_models.py
	modified:   etna/core/tests/test_decorators.py
	modified:   etna/core/tests/test_middleware.py
	modified:   etna/records/tests/test_blocks.py
	modified:   etna/records/tests/test_models.py
	modified:   etna/records/tests/test_urls.py
	modified:   etna/records/tests/test_views.py
  • Loading branch information
TNA-Allan committed Jan 3, 2024
2 parents 0c5dea6 + d36f39c commit abcc099
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 101 deletions.
6 changes: 3 additions & 3 deletions .platform.app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ name: app
# in multiple versions. Check the Python documentation
# (https://docs.platform.sh/languages/python.html#supported-versions)
# to find the supported versions for the 'python' type.
type: 'python:3.11'
type: 'python:3.12'

variables:
env:
DJANGO_SETTINGS_MODULE: 'config.settings.platform'
# pip
POETRY_VIRTUALENVS_IN_PROJECT: true
POETRY_VIRTUALENVS_CREATE: true
POETRY_VERSION: 1.5.1
POETRY_VERSION: 1.6.1

# The size of the persistent disk of the application (in MB).
disk: 2048
Expand All @@ -35,7 +35,7 @@ hooks:
curl -sS https://platform.sh/cli/installer | php
# Download the latest version of pip
python3.11 -m pip install --upgrade pip
python3.12 -m pip install --upgrade pip
# Install and configure Poetry
# Set user to false to install Poetry globally
Expand Down
6 changes: 3 additions & 3 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"""
import os

from distutils.sysconfig import get_python_lib
from distutils.util import strtobool
from sysconfig import get_path

import sentry_sdk

from sentry_sdk.integrations.django import DjangoIntegration

from ..versioning import get_git_sha
from .util import strtobool

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -110,7 +110,7 @@
"DIRS": [
os.path.join(BASE_DIR, "templates"),
os.path.join(
get_python_lib(), "nationalarchives-frontend-django/templates"
get_path("platlib"), "nationalarchives-frontend-django/templates"
),
],
"APP_DIRS": True,
Expand Down
3 changes: 1 addition & 2 deletions config/settings/dev.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import logging
import os

from distutils.util import strtobool

from .base import * # noqa: F401
from .util import strtobool

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = strtobool(os.getenv("DEBUG", "True")) # noqa: F405
Expand Down
13 changes: 13 additions & 0 deletions config/settings/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def strtobool(val):
"""Convert a string representation of truth to true (1) or false (0).
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return 1
elif val in ("n", "no", "f", "false", "off", "0"):
return 0
else:
raise ValueError("invalid truth value %r" % (val,))
24 changes: 12 additions & 12 deletions etna/ciim/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_test(self):

stripped_markup = format_description_markup(markup)

self.assertEquals(
self.assertEqual(
'<span><a href="/catalogue/id/C11996672/">link text</a></span>',
stripped_markup,
)
Expand All @@ -124,7 +124,7 @@ def test_no_links(self):

stripped_markup = format_description_markup(markup)

self.assertEquals("<span/>", stripped_markup)
self.assertEqual("<span/>", stripped_markup)

def test_multiple_links(self):
markup = (
Expand All @@ -136,7 +136,7 @@ def test_multiple_links(self):

stripped_markup = format_description_markup(markup)

self.assertEquals(
self.assertEqual(
(
"<span>"
'<a href="/catalogue/id/C11996672/">link text one</a>'
Expand All @@ -155,7 +155,7 @@ def test_external_link(self):

stripped_markup = format_description_markup(markup)

self.assertEquals(
self.assertEqual(
("<span>" '<a href="http://example.com/">link text one</a>' "</span>"),
stripped_markup,
)
Expand All @@ -166,7 +166,7 @@ def test_invalid_link(self):

stripped_markup = format_description_markup(markup)

self.assertEquals(
self.assertEqual(
("<span></span>"),
stripped_markup,
)
Expand Down Expand Up @@ -327,46 +327,46 @@ def test_none(self):

index = convert_sort_key_to_index(sort)

self.assertEquals(index, 0)
self.assertEqual(index, 0)

def test_empty_string(self):
sort = None

index = convert_sort_key_to_index(sort)

self.assertEquals(index, 0)
self.assertEqual(index, 0)

def test_converts_sort_key_with_leading_zero(self):
sort = "01"

index = convert_sort_key_to_index(sort)

self.assertEquals(index, 0)
self.assertEqual(index, 0)

def test_converts_sort_key_at_three_digit_boundary(self):
sort = "31000"

index = convert_sort_key_to_index(sort)

self.assertEquals(index, 999)
self.assertEqual(index, 999)

def test_converts_sort_key_at_four_digit_boundary(self):
sort = "31001"

index = convert_sort_key_to_index(sort)

self.assertEquals(index, 1000)
self.assertEqual(index, 1000)

def test_index_is_zero_for_invalid_sort_key(self):
sort = "10000"

index = convert_sort_key_to_index(sort)

self.assertEquals(index, 0)
self.assertEqual(index, 0)

def test_index_is_zero_for_non_int_sort_key(self):
sort = "NaN"

index = convert_sort_key_to_index(sort)

self.assertEquals(index, 0)
self.assertEqual(index, 0)
30 changes: 10 additions & 20 deletions etna/collections/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def setUp(self):
root_page.add_child(instance=self.topic_explorer_index_page)

def test_no_child_pages(self):
self.assertEquals(
self.topic_explorer_index_page.topic_explorer_pages.count(), 0
)
self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)

def test_unpublish_page_excluded(self):
unpublished_topic_page = TopicExplorerPage(
Expand All @@ -33,9 +31,7 @@ def test_unpublish_page_excluded(self):
self.topic_explorer_index_page.add_child(instance=unpublished_topic_page)
unpublished_topic_page.unpublish()

self.assertEquals(
self.topic_explorer_index_page.topic_explorer_pages.count(), 0
)
self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)

@unittest.skip(
"Disabled test due to all child pages on home being private during beta."
Expand All @@ -47,19 +43,15 @@ def test_private_page_excluded(self):
self.topic_explorer_index_page.add_child(instance=private_topic_page)
PageViewRestriction.objects.create(page=private_topic_page)

self.assertEquals(
self.topic_explorer_index_page.topic_explorer_pages.count(), 0
)
self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)

def test_published_public_pages(self):
topic_page = TopicExplorerPage(
title="Topic Page", intro="test", teaser_text="test"
)
self.topic_explorer_index_page.add_child(instance=topic_page)

self.assertEquals(
self.topic_explorer_index_page.topic_explorer_pages.count(), 1
)
self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 1)

def test_published_time_period_pages_excluded(self):
topic_page = TimePeriodExplorerPage(
Expand All @@ -71,9 +63,7 @@ def test_published_time_period_pages_excluded(self):
)
self.topic_explorer_index_page.add_child(instance=topic_page)

self.assertEquals(
self.topic_explorer_index_page.topic_explorer_pages.count(), 0
)
self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)


class TestTopicExplorerPage(TestCase):
Expand Down Expand Up @@ -158,7 +148,7 @@ def setUp(self):
root_page.add_child(instance=self.time_period_explorer_index_page)

def test_no_child_pages(self):
self.assertEquals(
self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)

Expand All @@ -173,7 +163,7 @@ def test_unpublish_page_excluded(self):
self.time_period_explorer_index_page.add_child(instance=unpublished_topic_page)
unpublished_topic_page.unpublish()

self.assertEquals(
self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)

Expand All @@ -191,7 +181,7 @@ def test_private_page_excluded(self):
self.time_period_explorer_index_page.add_child(instance=private_topic_page)
PageViewRestriction.objects.create(page=private_topic_page)

self.assertEquals(
self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)

Expand All @@ -205,7 +195,7 @@ def test_published_public_pages(self):
)
self.time_period_explorer_index_page.add_child(instance=topic_page)

self.assertEquals(
self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 1
)

Expand All @@ -215,6 +205,6 @@ def test_topic_pages_excluded(self):
)
self.time_period_explorer_index_page.add_child(instance=topic_page)

self.assertEquals(
self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)
4 changes: 2 additions & 2 deletions etna/core/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_allows_request_when_setting_value_is_true_and_authenticated(self):
for url in CONDITIONALLY_PROTECTED_URLS:
with self.subTest(f"URL: {url}"):
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)

@responses.activate
@override_settings(
Expand All @@ -87,4 +87,4 @@ def test_allows_unauthenticated_access_when_setting_value_is_false(self):
for url in CONDITIONALLY_PROTECTED_URLS:
with self.subTest(f"URL: {url}"):
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
14 changes: 7 additions & 7 deletions etna/core/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ class TestMaintenanceMode(TestCase):
@prevent_request_warnings
def test_without_maintenance_mode_ends(self):
response = self.client.get("/")
self.assertEquals(response.status_code, 503)
self.assertEqual(response.status_code, 503)
self.assertNotIn("Retry-After", response.headers)

@prevent_request_warnings
@override_settings(MAINTENENCE_MODE_ENDS="2011-11-04T00:05:23+04:00")
def test_maintenance_mode_ends_with_timezone_info(self):
response = self.client.get("/")
self.assertEquals(response.status_code, 503)
self.assertEquals(
self.assertEqual(response.status_code, 503)
self.assertEqual(
response.headers["Retry-After"], "Thu, 03 Nov 2011 20:05:23 GMT"
)

@prevent_request_warnings
@override_settings(MAINTENENCE_MODE_ENDS="2011-11-04T00:05:23")
def test_maintenance_mode_ends_without_timezone_info(self):
response = self.client.get("/")
self.assertEquals(response.status_code, 503)
self.assertEquals(
self.assertEqual(response.status_code, 503)
self.assertEqual(
response.headers["Retry-After"], "Fri, 04 Nov 2011 00:05:23 GMT"
)

Expand All @@ -40,7 +40,7 @@ def test_maintenance_mode_ends_without_timezone_info(self):
def test_maintenance_mode_bypassed_when_ip_in_allow_list(self, *args):
response = self.client.get("/")

self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)

@prevent_request_warnings
@override_settings(MAINTENENCE_MODE_ALLOW_IPS=["123.4.5.6"])
Expand All @@ -49,7 +49,7 @@ def test_maintenance_mode_enforced_when_ip_not_in_allowed_list(
self, mock_get_client_ip
):
response = self.client.get("/")
self.assertEquals(response.status_code, 503)
self.assertEqual(response.status_code, 503)


class TestInterpretCookiesMiddleware(SimpleTestCase):
Expand Down
2 changes: 1 addition & 1 deletion etna/records/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,4 @@ def test_view_edit_page_with_client_api_exception(self):
reverse("wagtailadmin_pages:edit", args=(self.article_page.id,))
)

self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
4 changes: 2 additions & 2 deletions etna/records/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def test_thumbnail_url(self):
images = Image.search.filter(rid="")
image = images[0]

self.assertEquals(
self.assertEqual(
image.thumbnail_url, "https://media.preview/path/to/thumbnail.jpeg"
)

Expand All @@ -612,7 +612,7 @@ def test_thumbnail_url_fallback(self):
image = images[0]

# Fallback serves image through Wagtail instead of from Client API
self.assertEquals(image.thumbnail_url, "/records/image/path/to/image.jpeg")
self.assertEqual(image.thumbnail_url, "/records/image/path/to/image.jpeg")


@unittest.skip("TODO:Rosetta")
Expand Down
2 changes: 1 addition & 1 deletion etna/records/tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_resolves_iaid(self):
def test_iaid_with_non_standard_prefix(self):
resolver = resolve("/catalogue/id/C123456/")

self.assertEquals(resolver.view_name, "details-page-machine-readable")
self.assertEqual(resolver.view_name, "details-page-machine-readable")
self.assertEqual(resolver.kwargs["id"], "C123456")

def test_resolves_uuid(self):
Expand Down
Loading

0 comments on commit abcc099

Please sign in to comment.