예제 #1
0
    def test_list(self):
        l = ['foo', 'bar', 1]
        response = json_response(l)

        response_json = json.loads(response.content)

        self.assertEqual(response_json, l)
예제 #2
0
    def json_response(self, response, result):
        """
        Helper method to return a json response (for ajax posts).

        :param response: HttpResponse or variant
        :param result: dict of key-values to return to requester
        :returns: json response
        """
        return json_response(response, result)
예제 #3
0
    def test_extents(self):
        e = Extents(period='year')
        response = json_response(e)
        response_json = json.loads(response.content)

        start, end = e
        self.assertEquals(
            parse_utc_datetime(response_json[0], JSON_DATETIME_FORMAT).year,
            start.year
        )
예제 #4
0
    def test_transformation(self):
        dt = parse_utc_datetime('2014-04-16 12:12:12')
        indata = dict(timestamp=dt)

        response = json_response(indata)
        outdata = json.loads(response.content)

        self.assertEquals(
            parse_utc_datetime(outdata['timestamp'], JSON_DATETIME_FORMAT),
            indata['timestamp'].astimezone(local_timezone)
        )
예제 #5
0
 def _verify_json_response(self, response, data, status_code):
     resp = json_response(response, data)
     json_str = resp.content
     resp_data = json.loads(json_str)
     self.assertEqual(resp.status_code, status_code)
     self._msg('test', status_code)
     self._msg('status', resp.status_code)
     self._msg('response content', json_str)
     for k, v in resp_data.items():
         self.assertEqual(data.get(k), v)
         self._msg('data[%s]' % k, v)
예제 #6
0
    def test_timeseriescontainer(self):
        keys = ['timestamp', 'foo']
        values = (
            (local_datetime(2015, 1, 1, 12, 0, 0), 1),
            (local_datetime(2015, 1, 2, 12, 0, 0), 2),
            (local_datetime(2015, 1, 3, 12, 0, 0), 3),
            (local_datetime(2015, 1, 4, 12, 0, 0), 4)
        )
        container = TimeseriesContainer(keys, values)

        response = json_response(container)
        # is valid json
        response_json = json.loads(response.content)

        self.assertEquals(response_json['keys'], keys)