Skip to content

Commit

Permalink
[deps] Added compatibility for djangorestframework<=3.15.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Aug 16, 2024
1 parent e0b9c1d commit fc55a5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion openwisp_controller/connection/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from django.contrib.auth.models import Permission
from django.test import TestCase
from django.urls import reverse
from packaging.version import parse as parse_version
from rest_framework import VERSION as REST_FRAMEWORK_VERSION
from rest_framework.exceptions import ErrorDetail
from swapper import load_model

Expand Down Expand Up @@ -378,7 +380,10 @@ def test_put_credential_detail(self):
'port': 22,
},
}
with self.assertNumQueries(8):
expected_queries = (
9 if parse_version(REST_FRAMEWORK_VERSION) >= parse_version('3.15') else 8
)
with self.assertNumQueries(expected_queries):
response = self.client.put(path, data, content_type='application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['name'], data['name'])
Expand Down
2 changes: 2 additions & 0 deletions openwisp_controller/pki/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Meta:
read_only_fields = ['created', 'modified']
extra_kwargs = {
'organization': {'required': True},
'common_name': {'default': '', 'required': False},
'key_length': {'initial': '2048'},
'digest': {'initial': 'sha256'},
'passphrase': {'write_only': True},
Expand Down Expand Up @@ -151,6 +152,7 @@ class Meta:
fields = get_cert_list_fields(CaListSerializer.Meta.fields[:])
read_only_fields = ['created', 'modified']
extra_kwargs = {
'common_name': {'default': '', 'required': False},
'revoked': {'read_only': True},
'revoked_at': {'read_only': True},
'key_length': {'initial': '2048'},
Expand Down
13 changes: 11 additions & 2 deletions openwisp_controller/pki/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.test import TestCase
from django.urls import reverse
from packaging.version import parse as parse_version
from rest_framework import VERSION as REST_FRAMEWORK_VERSION
from swapper import load_model

from openwisp_controller.tests.utils import TestAdminMixin
Expand Down Expand Up @@ -70,7 +72,10 @@ def test_ca_import_post_api(self):
'certificate': ca1.certificate,
'private_key': ca1.private_key,
}
with self.assertNumQueries(6):
expected_queries = (
7 if parse_version(REST_FRAMEWORK_VERSION) >= parse_version('3.15') else 6
)
with self.assertNumQueries(expected_queries):
r = self.client.post(path, data, content_type='application/json')
self.assertEqual(r.status_code, 201)
self.assertEqual(Ca.objects.count(), 2)
Expand Down Expand Up @@ -179,7 +184,10 @@ def test_import_cert_post_api(self):
'certificate': ca1.certificate,
'private_key': ca1.private_key,
}
with self.assertNumQueries(10):
expected_queries = (
11 if parse_version(REST_FRAMEWORK_VERSION) >= parse_version('3.15') else 10
)
with self.assertNumQueries(expected_queries):
r = self.client.post(path, data, content_type='application/json')
self.assertEqual(r.status_code, 201)
self.assertEqual(Cert.objects.count(), 1)
Expand All @@ -203,6 +211,7 @@ def test_cert_post_with_date_none(self):
path = reverse('pki_api:cert_list')
data = {
'name': 'test-cert',
'organization': None,
'ca': self._create_ca().pk,
'serial_number': "",
'validity_start': None,
Expand Down

0 comments on commit fc55a5c

Please sign in to comment.