Skip to content

Commit a336a8a

Browse files
committed
[fix] Fixed os_identifier validation bug in Build model
1 parent 94288de commit a336a8a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

openwisp_firmware_upgrader/base/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def clean(self):
109109
.objects.filter(
110110
category__organization=self.category.organization, os=self.os,
111111
)
112+
.exclude(pk=self.pk)
112113
.exists()
113114
):
114115
raise ValidationError(

openwisp_firmware_upgrader/tests/test_models.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,21 @@ def test_build_clean(self):
4949
org = self._get_org()
5050
cat1 = self._get_category(organization=org)
5151
cat2 = self._create_category(name='New category', organization=org)
52-
self._create_build(organization=org, category=cat1, os=self.os)
53-
try:
54-
self._create_build(organization=org, category=cat2, os=self.os)
55-
except ValidationError as e:
56-
self.assertIn('os', e.message_dict)
57-
else:
58-
self.fail('ValidationError not raised')
59-
self.assertEqual(Build.objects.count(), 1)
52+
b1 = self._create_build(organization=org, category=cat1, os=self.os)
53+
54+
with self.subTest('validation error should be raised'):
55+
try:
56+
self._create_build(organization=org, category=cat2, os=self.os)
57+
except ValidationError as e:
58+
self.assertIn('os', e.message_dict)
59+
else:
60+
self.fail('ValidationError not raised')
61+
62+
with self.subTest('1 build object expected'):
63+
self.assertEqual(Build.objects.count(), 1)
64+
65+
with self.subTest('validating the same object again should work'):
66+
b1.full_clean()
6067

6168
def test_fw_str(self):
6269
fw = self._create_firmware_image()

0 commit comments

Comments
 (0)