Example #1
0
 def test_json(self):
     obj = [datetime.datetime.now(), Instance(app_node="foo", http_port=1234), "some string", 3124]
     s = json_dumps(obj)
     new_obj = json_loads(s)
     self.assertTrue(isinstance(new_obj[1], Instance), type(new_obj[1]))
     # TODO: fix datetime decoding
     # self.assertTrue(isinstance(new_obj[0], datetime.datetime), type(new_obj[0]))
     # self.assertEquals(obj[0].year, new_obj[0].year)
     # self.assertEquals(obj[0].second, new_obj[0].second)
     self.assertEquals(obj[1].to_dict(), new_obj[1].to_dict())
Example #2
0
    def test_instances(self):
        rv = self.client.get("/instances/")
        self.assertTrue("[]" in rv.data, rv.data)
        self.assertEquals(rv.status_code, 200)
        instances = json_loads(rv.data)
        self.assertEquals(0, len(instances))
        # create
        foo = Instance(app_node="appnode1", db_node="dbnode1", http_port=8380)
        rv = self.client.post("/instances/", data=foo.to_json(), follow_redirects=True)
        self.assertEquals(rv.status_code, 201)
        foo = Instance.from_json(rv.data)
        self.assertEquals(foo.http_port, 8380)
        self.assertTrue(foo.id)
        # list
        rv = self.client.get("/instances/")
        self.assertTrue("appnode1" in rv.data, rv.data)

        instances = json_loads(rv.data)
        self.assertEquals(1, len(instances))
        self.assertEquals(foo.id, instances[0].id)
        # get
        rv = self.client.get("/instances/%s" % foo.id)
        self.assertEquals(rv.status_code, 200)
        bar = Instance.from_json(rv.data)
        self.assertEquals(foo.id, bar.id)
        self.assertEquals(foo.app_node, bar.app_node)
        # update
        foo.app_node = "appnode2"
        rv = self.client.put("/instances/" + str(foo.id), data=foo.to_json(), follow_redirects=True)
        self.assertTrue("appnode2" in rv.data, rv.data)
        # delete
        rv = self.client.delete("/instances/" + str(foo.id))
        self.assertEquals(rv.status_code, 200)
        # list
        rv = self.client.get("/instances/")
        instances = json_loads(rv.data)
        self.assertEquals(0, len(instances))