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

Django 5 support. #537

Merged
merged 13 commits into from
May 29, 2024
Merged
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -90,11 +90,11 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
7 changes: 7 additions & 0 deletions mreg/api/v1/tests/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def test_change_label_name(self):
response = self.assert_get('/api/v1/labels/')
data = response.json()
self.assertEqual("newname", data['results'][0]['name'])

def test_label_name_case_insensitive(self):
"""Test that label names are case insensitive."""
self.assert_post('/api/v1/labels/', {'name': 'case_insensitive', 'description': 'Case insensitive'})
self.assert_post_and_409('/api/v1/labels/', {'name': 'CASE_INSENSITIVE', 'description': 'Case insensitive'})
self.assert_get_and_200('/api/v1/labels/name/case_insensitive')
self.assert_get_and_200('/api/v1/labels/name/CASE_INSENSITIVE')
4 changes: 2 additions & 2 deletions mreg/api/v1/tests/tests_bacnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def test_post_no_id_201_created(self):
response = self.assert_post(self.basepath, post_data)
response = self.assert_get(response['Location'])
self.assertIn('id', response.data)
self.assertEquals(response.data['host'], self.host_two.id)
self.assertEqual(response.data['host'], self.host_two.id)

def test_post_with_hostname_instead_of_id(self):
post_data = {'hostname': self.host_two.name}
response = self.assert_post(self.basepath, post_data)
response = self.assert_get(response['Location'])
self.assertIn('id', response.data)
self.assertEquals(response.data['host'], self.host_two.id)
self.assertEqual(response.data['host'], self.host_two.id)

def test_post_without_host_400(self):
"""Posting a new entry without specifying a host should return 400 bad request"""
Expand Down
14 changes: 7 additions & 7 deletions mreg/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,13 @@ def post(self, request, *args, **kwargs):
ipdata = {"host": host.pk, "ipaddress": ipkey}
ip = Ipaddress()
ipserializer = IpaddressSerializer(ip, data=ipdata)
if ipserializer.is_valid(raise_exception=True):
self.perform_create(ipserializer)
location = request.path + host.name
return Response(
status=status.HTTP_201_CREATED,
headers={"Location": location},
)
ipserializer.is_valid(raise_exception=True)
self.perform_create(ipserializer)
location = request.path + host.name
return Response(
status=status.HTTP_201_CREATED,
headers={"Location": location},
)
else:
host = Host()
hostserializer = HostSerializer(host, data=hostdata)
Expand Down
5 changes: 3 additions & 2 deletions mreg/api/v1/views_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LabelList(MregListCreateAPIView):

def post(self, request, *args, **kwargs):
if "name" in request.data:
if self.get_queryset().filter(name=request.data["name"]).exists():
if self.get_queryset().filter(name=request.data["name"].lower()).exists():
content = {"ERROR": "Label name already in use"}
return Response(content, status=status.HTTP_409_CONFLICT)
self.lookup_field = "name"
Expand All @@ -43,8 +43,9 @@ class LabelDetail(LowerCaseLookupMixin, MregRetrieveUpdateDestroyAPIView):
permission_classes = (IsSuperOrAdminOrReadOnly,)


class LabelDetailByName(MregRetrieveUpdateDestroyAPIView):
class LabelDetailByName(LowerCaseLookupMixin, MregRetrieveUpdateDestroyAPIView):
queryset = Label.objects.all()
serializer_class = serializers.LabelSerializer
permission_classes = (IsSuperOrAdminOrReadOnly,)
filterset_class = LabelFilterSet
lookup_field = "name"
20 changes: 10 additions & 10 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Django>3
Django>4
djangorestframework==3.14.0
django-auth-ldap==4.0.0
django-auth-ldap==4.8.0
django-logging-json==1.15
django-netfields==1.2.4
django-filter==23.1
structlog==23.1.0
rich==13.4.2
django-netfields==1.3.2
django-filter==24.2
structlog==24.1.0
rich==13.7.1
gunicorn==22.0.0
idna==3.7
psycopg2-binary==2.9.5
pika==1.3.1
sentry-sdk==1.15.0

psycopg2-binary==2.9.9
pika==1.3.2
sentry-sdk==2.3.1
tzdata==2024.1
# Testing framwork
tox
pytest
Expand Down
19 changes: 10 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Django==3.2.25
Django==5.0.6
djangorestframework==3.14.0
django-auth-ldap==4.0.0
django-netfields==1.2.4
django-filter==23.1
structlog==23.1.0
rich==13.4.2
django-auth-ldap==4.8.0
django-netfields==1.3.2
django-filter==24.2
structlog==24.1.0
rich==13.7.1
gunicorn==22.0.0
idna==3.7
psycopg2-binary==2.9.5
pika==1.3.1
sentry-sdk==1.15.0
psycopg2-binary==2.9.9
pika==1.3.2
sentry-sdk==2.3.1
tzdata==2024.1
# For OpenAPI schema generation.
uritemplate
pyyaml
11 changes: 5 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ skip_missing_interpreters = true
envlist =
lint
coverage
python{37,38,39}-django32
python{38,39,310}-django40
python{38,39,310,311}-django41
python{38,39,310,311}-django42
python{38,39,310,311,312}-django42
python{310,311,312}-django50

toxworkdir = {env:TOX_WORKDIR:.tox}

[gh-actions]
python =
3.7: python37
3.8: python38
3.9: python39
3.10: python310
3.11: python311
3.12: python312

[testenv]
setenv =
Expand All @@ -30,12 +28,13 @@ deps =
django40: Django>=4.0,<4.1
django41: Django>=4.1,<4.2
django42: Django>=4.2.a1,<4.3
django50: Django>=5.0a1,<5.1
basepython =
python37: python3.7
python38: python3.8
python39: python3.9
python310: python3.10
python311: python3.11
python312: python3.12
allowlist_externals =
coverage
python
Expand Down
Loading