Ejemplo n.º 1
0
 def test_from_json(self):
     json = {
         'sum': 12,
         'stddev': 23.4
     }
     summary = Summary.from_json(json)
     expected = Summary(sum=12, stddev=23.4)
     self.assertEqual(summary, expected)
Ejemplo n.º 2
0
    def test_read(self):
        self.client.session.get.return_value = MockResponse(200, """[{
            "series": {
                "id": "id",
                "key": "key1",
                "name": "",
                "tags": [],
                "attributes": {}
            },
            "start": "2012-03-27T00:00:00.000Z",
            "end": "2012-03-28T00:00:00.000Z",
            "data": [{"t": "2012-03-27T00:00:00.000Z", "v": 12.34}],
            "summary": {}
        }]""")

        start = datetime.datetime(2012, 3, 27)
        end = datetime.datetime(2012, 3, 28)
        datasets = self.client.read(start, end, keys=['key1'])

        expected = [
            DataSet(Series('id', 'key1'), start, end, [DataPoint(start, 12.34)], Summary())]
        self.client.session.get.assert_called_once_with(
            'https://example.com/v1/data/?start=2012-03-27T00%3A00%3A00&end=2012-03-28T00%3A00%3A00&key=key1',
            auth=('key', 'secret'),
            headers=self.get_headers
        )
        self.assertEqual(datasets, expected)
Ejemplo n.º 3
0
    def test_read_key_escape(self):
        self.client.session.get.return_value = MockResponse(
            200, """{
            "series": {
                "id": "id",
                "key": "ke:y/1",
                "name": "",
                "tags": [],
                "attributes": {}
            },
            "start": "2012-03-27T00:00:00.000",
            "end": "2012-03-28T00:00:00.000",
            "data": [{"t": "2012-03-27T00:00:00.000", "v": 12.34}],
            "summary": {},
            "rollup": {}
        }""")

        start = datetime.datetime(2012, 3, 27)
        end = datetime.datetime(2012, 3, 28)
        dataset = self.client.read_key('ke:y/1', start, end)

        expected = DataSet(Series('id', 'ke:y/1'), start, end,
                           [DataPoint(start, 12.34)], Summary(), Rollup())
        self.client.session.get.assert_called_once_with(
            'https://example.com/v1/series/key/ke%3Ay%2F1/data/?start=2012-03-27T00%3A00%3A00&end=2012-03-28T00%3A00%3A00',
            auth=('key', 'secret'),
            headers=self.get_headers)
        print dataset
        print expected
        self.assertEqual(dataset, expected)
Ejemplo n.º 4
0
 def test_init(self):
     start = datetime.datetime(2012, 1, 1)
     end = datetime.datetime(2012, 1, 2)
     series = Series("id", "key")
     data = [DataPoint(start, 12.34), DataPoint(end, 23.45)]
     summary = Summary()
     dataset = DataSet(series, start, end, data, summary)
     self.assertEqual(dataset.series, series)
     self.assertEqual(dataset.start, start)
     self.assertEqual(dataset.end, end)
     self.assertEqual(dataset.data, data)
     self.assertEqual(dataset.summary, summary)
Ejemplo n.º 5
0
 def test_from_json(self):
     json = {
         'series': {
             'id': 'id',
             'key': 'key',
             'name': 'name',
             'tags': ['tag1', 'tag2'],
             'attributes': {'key1': 'value1'},
         },
         'start': '2012-03-27T00:00:00.000Z',
         'end': '2012-03-28T00:00:00.000Z',
         'data': [],
         'summary': {'min': 45.5}
     }
     dataset = DataSet.from_json(json)
     series = Series('id', 'key', 'name', {'key1': 'value1'}, ['tag1', 'tag2'])
     start = datetime.datetime(2012, 3, 27)
     end = datetime.datetime(2012, 3, 28)
     data = []
     summary = Summary(min=45.5)
     expected = DataSet(series, start, end, data, summary)
     self.assertEqual(dataset, expected)
Ejemplo n.º 6
0
 def test_init(self):
     summary = Summary(min=45.6, max=23.4)
     self.assertEqual(summary.min, 45.6)
     self.assertEqual(summary.max, 23.4)