Skip to content

Instantly share code, notes, and snippets.

@G-Goldstein
Created July 29, 2016 15:23
Show Gist options
  • Save G-Goldstein/fed1693750c58a1428964a93b509da2b to your computer and use it in GitHub Desktop.
Save G-Goldstein/fed1693750c58a1428964a93b509da2b to your computer and use it in GitHub Desktop.
def all_possible_ips():
for number in range(10, 255):
yield '172.31.32.' + str(number)
def all_available_ips(unavailable):
for ip in all_possible_ips():
if ip not in unavailable:
yield ip
#########################################################
import unittest
class SaunaTests(unittest.TestCase):
def setUp(self):
self.unavailable_ips = ['172.31.32.77']
def test_for_invalid_ip_172_31_32_1(self):
assert '172.31.32.1' not in all_possible_ips()
def test_for_invalid_ip_172_31_32_9(self):
assert '172.31.32.9' not in all_possible_ips()
def test_for_valid_ip_172_31_32_10(self):
assert '172.31.32.10' in all_possible_ips()
def test_for_valid_ip_172_31_32_20(self):
assert '172.31.32.20' in all_possible_ips()
def test_for_valid_ip_172_31_32_254(self):
assert '172.31.32.254' in all_possible_ips()
def test_for_invalid_ip_172_31_32_255(self):
assert '172.31.32.255' not in all_possible_ips()
def test_for_unavailable_ip_172_31_32_77(self):
assert '172.31.32.77' not in all_available_ips(self.unavailable_ips)
def test_for_available_ip_172_31_32_90(self):
assert '172.31.32.90' in all_available_ips(self.unavailable_ips)
unittest.main()
#for ip in all_possible_ips():
# print(ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment