Пример #1
0
def is_ip_address(thing):
    """Checks if this is an ip-address valid for machinetracker"""
    try:
        IPRange.from_string(thing)
    except ValueError:
        return False
    else:
        return True
Пример #2
0
 def test_out_of_bounds_negative_index_should_raise(self):
     i = IPRange(IP('10.0.42.0'), IP('10.0.42.127'))
     with pytest.raises(IndexError):
         i[-129]
Пример #3
0
 def test_ipv6_range_length_should_be_correct(self):
     i = IPRange(IP('fe80:700:1::'), IP('fe80:700:1::f'))
     assert len(i) == 16
Пример #4
0
 def test_multi_mask_should_raise(self):
     with pytest.raises(ValueError):
         IPRange.from_string('10.0.0.0/8/24')
Пример #5
0
 def test_invalid_netmask_should_raise(self):
     with pytest.raises(ValueError):
         IPRange.from_string('10.0.0.0/2000')
Пример #6
0
 def test_garbage_range_should_raise(self):
     with pytest.raises(ValueError):
         IPRange.from_string('blapp')
Пример #7
0
 def test_ipv6_with_unspecified_mask_should_parse(self):
     i = IPRange.from_string('fe80:800:1::/')
     assert i.len() > 1
Пример #8
0
 def test_ipv4_short_subnet_should_parse(self):
     i = IPRange.from_string('10.0.99/24')
     assert i[0] == IP('10.0.99.0')
     assert i[-1] == IP('10.0.99.255')
Пример #9
0
 def test_assembled_ipv4_range_should_parse(self):
     i = IPRange.from_string('10.0.42.0-127')
     self.assertEquals(i[0], IP('10.0.42.0'))
     self.assertEquals(i[-1], IP('10.0.42.127'))
Пример #10
0
 def test_simple_ipv6_range_should_parse(self):
     i = IPRange.from_string('fe80:700:1::-fe80:700:1::f')
     self.assertEquals(i[0], IP('fe80:700:1::'))
     self.assertEquals(i[-1], IP('fe80:700:1::f'))
Пример #11
0
 def test_simple_ipv4_range_should_parse(self):
     i = IPRange.from_string('10.0.42.0-10.0.42.63')
     self.assertEquals(i[0], IP('10.0.42.0'))
     self.assertEquals(i[-1], IP('10.0.42.63'))
Пример #12
0
 def test_out_of_bounds_negative_index_should_raise(self):
     i = IPRange(IP('10.0.42.0'), IP('10.0.42.127'))
     self.assertRaises(IndexError, lambda x: i[x], -129)
Пример #13
0
 def test_indexed_access_should_work(self):
     i = IPRange(IP('10.0.42.0'), IP('10.0.42.127'))
     self.assertEquals(i[5], IP('10.0.42.5'))
Пример #14
0
 def test_ipv6_range_length_should_be_correct(self):
     i = IPRange(IP('fe80:700:1::'), IP('fe80:700:1::f'))
     self.assertEquals(len(i), 16)
Пример #15
0
 def test_ipv4_range_length_should_be_correct(self):
     i = IPRange(IP('10.0.42.0'), IP('10.0.42.127'))
     self.assertEquals(len(i), 128)
Пример #16
0
 def test_simple_ipv6_range_should_parse(self):
     i = IPRange.from_string('fe80:700:1::-fe80:700:1::f')
     assert i[0] == IP('fe80:700:1::')
     assert i[-1] == IP('fe80:700:1::f')
Пример #17
0
 def test_ipv4_short_subnet_should_parse(self):
     i = IPRange.from_string('10.0.99/24')
     self.assertEquals(i[0], IP('10.0.99.0'))
     self.assertEquals(i[-1], IP('10.0.99.255'))
Пример #18
0
 def test_assembled_ipv6_range_should_parse(self):
     i = IPRange.from_string('fe80:700:1::aaa-fff')
     self.assertEquals(i[0], IP('fe80:700:1::aaa'))
     self.assertEquals(i[-1], IP('fe80:700:1::fff'))
Пример #19
0
 def test_ipv4_with_unspecified_mask_should_parse(self):
     i = IPRange.from_string('192.168.63/')
     assert len(i) > 1
Пример #20
0
 def test_ipv4_short_subnet_should_parse(self):
     i = IPRange.from_string('10.0.99/24')
     self.assertEquals(i[0], IP('10.0.99.0'))
     self.assertEquals(i[-1], IP('10.0.99.255'))
Пример #21
0
 def test_range_with_no_end_should_raise(self):
     with pytest.raises(ValueError):
         IPRange.from_string('10.0.42.0-')
Пример #22
0
 def test_ipv4_with_unspecified_mask_should_parse(self):
     i = IPRange.from_string('192.168.63/')
     self.assertTrue(len(i) > 1)
Пример #23
0
 def test_empty_range_should_raise(self):
     with pytest.raises(ValueError):
         IPRange.from_string('')
Пример #24
0
 def test_ipv6_with_unspecified_mask_should_parse(self):
     i = IPRange.from_string('fe80:800:1::/')
     self.assertTrue(i.len() > 1)
Пример #25
0
 def test_multi_range_should_raise(self):
     with pytest.raises(ValueError):
         IPRange.from_string('10.0.0.0-10.0.1.0-42')
Пример #26
0
 def test_simple_ipv4_range_should_parse(self):
     i = IPRange.from_string('10.0.42.0-10.0.42.63')
     self.assertEquals(i[0], IP('10.0.42.0'))
     self.assertEquals(i[-1], IP('10.0.42.63'))
Пример #27
0
 def test_ipv4_range_length_should_be_correct(self):
     i = IPRange(IP('10.0.42.0'), IP('10.0.42.127'))
     assert len(i) == 128
Пример #28
0
 def test_simple_ipv6_range_should_parse(self):
     i = IPRange.from_string('fe80:700:1::-fe80:700:1::f')
     self.assertEquals(i[0], IP('fe80:700:1::'))
     self.assertEquals(i[-1], IP('fe80:700:1::f'))
Пример #29
0
 def test_indexed_access_should_work(self):
     i = IPRange(IP('10.0.42.0'), IP('10.0.42.127'))
     assert i[5] == IP('10.0.42.5')
Пример #30
0
 def test_assembled_ipv4_range_should_parse(self):
     i = IPRange.from_string('10.0.42.0-127')
     self.assertEquals(i[0], IP('10.0.42.0'))
     self.assertEquals(i[-1], IP('10.0.42.127'))
Пример #31
0
 def test_simple_ipv4_range_should_parse(self):
     i = IPRange.from_string('10.0.42.0-10.0.42.63')
     assert i[0] == IP('10.0.42.0')
     assert i[-1] == IP('10.0.42.63')
Пример #32
0
 def test_assembled_ipv6_range_should_parse(self):
     i = IPRange.from_string('fe80:700:1::aaa-fff')
     assert i[0] == IP('fe80:700:1::aaa')
     assert i[-1] == IP('fe80:700:1::fff')
Пример #33
0
 def test_assembled_ipv4_range_should_parse(self):
     i = IPRange.from_string('10.0.42.0-127')
     assert i[0] == IP('10.0.42.0')
     assert i[-1] == IP('10.0.42.127')
Пример #34
0
 def test_assembled_ipv6_range_should_parse(self):
     i = IPRange.from_string('fe80:700:1::aaa-fff')
     self.assertEquals(i[0], IP('fe80:700:1::aaa'))
     self.assertEquals(i[-1], IP('fe80:700:1::fff'))