def test_add_remove_host(self): target = [(URI.address("http://localhost:3000"), True)] c = Cluster() c.add_host(URI.address("http://localhost:3000")) # add the same host, the list of hosts should be the same c.add_host(URI.address("http://localhost:3000")) self.assertEquals(target, c.hosts) target = [(URI.address("http://localhost:3000"), True), (URI(), True)] c.add_host(URI()) self.assertEquals(target, c.hosts) target = [(URI.address("http://localhost:3000"), False), (URI(), True)] c.remove_host(URI.address("http://localhost:3000")) self.assertEquals(target, c.hosts)
def test_create_client(self): # create default client c = Client() self.assertEquals(URI(), c.cluster.hosts[0][0]) # create with cluster c = Client(Cluster(URI.address(":15000"))) self.assertEquals(URI.address(":15000"), c.cluster.hosts[0][0]) # create with URI c = Client(URI.address(":20000")) self.assertEquals(URI.address(":20000"), c.cluster.hosts[0][0]) # create with invalid type self.assertRaises(PilosaError, Client, 15000)
def test_host_port_alternative(self): uri = URI(host="db1.pilosa.com", port=3333) self.compare(uri, "http", "db1.pilosa.com", 3333)
def test_default(self): uri = URI() self.compare(uri, "http", "localhost", 10101)
def test_equals_fails_with_other_object(self): self.assertFalse(URI() == "http://localhost:10101")
def test_equals(self): uri1 = URI(host="pilosa.com", port=1337) uri2 = URI.address("http://pilosa.com:1337") self.assertTrue(uri1 == uri2)
def test_to_string(self): uri = URI() self.assertEquals("http://localhost:10101", "%s" % uri)
def uri(self): return URI(host=self.host, port=self.port)