Skip to content

Commit 95ff8fe

Browse files
dee077nemesifier
andauthored
[fix] Always convert MAC address to uppercase format #922
Ensure consistency with the behavior of the openwisp-config agent. Fixes #922 --------- Co-authored-by: Federico Capoano <[email protected]>
1 parent 07ae5ce commit 95ff8fe

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

openwisp_controller/config/base/device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def _validate_unique_name(self):
262262

263263
def clean(self, *args, **kwargs):
264264
super().clean(*args, **kwargs)
265+
self.mac_address = self.mac_address.upper()
265266
self._validate_unique_name()
266267
self._validate_org_relation('group', field_error='group')
267268
self._validate_org_device_limit()

openwisp_controller/config/tests/test_device.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ def test_mac_address_validator(self):
6969
else:
7070
self.fail('ValidationError not raised for "{0}"'.format(mac_address))
7171

72+
def test_device_mac_address_uppercase(self):
73+
device = self._create_device(mac_address='00:1a:2b:3c:4d:5e')
74+
device.full_clean()
75+
self.assertEqual(device.mac_address, '00:1A:2B:3C:4D:5E')
76+
device.save()
77+
device.refresh_from_db()
78+
self.assertEqual(device.mac_address, '00:1A:2B:3C:4D:5E')
79+
7280
def test_config_status_modified(self):
7381
c = self._create_config(device=self._create_device(), status='applied')
7482
self.assertEqual(c.status, 'applied')

openwisp_controller/geo/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_put_create_location(self):
9494
device = self._create_object()
9595
self.assertEqual(self.location_model.objects.count(), 0)
9696
url = reverse(self.url_name, args=[device.pk])
97-
r = self.client.put(f'{url}?key={device.key }')
97+
r = self.client.put(f'{url}?key={device.key}')
9898
self.assertEqual(r.status_code, 200)
9999
self.assertDictEqual(
100100
r.json(),

0 commit comments

Comments
 (0)