示例#1
0
文件: test_web.py 项目: whilp/tsar
 def test_magic_params_accept(self):
     response = self.get("/records/fullfoo/bar/last?_accept=application/json", accept="*/*")
     self.assertEqual(response.status_int, 200)
     result = json.loads(response.body)["fullfoo/bar/last"]
     self.assertEqual(len(result), 4)
     self.assertEqual(result[0], [1278028800, -69])
     self.assertEqual(result[-1], [1278288000, 99])
示例#2
0
文件: test_web.py 项目: whilp/tsar
 def test_get_params_startstop(self):
     start, stop = 1278115200, 1278201600
     response = self.get("/records/fullfoo/bar/last?start=%d&stop=%d" % (start, stop),
         accept="application/json")
     self.assertEqual(response.status_int, 200)
     self.assertEqual(response.content_type, "application/json")
     body = json.loads(response.body)
     self.assertEqual(len(body["fullfoo/bar/last"]), 25)
示例#3
0
文件: test_web.py 项目: whilp/tsar
 def test_get_full(self):
     response = self.get("/records/fullfoo/bar/last", accept="application/json")
     self.assertEqual(response.status_int, 200)
     self.assertEqual(response.content_type, "application/json")
     body = json.loads(response.body)
     self.assertEqual(body["fullfoo/bar/last"], 
         [[1278028800, -69], [1278115200, -94], 
         [1278201600, -64], [1278288000, 99]])
示例#4
0
文件: test_web.py 项目: whilp/tsar
 def test_skip_null(self):
     response = self.get("/records/fullfoo/bar/last?interval=60&filters=skipnull", 
         accept="application/json")
     self.assertEqual(response.status_int, 200)
     body = json.loads(response.body)
     data = body["fullfoo/bar/last"]
     values = [x[1] for x in data]
     self.assertTrue(None not in values)
     self.assertEqual(len(data), 277)
示例#5
0
文件: test_web.py 项目: whilp/tsar
 def test_get_multiquery_and_magicparams(self):
     response = self.get("/records?_accept=application/json&" 
         "subject=foo&attribute=bar&cf=last&subject=spam&attribute=eggs&cf=last", 
         accept="text/csv")
     self.assertEqual(response.status_int, 200)
     self.assertEqual(response.content_type, "application/json")
     body = json.loads(response.body)
     self.assertTrue("foo/bar/last" in body)
     self.assertTrue("spam/eggs/last" in body)
示例#6
0
文件: test_web.py 项目: whilp/tsar
 def test_get_params_now(self):
     start, now = 2 * -86400, 1278201600
     response = self.get("/records/fullfoo/bar/last?start=%d&now=%d" % (start, now),
         accept="application/json")
     self.assertEqual(response.status_int, 200)
     self.assertEqual(response.content_type, "application/json")
     body = json.loads(response.body)
     data = body["fullfoo/bar/last"]
     self.assertEqual(len(data), 49)
     self.assertEqual(data[0], [1278028800, -96])
     self.assertEqual(data[-1], [1278201600, -98])
示例#7
0
文件: test_web.py 项目: whilp/tsar
    def test_get_json(self):
        data = chain([self.columns], self.data)
        body = self.datatocsvf(data).read()
        response = self.post("/records", content_type="text/csv",
            body=body)
        self.assertEquals(response.status_int, 204)

        response = self.get("/records?subject=foo&attribute=bar&cf=last"
            "&subject=spam&attribute=eggs&cf=last", 
            accept="application/json")
        self.assertEquals(response.status_int, 200)
        body = json.loads(response.body)
        self.assertTrue(body.get("foo/bar/last", []) is not [])
        self.assertTrue(body.get("spam/eggs/last", []) is not [])
示例#8
0
文件: test_web.py 项目: whilp/tsar
 def test_get(self):
     response = self.get("/records/foo/bar/last", accept="application/json")
     self.assertEqual(response.status_int, 200)
     self.assertEqual(response.content_type, "application/json")
     body = json.loads(response.body)
     self.assertEqual(body["foo/bar/last"], [])