Example #1
0
 def test_length(self):
     hosts = HostnameList()
     hosts.add("test1")
     hosts.add("test2")
     assert_equals(len(hosts), 2)
     hosts.add("test1")
     assert_equals(len(hosts), 2)
Example #2
0
 def test_indexing(self):
     hosts = HostnameList()
     hosts.add("test1")
     assert_equals(hosts[0].name, "test1")
     hosts.add("test2")
     assert_equals(hosts[1].name, "test2")
     assert_equals(hosts[-1].name, "test2")
Example #3
0
 def test_str(self):
     hosts = HostnameList()
     hosts.add('1.2.3.4')
     assert_equals(hosts.__str__(), 'HostList (1)')
     hosts.add('2.3.4.5')
     hosts.add('3.4.5.6')
     hosts.add('4.5.6.7')
     assert_equals(hosts.__str__(), 'HostList (4)')
Example #4
0
 def test_deletion(self):
     hosts = HostnameList()
     hosts.add("test1")
     assert_equals(len(hosts), 1)
     hosts.add("test2")
     assert_equals(len(hosts), 2)
     del hosts[-1]
     assert_equals(len(hosts), 1)
Example #5
0
 def test_repr(self):
     hosts = HostnameList()
     hosts.add('1.2.3.4')
     assert_equals(hosts.__repr__(), '<HostList \'1.2.3.4\'>')
     hosts.add('2.3.4.5')
     hosts.add('3.4.5.6')
     hosts.add('4.5.6.7')
     assert_equals(hosts.__repr__(), '<HostList \'1.2.3.4, 2.3.4.5, 3.4.5.6\'>')
Example #6
0
 def test_str(self):
     hosts = HostnameList()
     hosts.add("1.2.3.4")
     assert_equals(hosts.__str__(), "HostList (1)")
     hosts.add("2.3.4.5")
     hosts.add("3.4.5.6")
     hosts.add("4.5.6.7")
     assert_equals(hosts.__str__(), "HostList (4)")
Example #7
0
 def test_repr(self):
     hosts = HostnameList()
     hosts.add("1.2.3.4")
     assert_equals(hosts.__repr__(), "<HostList '1.2.3.4'>")
     hosts.add("2.3.4.5")
     hosts.add("3.4.5.6")
     hosts.add("4.5.6.7")
     assert_equals(hosts.__repr__(), "<HostList '1.2.3.4, 2.3.4.5, 3.4.5.6'>")
Example #8
0
    def test_contains_host(self):
        host = HostnameList()
        host.add(Hostname("test", "1.2.3.4"))
        assert_true("test" in host)
        assert_true(Hostname("test") in host)
        assert_true(Hostname("test", "1.2.3.4") in host)
        assert_true(Hostname("test.example.com") in host)
        assert_true(Hostname("test.example.com", "1.2.3.4") in host)

        assert_false("test1" in host)
        assert_false(Hostname("test1") in host)
        assert_false(Hostname("test1", "2.3.4.5") in host)
        assert_false(Hostname("test1.example.com") in host)
        assert_false(Hostname("test1.example.com", "2.3.4.5") in host)
Example #9
0
    def test_contains_host(self):
        host = HostnameList()
        host.add(Hostname('test', '1.2.3.4'))
        assert_true('test' in host)
        assert_true(Hostname('test') in host)
        assert_true(Hostname('test', '1.2.3.4') in host)
        assert_true(Hostname('test.example.com') in host)
        assert_true(Hostname('test.example.com', '1.2.3.4') in host)

        assert_false('test1' in host)
        assert_false(Hostname('test1') in host)
        assert_false(Hostname('test1', '2.3.4.5') in host)
        assert_false(Hostname('test1.example.com') in host)
        assert_false(Hostname('test1.example.com', '2.3.4.5') in host)
Example #10
0
 def test_add_fail(self):
     hosts = HostnameList()
     hosts.add('test1', '1.1.1.1')
     assert_equals(len(hosts), 1)
     assert_raises(TypeError, hosts.add)
     assert_equals(len(hosts), 1)
     hosts.add(ip='1.1.1.1')
     assert_equals(len(hosts), 1)
     hosts.add('1.1.1.1')
     assert_equals(len(hosts), 1)
Example #11
0
 def test_add_fail(self):
     hosts = HostnameList()
     hosts.add("test1", "1.1.1.1")
     assert_equals(len(hosts), 1)
     assert_raises(TypeError, hosts.add)
     assert_equals(len(hosts), 1)
     hosts.add(ip="1.1.1.1")
     assert_equals(len(hosts), 1)
     hosts.add("1.1.1.1")
     assert_equals(len(hosts), 1)
Example #12
0
 def test_indexing(self):
     hosts = HostnameList()
     hosts.add('test1')
     assert_equals(hosts[0].name, 'test1')
     hosts.add('test2')
     assert_equals(hosts[1].name, 'test2')
     assert_equals(hosts[-1].name, 'test2')
Example #13
0
 def test_length(self):
     hosts = HostnameList()
     hosts.add('test1')
     hosts.add('test2')
     assert_equals(len(hosts), 2)
     hosts.add('test1')
     assert_equals(len(hosts), 2)
Example #14
0
 def test_itr(self):
     hosts = HostnameList()
     hosts.add('test1')
     hosts.add('test2')
     host = hosts.next()
     assert_equals(host.name, 'test1')
     host = hosts.next()
     assert_equals(host.name, 'test2')
     assert_raises(StopIteration, hosts.next)
     host = hosts.next()
     assert_equals(host.name, 'test1')
     host = hosts.next()
     assert_equals(host.name, 'test2')
     assert_raises(StopIteration, hosts.next)
Example #15
0
 def test_deletion(self):
     hosts = HostnameList()
     hosts.add('test1')
     assert_equals(len(hosts), 1)
     hosts.add('test2')
     assert_equals(len(hosts), 2)
     del hosts[-1]
     assert_equals(len(hosts), 1)
Example #16
0
 def test_itr(self):
     hosts = HostnameList()
     hosts.add("test1")
     hosts.add("test2")
     host = hosts.next()
     assert_equals(host.name, "test1")
     host = hosts.next()
     assert_equals(host.name, "test2")
     assert_raises(StopIteration, hosts.next)
     host = hosts.next()
     assert_equals(host.name, "test1")
     host = hosts.next()
     assert_equals(host.name, "test2")
     assert_raises(StopIteration, hosts.next)
Example #17
0
 def test_get(self):
     hosts = HostnameList()
     hosts.add("test")
     assert_equals(hosts.get("test"), Hostname("test"))
     assert_equals(hosts.get("test"), Hostname("test"))
     assert_equals(hosts.get("test"), Hostname("test"))
     assert_equals(hosts.get("test1"), None)
     hosts.add("test.example.com")
     assert_equals(hosts.get("test"), Hostname("test"))
     assert_equals(hosts.get("test.example.com"), Hostname("test"))
     assert_equals(hosts.get("test"), Hostname("test.example.com"))
     assert_equals(hosts.get("test.example.com"), Hostname("test.example.com"))
Example #18
0
 def test_add(self):
     hosts = HostnameList()
     hosts.add("test1")
     assert_in("test1", hosts)
     assert_not_in("test2", hosts)
Example #19
0
 def test_add(self):
     hosts = HostnameList()
     hosts.add('test1')
     assert_in('test1', hosts)
     assert_not_in('test2', hosts)
Example #20
0
 def test_get(self):
     hosts = HostnameList()
     hosts.add('test')
     assert_equals(hosts.get('test'), Hostname('test'))
     assert_equals(hosts.get('test'), Hostname('test'))
     assert_equals(hosts.get('test'), Hostname('test'))
     assert_equals(hosts.get('test1'), None)
     hosts.add('test.example.com')
     assert_equals(hosts.get('test'), Hostname('test'))
     assert_equals(hosts.get('test.example.com'), Hostname('test'))
     assert_equals(hosts.get('test'), Hostname('test.example.com'))
     assert_equals(hosts.get('test.example.com'), Hostname('test.example.com'))