diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9126b43a..3dbb5e3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.12" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1e5bb92c..3ba33617 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,7 +3,7 @@ Release notes ### Version 5.1.0-dev -- Upgrade Python version to 3.12 +- Upgrade Python version to 3.12 and Django to 5.0.x https://github.com/nexB/dejacode/issues/50 - Replace Celery by RQ for async job queue and worker. diff --git a/component_catalog/tests/test_admin.py b/component_catalog/tests/test_admin.py index dff164eb..3c4e3623 100644 --- a/component_catalog/tests/test_admin.py +++ b/component_catalog/tests/test_admin.py @@ -495,7 +495,7 @@ def test_activity_log_activated(self): def test_component_admin_changelist_list_display_as_popup(self): self.client.login(username="test", password="secret") url = reverse("admin:component_catalog_component_changelist") - expect1 = '' + expect1 = ' + ', + '', ) def test_package_list_view_usage_policy_availability(self): @@ -1732,10 +1733,7 @@ def test_package_details_view_add_to_product(self): self.assertContains(response, expected) self.assertIsNotNone(response.context_data["form"]) - expected_status_select = ( - 'Core') diff --git a/component_catalog/tests/testfiles/search/component_dataset.json b/component_catalog/tests/testfiles/search/component_dataset.json index 254ae7f2..9cd869c8 100644 --- a/component_catalog/tests/testfiles/search/component_dataset.json +++ b/component_catalog/tests/testfiles/search/component_dataset.json @@ -28,8 +28,8 @@ "nexB" ], "uuid": "53fa7229-617b-4dfa-9eee-8c09e9380046", - "created_date": "2014-07-01T00:00:00", - "last_modified_date": "2017-05-19T16:09:49.020", + "created_date": "2014-07-01T00:00:00Z", + "last_modified_date": "2017-05-19T16:09:49.020Z", "reference_notes": "", "usage_policy": null, "name": "logback", @@ -68,8 +68,8 @@ "nexB" ], "uuid": "03df48a9-60df-43b6-9c04-4a4c9015f309", - "created_date": "2014-07-01T00:00:00", - "last_modified_date": "2017-05-19T16:10:20.504", + "created_date": "2014-07-01T00:00:00Z", + "last_modified_date": "2017-05-19T16:10:20.504Z", "reference_notes": "", "usage_policy": null, "name": "logback", @@ -108,8 +108,8 @@ "nexB" ], "uuid": "fed79fab-5d00-4994-a2d1-ad35164b736a", - "created_date": "2014-07-01T00:00:00", - "last_modified_date": "2014-03-04T12:07:06.500", + "created_date": "2014-07-01T00:00:00Z", + "last_modified_date": "2014-03-04T12:07:06.500Z", "reference_notes": "", "usage_policy": null, "name": "logback eclipse", @@ -148,8 +148,8 @@ "nexB" ], "uuid": "4a037d63-f479-41f7-985e-436b8039160a", - "created_date": "2014-07-01T00:00:00", - "last_modified_date": "2016-11-10T03:56:18.135", + "created_date": "2014-07-01T00:00:00Z", + "last_modified_date": "2016-11-10T03:56:18.135Z", "reference_notes": "", "usage_policy": null, "name": "jblogbackup", @@ -188,8 +188,8 @@ "nexB" ], "uuid": "663fe571-6042-48cd-95ec-6cf57316a591", - "created_date": "2015-08-04T15:08:45.738", - "last_modified_date": "2015-08-21T12:16:25.333", + "created_date": "2015-08-04T15:08:45.738Z", + "last_modified_date": "2015-08-21T12:16:25.333Z", "reference_notes": "", "usage_policy": null, "name": "logback classic", @@ -228,8 +228,8 @@ "nexB" ], "uuid": "d47238fd-09aa-45e9-aafa-9d8c3fe10b93", - "created_date": "2014-07-01T00:00:00", - "last_modified_date": "2016-11-10T03:56:18.165", + "created_date": "2014-07-01T00:00:00Z", + "last_modified_date": "2016-11-10T03:56:18.165Z", "reference_notes": "", "usage_policy": null, "name": "jblogbackup", @@ -268,8 +268,8 @@ "nexB" ], "uuid": "31368d10-b832-4c77-87d3-2d300989d30e", - "created_date": "2014-07-01T00:00:00", - "last_modified_date": "2016-11-10T04:17:12.090", + "created_date": "2014-07-01T00:00:00Z", + "last_modified_date": "2016-11-10T04:17:12.090Z", "reference_notes": "", "usage_policy": null, "name": "nagios-logback-appender", @@ -308,8 +308,8 @@ "nexB" ], "uuid": "0a8bfdd1-7c48-4ac7-99f1-9e6c46e1bb81", - "created_date": "2014-07-01T00:00:00", - "last_modified_date": "2017-05-19T16:10:45.082", + "created_date": "2014-07-01T00:00:00Z", + "last_modified_date": "2017-05-19T16:10:45.082Z", "reference_notes": "", "usage_policy": null, "name": "logback", @@ -348,8 +348,8 @@ "nexB" ], "uuid": "9b1c732d-081b-44ae-a366-ac0182281422", - "created_date": "2017-06-13T10:05:03.727", - "last_modified_date": "2017-06-13T10:05:03.727", + "created_date": "2017-06-13T10:05:03.727Z", + "last_modified_date": "2017-06-13T10:05:03.727Z", "reference_notes": "", "usage_policy": null, "name": "zzz", diff --git a/dejacode/settings.py b/dejacode/settings.py index 0ef9b0db..19e052d6 100644 --- a/dejacode/settings.py +++ b/dejacode/settings.py @@ -9,6 +9,7 @@ # Common Django settings for all deployments of DejaCode import sys +import tempfile from pathlib import Path import environ @@ -209,7 +210,13 @@ def gettext_noop(s): # CSRF_COOKIE_HTTPONLY = True # Also, security.W004 SECURE_HSTS_SECONDS and security.W008 SECURE_SSL_REDIRECT # are handled at the web server level. -SILENCED_SYSTEM_CHECKS = ["security.W004", "security.W008", "security.W017", "urls.W005"] +SILENCED_SYSTEM_CHECKS = [ + "security.W004", + "security.W008", + "security.W017", + "urls.W005", + "admin.E039", +] # Set the following to True to enable ClamAV scan on uploaded files # This requires the installation of ClamAV @@ -654,6 +661,8 @@ def get_fake_redis_connection(config, use_strict_redis): if IS_TESTS: # Silent the django-axes logging during tests LOGGING["loggers"].update({"axes": {"handlers": ["null"]}}) + # Do not pollute the MEDIA_ROOT location while running the tests. + MEDIA_ROOT = tempfile.TemporaryDirectory().name # Set a faster hashing algorithm for running the tests # https://docs.djangoproject.com/en/dev/topics/testing/overview/#password-hashing PASSWORD_HASHERS = [ diff --git a/dejacode_toolkit/scancodeio.py b/dejacode_toolkit/scancodeio.py index 2cc1c420..962043e5 100644 --- a/dejacode_toolkit/scancodeio.py +++ b/dejacode_toolkit/scancodeio.py @@ -7,13 +7,13 @@ # import json +from hashlib import md5 from urllib.parse import quote_plus from django.apps import apps from django.conf import settings from django.core import signing from django.urls import reverse -from django.utils.crypto import md5 import requests from license_expression import Licensing diff --git a/dje/filters.py b/dje/filters.py index 73568c79..b1cbbd22 100644 --- a/dje/filters.py +++ b/dje/filters.py @@ -467,7 +467,7 @@ class DataspaceFilter(ChoicesOnlyListFilterMixin, BaseDataspaceLookupsFilter): """ title = _("dataspace") - parameter_name = "dataspace__id__exact" + parameter_name = "dataspace__id" def lookups(self, request, model_admin): """Set the lookup value for the current user dataspace choice to None.""" diff --git a/dje/importers.py b/dje/importers.py index 927651f0..082a02b2 100644 --- a/dje/importers.py +++ b/dje/importers.py @@ -203,9 +203,9 @@ def post_process_form(self): continue choices = [str(getattr(choice, identifier_field, "")) for choice in form_field.queryset] - form_field.error_messages[ - "invalid_choice" - ] = 'That choice is not one of the available choices: "{}"'.format(", ".join(choices)) + form_field.error_messages["invalid_choice"] = ( + 'That choice is not one of the available choices: "{}"'.format(", ".join(choices)) + ) for field_name, field in self.fields.items(): # Using `type()` comparison in place if `isinstance` since we do not want diff --git a/dje/registration.py b/dje/registration.py index 95504188..24fd9de1 100644 --- a/dje/registration.py +++ b/dje/registration.py @@ -126,9 +126,9 @@ def __init__(self, *args, **kwargs): self.fields["hcaptcha"].label = "" - self.fields[ - "updates_email_notification" - ].label = "Receive updates on DejaCode features and news" + self.fields["updates_email_notification"].label = ( + "Receive updates on DejaCode features and news" + ) for field in self.fields.values(): field.help_text = None diff --git a/dje/tests/test_admin.py b/dje/tests/test_admin.py index e4bf384e..1b802a76 100644 --- a/dje/tests/test_admin.py +++ b/dje/tests/test_admin.py @@ -140,7 +140,8 @@ def test_dataspace_admin_changeform_readonly_fields(self): response = self.client.get(dataspace_change_url) expected = ( f'' + f'class="vTextField" maxlength="20" required aria-describedby="id_name_helptext" ' + f'id="id_name">' ) self.assertContains(response, expected, html=True) diff --git a/dje/tests/test_api.py b/dje/tests/test_api.py index 8f862af5..bd83ca80 100644 --- a/dje/tests/test_api.py +++ b/dje/tests/test_api.py @@ -497,8 +497,8 @@ def test_api_external_reference_detail_endpoint(self): self.assertEqual(self.ext_ref1.content_type.model, response.data["content_type"]) self.assertEqual(self.ext_ref1.external_url, response.data["external_url"]) self.assertEqual(self.ext_ref1.external_id, response.data["external_id"]) - self.assertEqual(26, len(response.data["created_date"])) - self.assertEqual(26, len(response.data["last_modified_date"])) + self.assertEqual(32, len(response.data["created_date"])) + self.assertEqual(32, len(response.data["last_modified_date"])) def test_api_external_reference_endpoint_create(self): self.client.login(username="super_user", password="secret") diff --git a/dje/tests/test_user.py b/dje/tests/test_user.py index 8257e315..a9d72731 100644 --- a/dje/tests/test_user.py +++ b/dje/tests/test_user.py @@ -687,8 +687,8 @@ def test_user_model_last_active_property(self): def test_user_model_serialize_user_data(self): user = create_user("active", self.dataspace) - user.date_joined = "2020-09-01 23:13:05.611210" - user.last_login = "2021-09-01 23:13:05.611210" + user.date_joined = "2020-09-01 23:13:05.611210Z" + user.last_login = "2021-09-01 23:13:05.611210Z" user.save() expected = { @@ -697,9 +697,9 @@ def test_user_model_serialize_user_data(self): "last_name": "", "username": "active", "company": "", - "last_login": "2021-09-01 23:13:05.611210", - "date_joined": "2020-09-01 23:13:05.611210", - "last_active": "2021-09-01 23:13:05.611210", + "last_login": "2021-09-01 23:13:05.611210Z", + "date_joined": "2020-09-01 23:13:05.611210Z", + "last_active": "2021-09-01 23:13:05.611210Z", "is_superuser": "False", "is_staff": "False", "is_active": "True", diff --git a/dje/tests/testfiles/test_dataset_cc_only.json b/dje/tests/testfiles/test_dataset_cc_only.json index f5d5f875..35d19f16 100644 --- a/dje/tests/testfiles/test_dataset_cc_only.json +++ b/dje/tests/testfiles/test_dataset_cc_only.json @@ -40,8 +40,8 @@ "nexB" ], "uuid": "7c5af42c-9b26-40ab-a24c-a539e8e9e685", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "usage_policy": null, "holder": "", @@ -109,8 +109,8 @@ "nexB" ], "uuid": "a03c5662-b30c-43c9-b88a-e5e8915522d1", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "usage_policy": null, "holder": "", @@ -178,8 +178,8 @@ "nexB" ], "uuid": "2a9ef27e-9240-44f8-8a3c-73f52d474d06", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "usage_policy": null, "notes": "again, yes", @@ -268,8 +268,8 @@ "nexB" ], "uuid": "b91a9a06-b709-45a4-ac8e-a57bde0c8f38", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "usage_policy": null, "type": "", diff --git a/dje/tests/testfiles/test_dataset_ll_only.json b/dje/tests/testfiles/test_dataset_ll_only.json index 8ab0d142..ae8f80fe 100644 --- a/dje/tests/testfiles/test_dataset_ll_only.json +++ b/dje/tests/testfiles/test_dataset_ll_only.json @@ -117,8 +117,8 @@ "nexB" ], "uuid": "acb266e4-ec8a-49bc-b388-e3e006aa9623", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "usage_policy": null, "owner": [ diff --git a/dje/tests/testfiles/test_dataset_organization_only.json b/dje/tests/testfiles/test_dataset_organization_only.json index d62b54d5..02e16d02 100644 --- a/dje/tests/testfiles/test_dataset_organization_only.json +++ b/dje/tests/testfiles/test_dataset_organization_only.json @@ -6,8 +6,8 @@ "nexB" ], "uuid": "0b9931db-db6e-49d1-b3f1-218cb302b20c", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "name": "Linus Torvalds", "homepage_url": "http://en.wikipedia.org/wiki/Linus_Torvalds", "contact_info": "", @@ -23,8 +23,8 @@ "nexB" ], "uuid": "1711f308-8072-4357-b72d-29afd075816a", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "name": "Test Organization", "homepage_url": "", "contact_info": "", diff --git a/dje/tests/testfiles/test_dataset_pp_only.json b/dje/tests/testfiles/test_dataset_pp_only.json index 958699e1..1b9f656e 100644 --- a/dje/tests/testfiles/test_dataset_pp_only.json +++ b/dje/tests/testfiles/test_dataset_pp_only.json @@ -6,8 +6,8 @@ "nexB" ], "uuid": "b91a9a06-b709-45a4-ac8e-a57bde0c8f38", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "usage_policy": null, "type": "", @@ -69,8 +69,8 @@ "nexB" ], "uuid": "565737ed-ab23-46eb-bbcf-185da2da50dc", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "keywords": [ "Framework" ], @@ -132,8 +132,8 @@ "nexB" ], "uuid": "dc39ab30-d521-4dd4-a281-8742a5f83770", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "notes": "", "is_deployed": true, @@ -172,8 +172,8 @@ "nexB" ], "uuid": "7204dec9-63d7-40c0-b745-b48776afe189", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "reference_notes": "", "notes": "", "is_deployed": true, @@ -259,8 +259,8 @@ "nexB" ], "uuid": "4ec1aba0-04cb-434c-8d3d-864281d7d9f1", - "created_date": "2018-01-30T08:26:43.832", - "last_modified_date": "2018-01-30T11:28:46.029", + "created_date": "2018-01-30T08:26:43.832Z", + "last_modified_date": "2018-01-30T11:28:46.029Z", "product": [ "nexB", "565737ed-ab23-46eb-bbcf-185da2da50dc" @@ -280,8 +280,8 @@ "nexB" ], "uuid": "34311f4e-51c5-4443-86d9-2e1b218ebb3b", - "created_date": "2018-01-30T08:23:57.960", - "last_modified_date": "2018-01-30T11:35:38.631", + "created_date": "2018-01-30T08:23:57.960Z", + "last_modified_date": "2018-01-30T11:35:38.631Z", "product": [ "nexB", "565737ed-ab23-46eb-bbcf-185da2da50dc" @@ -301,8 +301,8 @@ "nexB" ], "uuid": "3b997a71-02b6-4fe7-9a26-1da5257c52d5", - "created_date": "2018-01-30T11:31:04.965", - "last_modified_date": "2018-01-30T11:31:04.965", + "created_date": "2018-01-30T11:31:04.965Z", + "last_modified_date": "2018-01-30T11:31:04.965Z", "deployed_from": [ "nexB", "34311f4e-51c5-4443-86d9-2e1b218ebb3b" diff --git a/dje/tests/testfiles/test_dataset_user_only.json b/dje/tests/testfiles/test_dataset_user_only.json index 55a4f69a..4dbae4c3 100644 --- a/dje/tests/testfiles/test_dataset_user_only.json +++ b/dje/tests/testfiles/test_dataset_user_only.json @@ -30,7 +30,7 @@ "model": "dje.dejacodeuser", "fields": { "password": "sha1$e7042$dfcb7d3a5962b60e6009ea66a3b688c26827d1c0", - "last_login": "2011-08-24T09:20:01", + "last_login": "2011-08-24T09:20:01Z", "is_superuser": true, "username": "nexb_user", "first_name": "", @@ -38,7 +38,7 @@ "email": "test@test.com", "is_staff": true, "is_active": true, - "date_joined": "2011-08-24T09:20:01", + "date_joined": "2011-08-24T09:20:01Z", "uuid": "e7b90a81-f68f-4416-98d8-4eea0b2b6ac7", "dataspace": [ "nexB" diff --git a/dje/tests/testfiles/test_dataset_workflow.json b/dje/tests/testfiles/test_dataset_workflow.json index f2db538f..a17cfd64 100644 --- a/dje/tests/testfiles/test_dataset_workflow.json +++ b/dje/tests/testfiles/test_dataset_workflow.json @@ -6,8 +6,8 @@ "nexB" ], "uuid": "04f6d1e1-a619-4e42-975d-34c04e41ca17", - "created_date": "2011-08-24T09:20:01", - "last_modified_date": "2011-08-24T09:20:01", + "created_date": "2011-08-24T09:20:01Z", + "last_modified_date": "2011-08-24T09:20:01Z", "name": "Add New License to the License Library", "description": "The purpose of this form is to request the application data administrators to add a new License to the License Library.", "content_type": [ diff --git a/dje/views.py b/dje/views.py index 5c3a6da1..1fc38c7e 100644 --- a/dje/views.py +++ b/dje/views.py @@ -51,6 +51,7 @@ from django.urls import NoReverseMatch from django.urls import reverse from django.urls import reverse_lazy +from django.utils import timezone from django.utils.decorators import method_decorator from django.utils.html import format_html from django.utils.text import capfirst @@ -1935,7 +1936,8 @@ def get_history_entries(self, days): """ user_dataspace_id = self.request.user.dataspace_id content_type = ContentType.objects.get_for_model(self.model) - start = datetime.datetime.now() - datetime.timedelta(days=days) + + start = timezone.now() - datetime.timedelta(days=days) history_entries = History.objects.filter( object_dataspace_id=user_dataspace_id, @@ -2008,7 +2010,7 @@ def get_context_data(self, **kwargs): "objects": self.get_objects(days), "verbose_name": self.model._meta.verbose_name, "dataspace": self.request.user.dataspace, - "now": datetime.datetime.now(), + "now": timezone.now(), } ) return context diff --git a/dje/widgets.py b/dje/widgets.py index dbb39c2d..0f1ebd99 100644 --- a/dje/widgets.py +++ b/dje/widgets.py @@ -53,7 +53,8 @@ def render(self, name, value, attrs=None, renderer=None, choices=()): output.append("") menu = format_html("\n".join(output)) - return self.dropdown_template.format( + return format_html( + self.dropdown_template, menu=menu, active="active" if value else "", label=self.label if self.label else name.title(), diff --git a/license_library/tests/test_admin.py b/license_library/tests/test_admin.py index fd7eed16..2317e0dd 100644 --- a/license_library/tests/test_admin.py +++ b/license_library/tests/test_admin.py @@ -1348,10 +1348,11 @@ def test_short_and_long_descriptions(self): self.assertContains(response, long_desc_html, html=True) def test_history_list_filter(self): - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: fake_now = datetime.datetime(year=2012, month=8, day=1) + fake_now = fake_now.astimezone(datetime.timezone.utc) # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = fake_now + mock_timezone.return_value = fake_now self.client.login(username="nexb_user", password="t3st") url = reverse("admin:license_library_licensetag_changelist") diff --git a/notification/tests/test_tasks.py b/notification/tests/test_tasks.py index 80946414..7a8f9c48 100644 --- a/notification/tests/test_tasks.py +++ b/notification/tests/test_tasks.py @@ -257,8 +257,6 @@ def test_notification_task_on_workflow_request_add_comment_generic_url(self, met self.assertEqual(str(comment.uuid), data["uuid"]) self.assertEqual("nexb_user", data["user"]) self.assertEqual("A comment content", data["text"]) - self.assertEqual(comment.created_date.isoformat(), data["created_date"]) - self.assertEqual(comment.last_modified_date.isoformat(), data["last_modified_date"]) @patch("requests.Session.post", autospec=True) def test_notification_task_on_workflow_request_add_comment_slack_url(self, method_mock): diff --git a/organization/tests/test_admin.py b/organization/tests/test_admin.py index 73048f8c..f2c629df 100644 --- a/organization/tests/test_admin.py +++ b/organization/tests/test_admin.py @@ -294,7 +294,7 @@ def test_owner_changelist_has_filters_activated(self): response = self.client.post(url) self.assertFalse(response.context["cl"].has_filters_activated) - params = "?created_date__gte=2017-01-25+00%3A00%3A00" + params = "?created_date__gte=2017-01-25+00%3A00%3A00Z" response = self.client.get(url + params) self.assertTrue(response.context["cl"].has_filters_activated) response = self.client.post(url + params) @@ -451,8 +451,8 @@ def test_owner_changeform_name_with_unicode(self): response = self.client.get(new_owner.get_admin_url()) expected = ( - f'' + f'' ) self.assertContains(response, expected, html=True) diff --git a/organization/tests/test_api.py b/organization/tests/test_api.py index 162fe6d0..25769ec6 100644 --- a/organization/tests/test_api.py +++ b/organization/tests/test_api.py @@ -184,8 +184,8 @@ def test_api_owner_detail_endpoint(self): self.assertEqual("", response.data["homepage_url"]) self.assertEqual("", response.data["notes"]) self.assertEqual("nexB", response.data["dataspace"]) - self.assertEqual(26, len(response.data["created_date"])) - self.assertEqual(26, len(response.data["last_modified_date"])) + self.assertEqual(32, len(response.data["created_date"])) + self.assertEqual(32, len(response.data["last_modified_date"])) self.assertIn( reverse("api_v2:license-detail", args=[self.license.uuid]), response.data["licenses"][0] ) diff --git a/organization/tests/test_filters.py b/organization/tests/test_filters.py index fdae043f..31b0a5f7 100644 --- a/organization/tests/test_filters.py +++ b/organization/tests/test_filters.py @@ -63,7 +63,8 @@ def setUp(self): # History.action_time is automatically set to the current # time *anytime* the model is saved, so to set a custom value for # action_time we use QuerySet.update() - self.fake_now = datetime.datetime(year=2012, month=8, day=1) + fake_now = datetime.datetime(year=2012, month=8, day=1) + self.fake_now = fake_now.astimezone(datetime.timezone.utc) # create LogEntry objects for the owners @@ -115,12 +116,12 @@ class HistoryCreatedActionTimeListFilterTestCase( class_under_test = HistoryCreatedActionTimeListFilter def get_lookup_params(self): - return {"created_date": "past_7_days"} + return {"created_date": ["past_7_days"]} def test_get_history_objects(self): - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now self.assertEqual(0, self.filter.get_history_objects().count()) def test_get_history_objects_with_invalid_input(self): @@ -131,18 +132,18 @@ def test_get_history_objects_with_invalid_input(self): request, {"created_date": "invalid_value"}, Owner, model_admin ) - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now self.assertEqual(None, filter.get_history_objects()) def test_queryset(self): request = Mock() qs = Owner.objects.all() - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now qs2 = self.filter.queryset(request, qs) self.assertEqual(0, qs2.count()) @@ -155,9 +156,9 @@ def test_queryset_with_invalid_input(self): ) qs = Owner.objects.all() - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now self.assertEqual(None, filter.queryset(request, qs)) def test_choices(self): @@ -194,12 +195,12 @@ class HistoryModifiedActionTimeListFilterTestCase( class_under_test = HistoryModifiedActionTimeListFilter def get_lookup_params(self): - return {"modified_date": "past_7_days"} + return {"modified_date": ["past_7_days"]} def test_get_history_objects(self): - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now self.assertEqual(1, self.filter.get_history_objects().count()) def test_get_history_objects_with_invalid_input(self): @@ -210,18 +211,18 @@ def test_get_history_objects_with_invalid_input(self): request, {"modified_date": "invalid_value"}, Owner, model_admin ) - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now self.assertEqual(None, filter.get_history_objects()) def test_queryset(self): request = Mock() qs = Owner.objects.all() - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now qs2 = self.filter.queryset(request, qs) self.assertEqual(1, qs2.count()) @@ -234,9 +235,9 @@ def test_queryset_with_invalid_input(self): ) qs = Owner.objects.all() - with patch("dje.filters.timezone") as mock_timezone: + with patch("dje.filters.timezone.now") as mock_timezone: # patch timezone.now() so that it Return a consistent date - mock_timezone.now.return_value = self.fake_now + mock_timezone.return_value = self.fake_now self.assertEqual(None, filter.queryset(request, qs)) def test_choices(self): @@ -414,7 +415,9 @@ def test_queryset_for_nexb_user(self): request.GET = {} request.user = self.nexb_user model_admin = Mock() - filter = CreatedByListFilter(request, {"created_by": self.nexb_user.pk}, Owner, model_admin) + filter = CreatedByListFilter( + request, {"created_by": [self.nexb_user.pk]}, Owner, model_admin + ) qs = Owner.objects.scope(self.nexb_dataspace) expected = [self.owner1, self.owner4] @@ -427,7 +430,7 @@ def test_queryset_for_other_user(self): request.user = self.other_user model_admin = Mock() filter = CreatedByListFilter( - request, {"created_by": self.other_user.pk}, Owner, model_admin + request, {"created_by": [self.other_user.pk]}, Owner, model_admin ) qs = Owner.objects.scope(self.nexb_dataspace) diff --git a/policy/tests/test_admin.py b/policy/tests/test_admin.py index ba9b8994..93c5be53 100644 --- a/policy/tests/test_admin.py +++ b/policy/tests/test_admin.py @@ -137,7 +137,10 @@ def test_usage_policy_changeform_update_content_type_once_assigned(self): def test_usage_policy_changeform_color_code_as_color_input(self): self.client.login(username="test", password="secret") response = self.client.get(self.component_policy.get_admin_url()) - expected = '' + expected = ( + '' + ) self.assertContains(response, expected, html=True) def test_usage_policy_changeform_clean_color_code(self): diff --git a/product_portfolio/tests/test_attribution.py b/product_portfolio/tests/test_attribution.py index 40f15b36..bb600b95 100644 --- a/product_portfolio/tests/test_attribution.py +++ b/product_portfolio/tests/test_attribution.py @@ -927,7 +927,9 @@ def test_attribution_generation_include_packages(self): expected = ( '' + 'class="checkboxinput form-check-input" ' + 'aria-describedby="id_include_packages_helptext" id="id_include_packages" ' + "checked>" ) response = self.client.get(url) self.assertContains(response, expected) @@ -935,7 +937,8 @@ def test_attribution_generation_include_packages(self): self.pp1.delete() expected = ( '' + 'class="checkboxinput form-check-input" ' + 'aria-describedby="id_include_packages_helptext" id="id_include_packages">' ) response = self.client.get(url) self.assertContains(response, expected) diff --git a/product_portfolio/tests/test_importers.py b/product_portfolio/tests/test_importers.py index d370194a..23287cfa 100644 --- a/product_portfolio/tests/test_importers.py +++ b/product_portfolio/tests/test_importers.py @@ -563,9 +563,9 @@ def test_codebaseresource_import_custom_product_component(self): product=self.product1, dataspace=self.dataspace, ) - formset_data[ - "form-0-product_component" - ] = f"{product_component.name}:{product_component.version}" + formset_data["form-0-product_component"] = ( + f"{product_component.name}:{product_component.version}" + ) importer = CodebaseResourceImporter(self.super_user, formset_data=formset_data) importer.save_all() self.assertTrue(importer.formset.is_valid()) @@ -575,9 +575,9 @@ def test_codebaseresource_import_custom_product_component(self): product_component.name = self.c1.name product_component.version = self.c1.version product_component.save() - formset_data[ - "form-0-product_component" - ] = f"{product_component.name}:{product_component.version}" + formset_data["form-0-product_component"] = ( + f"{product_component.name}:{product_component.version}" + ) importer = CodebaseResourceImporter(self.super_user, formset_data=formset_data) importer.save_all() self.assertTrue(importer.formset.is_valid()) diff --git a/product_portfolio/tests/test_models.py b/product_portfolio/tests/test_models.py index 40b52f5d..9d30b2ed 100644 --- a/product_portfolio/tests/test_models.py +++ b/product_portfolio/tests/test_models.py @@ -266,8 +266,8 @@ def test_product_model_assign_objects(self): self.assertEqual(status1, pc.review_status) self.assertEqual(self.super_user, pc.created_by) self.assertEqual(self.super_user, pc.last_modified_by) - self.assertEqual(26, len(str(pc.created_date))) - self.assertEqual(26, len(str(pc.last_modified_date))) + self.assertEqual(32, len(str(pc.created_date))) + self.assertEqual(32, len(str(pc.last_modified_date))) self.product1.refresh_from_db() history_entries = History.objects.get_for_object(self.product1) diff --git a/product_portfolio/tests/test_views.py b/product_portfolio/tests/test_views.py index ad7fc1cc..9ca75abc 100644 --- a/product_portfolio/tests/test_views.py +++ b/product_portfolio/tests/test_views.py @@ -1751,11 +1751,15 @@ def test_product_portfolio_productpackage_form(self): # Change status permission form = ProductPackageForm(self.basic_user, instance=productpackage) - self.assertTrue('' in str(form)) + expected = ( + '