Skip to content

Commit

Permalink
[test] Added test for subnet/32
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Feb 23, 2022
1 parent 3453d85 commit aa79c96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions openwisp_ipam/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ def count(self):
if self.stop is not None:
return self.stop - self.start
broadcast = int(self.subnet.subnet.broadcast_address)
if self.subnet.subnet.max_prefixlen == 32:
if self.subnet.subnet._prefixlen == 32:
# IPV4
if self.subnet.subnet.version == 4:
# Networks with a mask of 32 will return a list
# containing the single host address
if self.subnet.subnet.prefixlen == 32:
return 1
# Other than subnet /32, exclude broadcast
return broadcast - self.network - 1
# IPV6
else:
return broadcast - self.network

Expand Down
9 changes: 9 additions & 0 deletions openwisp_ipam/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,12 @@ def assert_response(response):
reverse('admin:ipam_export_subnet', args=[subnet.id]), follow=True
)
assert_response(response)

def test_subnet_32(self):
subnet = self._create_subnet(subnet='192.168.0.0/32', description='Subnet 32')
try:
response = self.client.get(reverse('ipam:hosts', args=(subnet.id,)))
self.assertIsNone(response.data['next'])
self.assertIsNone(response.data['previous'])
except ValueError as err:
self.fail(f'subnet/32: {err}')

0 comments on commit aa79c96

Please sign in to comment.