Esempio n. 1
0
    def test_filters_mesurement_with_query(self, Measurement, JsonResponse,
                                           build_query):

        query = Query()
        build_query.return_value = query

        response = views.api(self.request)

        Measurement.objects.filter.assert_called_once_with(
            *query.args, **query.kwargs)
Esempio n. 2
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)
Esempio n. 3
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)