def test_parse_datetime_optional(self): '''Tests parsing an optional ISO datetime parameter that is missing.''' request = MagicMock(Request) request.QUERY_PARAMS = QueryDict('', mutable=True) request.QUERY_PARAMS.update({ 'test': 'value1', }) self.assertIsNone(rest_util.parse_datetime(request, 'test2', required=False))
def test_parse_datetime(self): '''Tests parsing a valid ISO datetime.''' request = MagicMock(Request) request.QUERY_PARAMS = QueryDict('', mutable=True) request.QUERY_PARAMS.update({ 'test': '2015-01-01T00:00:00Z', }) self.assertEqual(rest_util.parse_datetime(request, 'test'), datetime.datetime(2015, 1, 1, tzinfo=timezone.utc))
def test_parse_datetime_optional(self): """Tests parsing an optional ISO datetime parameter that is missing.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': 'value1', }) self.assertIsNone( rest_util.parse_datetime(request, 'test2', required=False))
def test_parse_datetime(self): """Tests parsing a valid ISO datetime.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': '2015-01-01T00:00:00Z', }) self.assertEqual(rest_util.parse_datetime(request, 'test'), datetime.datetime(2015, 1, 1, tzinfo=utc))
def test_parse_datetime_default(self): '''Tests parsing a required ISO datetime parameter that is provided via default value.''' request = MagicMock(Request) request.QUERY_PARAMS = QueryDict('', mutable=True) request.QUERY_PARAMS.update({ 'test': '2015-01-01T00:00:00Z', }) default_value = datetime.datetime(2015, 2, 10, tzinfo=timezone.utc) self.assertEqual(rest_util.parse_datetime(request, 'test2', default_value), default_value)
def test_parse_datetime_default(self): """Tests parsing a required ISO datetime parameter that is provided via default value.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': '2015-01-01T00:00:00Z', }) default_value = datetime.datetime(2015, 2, 10, tzinfo=utc) self.assertEqual( rest_util.parse_datetime(request, 'test2', default_value), default_value)