Example #1
0
    def test_supports_relative_timestamps(self):
        query = {
            'ts': {'$humanTime': '1 hour ago'}
        }

        one_hour_ago = parse_human_time("1 hour ago")
        query_data = parse_query_json(json.dumps(query))
        self.assertEqual(query_data['ts'], one_hour_ago)
Example #2
0
    def test_supports_relative_timestamps(self):
        query = {
            'ts': {'$humanTime': '1 hour ago'}
        }

        one_hour_ago = parse_human_time("1 hour ago", None)
        query_data = parse_query_json(json.dumps(query), None)
        self.assertEqual(query_data['ts'], one_hour_ago)
Example #3
0
    def tests_use_utc_for_relative_timestamps_with_timezone(self):
        query = {
            'ts': {'$humanTime': '1 hour ago'}
        }

        one_hour_ago = parse_human_time("1 hour ago", None)

        query_data = parse_query_json(json.dumps(query), 'US/Eastern')
        self.assertEqual(query_data['ts'], one_hour_ago)
Example #4
0
    def tests_supports_absolute_timestamps_with_timezone(self):
        query = {
            'ts': {'$humanTime': 'august 20th 2016 at 2pm'}
        }

        expected_date_time = datetime.datetime(2016, 8, 20, 18, 0).replace(tzinfo=utc)

        query_data = parse_query_json(json.dumps(query), 'US/Eastern')
        self.assertEqual(query_data['ts'], expected_date_time)
Example #5
0
    def test_ignores_non_isodate_fields(self):
        query = {
            'test': 1,
            'test_list': ['a', 'b', 'c'],
            'test_dict': {
                'a': 1,
                'b': 2
            }
        }

        query_data = parse_query_json(json.dumps(query))
        self.assertDictEqual(query_data, query)
Example #6
0
    def test_ignores_non_isodate_fields(self):
        query = {
            'test': 1,
            'test_list': ['a', 'b', 'c'],
            'test_dict': {
                'a': 1,
                'b': 2
            }
        }

        query_data = parse_query_json(json.dumps(query))
        self.assertDictEqual(query_data, query)
Example #7
0
    def test_ignores_non_isodate_fields(self):
        query = {
            "test": 1,
            "test_list": ["a", "b", "c"],
            "test_dict": {
                "a": 1,
                "b": 2
            }
        }

        query_data = parse_query_json(json_dumps(query))
        self.assertDictEqual(query_data, query)
    def test_parses_isodate_fields(self):
        query = {
            "test": 1,
            "test_list": ["a", "b", "c"],
            "test_dict": {"a": 1, "b": 2},
            "testIsoDate": 'ISODate("2014-10-03T00:00")',
        }

        query_data = parse_query_json(json_dumps(query))

        self.assertEqual(
            query_data["testIsoDate"], datetime.datetime(2014, 10, 3, 0, 0)
        )
Example #9
0
    def test_parses_isodate_fields(self):
        query = {
            'test': 1,
            'test_list': ['a', 'b', 'c'],
            'test_dict': {
                'a': 1,
                'b': 2
            },
            'testIsoDate': "ISODate(\"2014-10-03T00:00\")"
        }

        query_data = parse_query_json(json.dumps(query), None)

        self.assertEqual(query_data['testIsoDate'], datetime.datetime(2014, 10, 3, 0, 0))
Example #10
0
    def test_parses_isodate_fields(self):
        query = {
            'test': 1,
            'test_list': ['a', 'b', 'c'],
            'test_dict': {
                'a': 1,
                'b': 2
            },
            'testIsoDate': "ISODate(\"2014-10-03T00:00\")"
        }

        query_data = parse_query_json(json.dumps(query))

        self.assertEqual(query_data['testIsoDate'], datetime.datetime(2014, 10, 3, 0, 0))
 def test_supports_extended_json_types(self):
     query = {
         "test": 1,
         "test_list": ["a", "b", "c"],
         "test_dict": {"a": 1, "b": 2},
         "testIsoDate": 'ISODate("2014-10-03T00:00")',
         "test$date": {"$date": "2014-10-03T00:00:00.0"},
         "test$undefined": {"$undefined": None},
     }
     query_data = parse_query_json(json_dumps(query))
     self.assertEqual(query_data["test$undefined"], None)
     self.assertEqual(
         query_data["test$date"],
         datetime.datetime(2014, 10, 3, 0, 0).replace(tzinfo=utc),
     )
Example #12
0
 def test_supports_extended_json_types(self):
     query = {
         'test': 1,
         'test_list': ['a', 'b', 'c'],
         'test_dict': {
             'a': 1,
             'b': 2
         },
         'testIsoDate': "ISODate(\"2014-10-03T00:00\")",
         'test$date': {
             '$date': '2014-10-03T00:00:00.0'
         },
         'test$undefined': {
             '$undefined': None
         }
     }
     query_data = parse_query_json(json.dumps(query), None)
     self.assertEqual(query_data['test$undefined'], None)
     self.assertEqual(query_data['test$date'], datetime.datetime(2014, 10, 3, 0, 0).replace(tzinfo=utc))
Example #13
0
 def test_supports_extended_json_types(self):
     query = {
         'test': 1,
         'test_list': ['a', 'b', 'c'],
         'test_dict': {
             'a': 1,
             'b': 2
         },
         'testIsoDate': "ISODate(\"2014-10-03T00:00\")",
         'test$date': {
             '$date': '2014-10-03T00:00:00.0'
         },
         'test$undefined': {
             '$undefined': None
         }
     }
     query_data = parse_query_json(json.dumps(query))
     self.assertEqual(query_data['test$undefined'], None)
     self.assertEqual(query_data['test$date'], datetime.datetime(2014, 10, 3, 0, 0).replace(tzinfo=utc))
Example #14
0
    def test_handles_nested_fields(self):
        # https://github.com/getredash/redash/issues/597
        query = {
            "collection": "bus",
            "aggregate": [
                {
                    "$geoNear": {
                        "near": {"type": "Point", "coordinates": [-22.910079, -43.205161]},
                        "maxDistance": 100000000,
                        "distanceField": "dist.calculated",
                        "includeLocs": "dist.location",
                        "spherical": True
                    }
                }
            ]
        }

        query_data = parse_query_json(json.dumps(query), None)

        self.assertDictEqual(query, query_data)
Example #15
0
    def test_handles_nested_fields(self):
        # https://github.com/getredash/redash/issues/597
        query = {
            "collection": "bus",
            "aggregate": [
                {
                    "$geoNear": {
                        "near": {"type": "Point", "coordinates": [-22.910079, -43.205161]},
                        "maxDistance": 100000000,
                        "distanceField": "dist.calculated",
                        "includeLocs": "dist.location",
                        "spherical": True
                    }
                }
            ]
        }

        query_data = parse_query_json(json.dumps(query))

        self.assertDictEqual(query, query_data)
Example #16
0
    def test_supports_relative_timestamps(self):
        query = {"ts": {"$humanTime": "1 hour ago"}}

        one_hour_ago = parse_human_time("1 hour ago")
        query_data = parse_query_json(json_dumps(query))
        self.assertEqual(query_data["ts"], one_hour_ago)