示例#1
0
    def test_if_type_in_request_GET_build_query_with_it(self):
        request = HttpRequest()
        request.GET['type'] = u'a'
        request.GET.update({'type': u'b'})

        query = views.build_query(request.GET)

        self.assertEqual(str(query.args), str([Q(type=u'a') | Q(type=u'b')]))
示例#2
0
    def test_if_sensor_id_in_request_GET_build_query_with_it(self):
        request = HttpRequest()
        request.GET['sensor-id'] = u'a'
        request.GET.update({'sensor-id': u'b'})

        query = views.build_query(request.GET)

        self.assertEqual(str(query.args), str([Q(sensor_id=u'a') | Q(sensor_id=u'b')]))
示例#3
0
    def test_if_type_in_request_GET_build_query_with_it(self):
        request = HttpRequest()
        request.GET['type'] = u'a'
        request.GET.update({'type': u'b'})

        query = views.build_query(request.GET)

        self.assertEqual(str(query.args), str([Q(type=u'a') | Q(type=u'b')]))
示例#4
0
    def test_invalid_args_returns_an_invalid_args_exception(self):
        request = HttpRequest()
        request.GET['datetime-first'] = 'invalid datetime'
        request.GET['datetime-last'] = '2015-01-01 00:00:50'

        with self.assertRaises(Exception) as e:
            query = views.build_query(request.GET)
            self.assertTrue(hasattr('errors', e))
示例#5
0
    def test_invalid_args_returns_an_invalid_args_exception(self):
        request = HttpRequest()
        request.GET['datetime-first'] = 'invalid datetime'
        request.GET['datetime-last'] = '2015-01-01 00:00:50'

        with self.assertRaises(Exception) as e:
            query = views.build_query(request.GET)
            self.assertTrue(hasattr('errors', e))
示例#6
0
    def test_if_sensor_id_in_request_GET_build_query_with_it(self):
        request = HttpRequest()
        request.GET['sensor-id'] = u'a'
        request.GET.update({'sensor-id': u'b'})

        query = views.build_query(request.GET)

        self.assertEqual(str(query.args),
                         str([Q(sensor_id=u'a') | Q(sensor_id=u'b')]))
示例#7
0
    def test_builds_query_with_date(self):

        request = HttpRequest()
        request.GET['date'] = '2015-01-01'
        expected_query = Query()
        expected_query.kwargs = {'datetime__year': 2015, 'datetime__month': 1, 'datetime__day': 1}

        query = views.build_query(request.GET)
        
        self.assertEqual(query, expected_query)
示例#8
0
    def test_builds_query_with_first_and_last_datetime(self):

        request = HttpRequest()
        request.GET['datetime-first'] = '2015-01-01 00:00:40'
        request.GET['datetime-last'] = '2015-01-01 00:00:50'
        expected_query = Query()
        expected_query.kwargs = {
            'datetime__gte': timezone.make_aware(datetime.datetime(2015, 1, 1, 0, 0, 40)),
            'datetime__lte': timezone.make_aware(datetime.datetime(2015, 1, 1, 0, 0, 50)),
        }
        
        query = views.build_query(request.GET)

        self.assertEqual(query, expected_query)
示例#9
0
    def test_builds_query_with_date(self):

        request = HttpRequest()
        request.GET['date'] = '2015-01-01'
        expected_query = Query()
        expected_query.kwargs = {
            'datetime__year': 2015,
            'datetime__month': 1,
            'datetime__day': 1
        }

        query = views.build_query(request.GET)

        self.assertEqual(query, expected_query)
示例#10
0
    def test_builds_query_with_first_and_last_datetime(self):

        request = HttpRequest()
        request.GET['datetime-first'] = '2015-01-01 00:00:40'
        request.GET['datetime-last'] = '2015-01-01 00:00:50'
        expected_query = Query()
        expected_query.kwargs = {
            'datetime__gte':
            timezone.make_aware(datetime.datetime(2015, 1, 1, 0, 0, 40)),
            'datetime__lte':
            timezone.make_aware(datetime.datetime(2015, 1, 1, 0, 0, 50)),
        }

        query = views.build_query(request.GET)

        self.assertEqual(query, expected_query)