Skip to content

Commit

Permalink
[fix] Code correction #866
Browse files Browse the repository at this point in the history
Fixes #866
  • Loading branch information
praptisharma28 committed Sep 11, 2024
1 parent 21ad1b9 commit 0613299
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 2 additions & 7 deletions openwisp_controller/subnet_division/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,8 @@ def _validate_existing_fields(self):

def _validate_master_subnet_consistency(self):
# Try to retrieve and validate master_subnet
try:
master_subnet = self.master_subnet.subnet
if not master_subnet:
raise ValidationError(
{'master_subnet': _('Master subnet must be a valid subnet.')}
)
except AttributeError:
master_subnet = self.master_subnet.subnet
if not master_subnet:
raise ValidationError(
{'master_subnet': _('Master subnet is required and cannot be empty.')}
)
Expand Down
7 changes: 6 additions & 1 deletion openwisp_controller/subnet_division/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,13 @@ def test_invalid_master_subnet(self):
organization=self.org,
master_subnet=invalid_subnet, # Invalid master_subnet
)
with self.assertRaises(ValidationError):
with self.assertRaises(ValidationError) as cm:
rule.full_clean()
e = cm.exception
self.assertIn(
'Master subnet must be a valid subnet.',
e.message_dict.get('master_subnet', []),
)


class TestOpenVPNSubnetDivisionRule(
Expand Down

0 comments on commit 0613299

Please sign in to comment.