Example #1
0
    def attachments(self):
        if hasattr(self, '_hydrated_attachments_cache'):
            return self._hydrated_attachments_cache

        self._hydrated_attachments_cache = []
        if self.attachments_cache:
            for attachment in copy.deepcopy(self.attachments_cache):
                attachment['uploaded_on'] = parse_iso8601_string(attachment['uploaded_on'])
                self._hydrated_attachments_cache.append(attachment)

        return self._hydrated_attachments_cache
Example #2
0
    def test_valid_input(self):
        """util parses iso 8601 strings"""
        INPUTS = (
            '2016-10-22T20:55:39.185085Z',
            '2016-10-22T20:55:39.185085-01:00',
            '2016-10-22T20:55:39-01:00',
            '2016-10-22T20:55:39.185085+01:00',
        )

        for test_input in INPUTS:
            self.assertTrue(parse_iso8601_string(test_input))
Example #3
0
    def attachments(self):
        if hasattr(self, '_hydrated_attachments_cache'):
            return self._hydrated_attachments_cache

        self._hydrated_attachments_cache = []
        if self.attachments_cache:
            for attachment in copy.deepcopy(self.attachments_cache):
                attachment['uploaded_on'] = parse_iso8601_string(attachment['uploaded_on'])
                self._hydrated_attachments_cache.append(attachment)

        return self._hydrated_attachments_cache
    def test_valid_input(self):
        """util parses iso 8601 strings"""
        INPUTS = [
            '2016-10-22T20:55:39.185085Z',
            '2016-10-22T20:55:39.185085-01:00',
            '2016-10-22T20:55:39-01:00',
            '2016-10-22T20:55:39.185085+01:00',
        ]

        for test_input in INPUTS:
            self.assertTrue(parse_iso8601_string(test_input))
Example #5
0
    def test_invalid_input(self):
        """util throws ValueError on invalid input"""
        INPUTS = (
            '',
            '2016-10-22',
            '2016-10-22T30:55:39.185085+11:00',
            '2016-10-22T20:55:39.18SSSSS5085Z',
        )

        for test_input in INPUTS:
            with self.assertRaises(ValueError):
                self.assertTrue(parse_iso8601_string(test_input))
    def test_invalid_input(self):
        """util throws ValueError on invalid input"""
        INPUTS = [
            '',
            '2016-10-22',
            '2016-10-22T30:55:39.185085+11:00',
            '2016-10-22T20:55:39.18SSSSS5085Z',
        ]

        for test_input in INPUTS:
            with self.assertRaises(ValueError):
                self.assertTrue(parse_iso8601_string(test_input))
Example #7
0
    def to_python(self, value):
        """
        Validates that the input can be converted to a datetime. Returns a
        Python datetime.datetime object.
        """
        if value in self.empty_values:
            return None

        try:
            return parse_iso8601_string(value)
        except ValueError:
            raise ValidationError(self.error_messages['invalid'],
                                  code='invalid')