def test_unicode(self):
        """Unicode values pass validation."""

        valid_datetime_str = '2016-09-12T00:00:00.0Z'
        valid_datetime = (
            parse_datetime(valid_datetime_str).replace(tzinfo=None)
        )

        with patch('manager_rest.rest.rest_decorators.request') as request:
            data = [
                (
                    u'field,{0},{0}'.format(valid_datetime_str),
                    {'field': {'from': valid_datetime, 'to': valid_datetime}},
                ),
                (
                    u'field,{0},'.format(valid_datetime_str),
                    {'field': {'from': valid_datetime}},
                ),
                (
                    u'field,,{0}'.format(valid_datetime_str),
                    {'field': {'to': valid_datetime}},
                ),
            ]

            for (valid_value, expected_value) in data:
                request.args.getlist.return_value = [valid_value]
                rangeable(self.verify(expected_value))()
    def test_from_to_optional(self):
        """From/to are optional and validation passes if one is missing."""

        valid_datetime_str = '2016-09-12T00:00:00.0Z'
        valid_datetime = (
            parse_datetime(valid_datetime_str).replace(tzinfo=None)
        )

        with patch('manager_rest.rest.rest_decorators.request') as request:
            data = [
                (
                    'field,{0},{0}'.format(valid_datetime_str),
                    {'field': {'from': valid_datetime, 'to': valid_datetime}},
                ),
                (
                    'field,,{0}'.format(valid_datetime_str),
                    {'field': {'to': valid_datetime}},
                ),
                (
                    'field,{0},'.format(valid_datetime_str),
                    {'field': {'from': valid_datetime}},
                ),
            ]

            for (valid_value, expected_value) in data:
                request.args.getlist.return_value = [valid_value]
                rangeable(self.verify(expected_value))()
 def test_invalid(self):
     """Exception is raised for invalid values."""
     with patch('manager_rest.rest.rest_decorators.request') as request:
         invalid_values = [
             'invalid',
             ',,',  # parameter must be a string
             'field,,',  # one of from or to must be present
             'field,from,to',  # from and to should be datetimes
         ]
         for invalid_value in invalid_values:
             request.args.getlist.return_value = [invalid_value]
             with self.assertRaises(Invalid):
                 rangeable(Mock)()
Beispiel #4
0
 def test_invalid(self):
     """Exception is raised for invalid values."""
     with patch('manager_rest.rest.rest_decorators.request') as request:
         invalid_values = [
             'invalid',
             ',,',  # parameter must be a string
             'field,,',  # one of from or to must be present
             'field,from,to',  # from and to should be datetimes
         ]
         for invalid_value in invalid_values:
             request.args.getlist.return_value = [invalid_value]
             with self.assertRaises(Invalid):
                 rangeable(Mock)()
Beispiel #5
0
    def test_iso8601_datetime(self):
        """ISO8601 datetimes are valid and pass validation."""
        valid_datetime_strs = (
            '2017-03-16',
            '2017-03-16T12:33:01+00:00',
            '2017-03-16T12:33:01Z',
            '20170316T123301Z',
        )

        with patch('manager_rest.rest.rest_decorators.request') as request:
            for valid_datetime_str in valid_datetime_strs:
                valid_value = 'field,{0},{0}'.format(valid_datetime_str)
                valid_datetime = parse_datetime(valid_datetime_str)
                expected_value = {
                    'field': {
                        'from': valid_datetime,
                        'to': valid_datetime,
                    }
                }

                request.args.getlist.return_value = [valid_value]
                rangeable(self.verify(expected_value))()
Beispiel #6
0
    def test_unicode(self):
        """Unicode values pass validation."""

        valid_datetime_str = '2016-09-12T00:00:00.0Z'
        valid_datetime = (parse_datetime(valid_datetime_str).replace(
            tzinfo=None))

        with patch('manager_rest.rest.rest_decorators.request') as request:
            data = [
                (
                    u'field,{0},{0}'.format(valid_datetime_str),
                    {
                        'field': {
                            'from': valid_datetime,
                            'to': valid_datetime
                        }
                    },
                ),
                (
                    u'field,{0},'.format(valid_datetime_str),
                    {
                        'field': {
                            'from': valid_datetime
                        }
                    },
                ),
                (
                    u'field,,{0}'.format(valid_datetime_str),
                    {
                        'field': {
                            'to': valid_datetime
                        }
                    },
                ),
            ]

            for (valid_value, expected_value) in data:
                request.args.getlist.return_value = [valid_value]
                rangeable(self.verify(expected_value))()
Beispiel #7
0
    def test_from_to_optional(self):
        """From/to are optional and validation passes if one is missing."""

        valid_datetime_str = '2016-09-12T00:00:00.0Z'
        valid_datetime = (parse_datetime(valid_datetime_str).replace(
            tzinfo=None))

        with patch('manager_rest.rest.rest_decorators.request') as request:
            data = [
                (
                    'field,{0},{0}'.format(valid_datetime_str),
                    {
                        'field': {
                            'from': valid_datetime,
                            'to': valid_datetime
                        }
                    },
                ),
                (
                    'field,,{0}'.format(valid_datetime_str),
                    {
                        'field': {
                            'to': valid_datetime
                        }
                    },
                ),
                (
                    'field,{0},'.format(valid_datetime_str),
                    {
                        'field': {
                            'from': valid_datetime
                        }
                    },
                ),
            ]

            for (valid_value, expected_value) in data:
                request.args.getlist.return_value = [valid_value]
                rangeable(self.verify(expected_value))()
    def test_iso8601_datetime(self):
        """ISO8601 datetimes are valid and pass validation."""
        valid_datetime_strs = (
            '2017-03-16',
            '2017-03-16T12:33:01+00:00',
            '2017-03-16T12:33:01Z',
            '20170316T123301Z',
        )

        with patch('manager_rest.rest.rest_decorators.request') as request:
            for valid_datetime_str in valid_datetime_strs:
                valid_value = 'field,{0},{0}'.format(valid_datetime_str)
                valid_datetime = (
                    parse_datetime(valid_datetime_str).replace(tzinfo=None)
                )
                expected_value = {
                    'field': {
                        'from': valid_datetime,
                        'to': valid_datetime,
                    }
                }

                request.args.getlist.return_value = [valid_value]
                rangeable(self.verify(expected_value))()
 def test_empty(self):
     """No range arguments mapped to an empty dictionary."""
     with patch('manager_rest.rest.rest_decorators.request') as request:
         request.args.getlist.return_value = []
         rangeable(self.verify({}))()
Beispiel #10
0
 def test_empty(self):
     """No range arguments mapped to an empty dictionary."""
     with patch('manager_rest.rest.rest_decorators.request') as request:
         request.args.getlist.return_value = []
         rangeable(self.verify({}))()