Exemplo n.º 1
0
    def test_serialized_no_start_date_and_end_date(self):
        data = {}

        serializer = BusinessSecondsSerializer(data=data)

        assert serializer.is_valid() is False
        assert serializer.data == data
        assert serializer.validated_data == {}
        assert serializer.errors == {
            'end_time':
            [ErrorDetail(string='This field is required.', code='required')],
            'start_time':
            [ErrorDetail(string='This field is required.', code='required')]
        }
Exemplo n.º 2
0
    def test_serialized_empty_end_date(self):
        data = {
            'start_time': '2021-03-29T07:00:00-0200',
            'end_time': '',
        }

        serializer = BusinessSecondsSerializer(data=data)

        assert serializer.is_valid() is False
        assert serializer.data == data
        assert serializer.validated_data == {}
        assert serializer.errors == {
            'end_time':
            [ErrorDetail(string='This field may not be blank.', code='blank')]
        }
Exemplo n.º 3
0
    def test_serialized_date_range_3(self):
        data = {
            'start_time': '2021-03-29T08:00:00-0200',
            'end_time': '2021-03-29T17:00:00-0200',
        }

        serializer = BusinessSecondsSerializer(data=data)

        assert serializer.is_valid() is True
        assert serializer.data == data
        assert serializer.validated_data == OrderedDict([
            ('start_time', '2021-03-29T08:00:00-0200'),
            ('end_time', '2021-03-29T17:00:00-0200')
        ])

        self.assertIsInstance(serializer.validate_content(data['start_time']),
                              datetime.datetime)
        assert str(serializer.validate_content(
            data['start_time'])) == '2021-03-29 08:00:00-02:00'

        self.assertIsInstance(serializer.validate_content(data['end_time']),
                              datetime.datetime)
        assert str(serializer.validate_content(
            data['end_time'])) == '2021-03-29 17:00:00-02:00'

        self.assertIsInstance(
            serializer.count_seconds_for_start_date(
                serializer.validate_content(data['start_time']),
                serializer.validate_content(data['end_time'])), int)
        assert serializer.count_seconds_for_start_date(
            serializer.validate_content(data['start_time']),
            serializer.validate_content(data['end_time'])) == 32400

        self.assertIsInstance(
            serializer.count_business_seconds(
                serializer.validate_content(data['start_time']),
                serializer.validate_content(data['end_time'])), int)
        assert serializer.count_business_seconds(
            serializer.validate_content(data['start_time']),
            serializer.validate_content(data['end_time'])) == 32400

        assert serializer.errors == {}