Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Django 5.0.x #50 #58

Merged
merged 14 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 5 additions & 6 deletions component_catalog/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<input type="checkbox" id="action-toggle">'
expect1 = '<input type="checkbox" id="action-toggle"'
expect2 = "get_hierarchy_link"
expect3 = "<span>View</span>"
expect4 = '<td class="action-checkbox">'
Expand Down Expand Up @@ -864,7 +864,6 @@ def test_component_save_as_with_inlines(self):
"dje-externalreference-content_type-object_id-INITIAL_FORMS": 0,
}
response = self.client.post(url, data)
# print response.context_data['adminform'].form.errors
self.assertEqual(302, response.status_code)

new_component = Component.objects.get(name=new_name, dataspace=self.dataspace1)
Expand Down Expand Up @@ -901,8 +900,8 @@ def test_add_to_product_action_proper_component(self):
self.assertEqual(self.license1.key, pc.license_expression)
self.assertEqual(self.user, pc.created_by)
self.assertEqual(self.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.assertFalse(History.objects.get_for_object(pc).exists())
self.assertEqual(self.user, pc.created_by)
Expand Down Expand Up @@ -956,8 +955,8 @@ def test_add_to_product_action_proper_package(self):
self.assertEqual(self.license1.key, pp.license_expression)
self.assertEqual(self.user, pp.created_by)
self.assertEqual(self.user, pp.last_modified_by)
self.assertEqual(26, len(str(pp.created_date)))
self.assertEqual(26, len(str(pp.last_modified_date)))
self.assertEqual(32, len(str(pp.created_date)))
self.assertEqual(32, len(str(pp.last_modified_date)))

self.assertFalse(History.objects.get_for_object(pp).exists())
self.assertEqual(self.user, pp.created_by)
Expand Down
16 changes: 10 additions & 6 deletions component_catalog/tests/test_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,10 @@ def test_component_import_null_boolean_field(self):
self.assertContains(response, expected1, html=True, count=4)

expected_template = """
<select name="form-0-{0}" id="id_form-0-{0}">
<select name="form-0-{field_name}"
aria-describedby="id_form-0-{field_name}_helptext"
id="id_form-0-{field_name}"
>
<option value="unknown">Unknown</option>
<option value="true">Yes</option>
<option value="false" selected>No</option>
Expand All @@ -909,7 +912,8 @@ def test_component_import_null_boolean_field(self):
"indemnification",
]
for field_name in fields:
self.assertContains(response, expected_template.format(field_name), html=True)
expected = expected_template.format(field_name=field_name)
self.assertContains(response, expected, html=True)

# Results
formset_data = {
Expand All @@ -926,10 +930,10 @@ def test_component_import_null_boolean_field(self):
self.client.post(url, formset_data)
component = Component.objects.latest("id")
self.assertEqual(formset_data["form-0-name"], component.name)
self.assertTrue(component.sublicense_allowed is False)
self.assertTrue(component.express_patent_grant is False)
self.assertTrue(component.covenant_not_to_assert is False)
self.assertTrue(component.indemnification is False)
self.assertFalse(component.sublicense_allowed)
self.assertFalse(component.express_patent_grant)
self.assertFalse(component.covenant_not_to_assert)
self.assertFalse(component.indemnification)

def test_component_import_acceptable_linkages(self):
formset_data = {
Expand Down
2 changes: 1 addition & 1 deletion component_catalog/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def test_component_deletion(self):
# Deleting c1 should delete the c1 object and the Subcomponent, but c2
# is not impacted
self.c1.delete()
self.assertFalse(Subcomponent.objects.filter(parent=self.c1, child=self.c2))
self.assertFalse(Subcomponent.objects.filter(parent__id=self.c1.id, child=self.c2))
self.assertFalse(Component.objects.filter(id=self.c1.id))
self.assertTrue(Component.objects.filter(id=self.c2.id))

Expand Down
10 changes: 4 additions & 6 deletions component_catalog/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,8 +1509,9 @@ def test_package_list_view_add_to_component_from_package_data(self):
self.assertContains(response, 'value="1.0"')
self.assertContains(
response,
'<input type="url" name="homepage_url" maxlength="1024"'
' class="urlinput form-control" id="id_homepage_url">',
'<input type="url" name="homepage_url" maxlength="1024" '
'class="urlinput form-control" aria-describedby="id_homepage_url_helptext" '
'id="id_homepage_url">',
)

def test_package_list_view_usage_policy_availability(self):
Expand Down Expand Up @@ -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 = (
'<select name="review_status" class="select form-select" disabled'
' id="id_review_status">'
)
expected_status_select = '<select name="review_status" class="select form-select" disabled'
self.assertContains(response, expected_status_select)
self.assertContains(response, f'<option value="{purpose1.pk}">Core</option>')

Expand Down
36 changes: 18 additions & 18 deletions component_catalog/tests/testfiles/search/component_dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion dejacode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Common Django settings for all deployments of DejaCode

import sys
import tempfile
from pathlib import Path

import environ
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion dejacode_toolkit/scancodeio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dje/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 3 additions & 3 deletions dje/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions dje/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion dje/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def test_dataspace_admin_changeform_readonly_fields(self):
response = self.client.get(dataspace_change_url)
expected = (
f'<input type="text" name="name" value="{self.other_dataspace.name}" '
f'class="vTextField" maxlength="20" required id="id_name" />'
f'class="vTextField" maxlength="20" required aria-describedby="id_name_helptext" '
f'id="id_name">'
)
self.assertContains(response, expected, html=True)

Expand Down
4 changes: 2 additions & 2 deletions dje/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions dje/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions dje/tests/testfiles/test_dataset_cc_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": "",
Expand Down
Loading