コード例 #1
0
    def test_list_no_start_date_and_end_date(self):
        data = {
        }
        request = self.factory.get('/api/business_seconds', data)

        view = BusinessSecondsViewSet.as_view({'get': 'list'})

        response = view(request).render()

        expected_json = {'error': "Must include 'start_time' and 'end_time'."}

        assert response.status_code == 400
        assert json.loads(response.content) == expected_json
コード例 #2
0
    def test_list_no_end_date(self):
        data = {
            'start_time': '2021-03-33T07:00:00-0200',
        }
        request = self.factory.get('/api/business_seconds', data)

        view = BusinessSecondsViewSet.as_view({'get': 'list'})

        response = view(request).render()

        expected_json = {'end_time': ['This field is required.']}

        assert response.status_code == 400
        assert json.loads(response.content) == expected_json
コード例 #3
0
    def test_list_empty_start_date(self):
        data = {
            'start_time': '',
            'end_time': '2021-04-03T18:00:00-0200',
        }
        request = self.factory.get('/api/business_seconds', data)

        view = BusinessSecondsViewSet.as_view({'get': 'list'})

        response = view(request).render()

        expected_json = {'start_time': ['This field may not be blank.']}

        assert response.status_code == 400
        assert json.loads(response.content) == expected_json
コード例 #4
0
    def test_list_invalid_date_6(self):
        data = {
            'start_time': '2021-03-28T07:00:00-0200',
            'end_time': '2021-04-03T18:00:00-02000',
        }
        request = self.factory.get('/api/business_seconds', data)

        view = BusinessSecondsViewSet.as_view({'get': 'list'})

        response = view(request).render()

        expected_json = {'end_time': ['Ensure this field has no more than 24 characters.']}

        assert response.status_code == 400
        assert json.loads(response.content) == expected_json
コード例 #5
0
    def test_list_invalid_date_7(self):
        data = {
            'start_time': '2021-03-33T07:00:00-0200',
            'end_time': '2021-04-03T18:00:00-0200',
        }
        request = self.factory.get('/api/business_seconds', data)

        view = BusinessSecondsViewSet.as_view({'get': 'list'})

        response = view(request).render()

        expected_json = {'error': 'The value is not a valid Time.The format must be YYYY-MM-DDThh:mm:ssTZD - '
                                  'Ie. 2019-01-04T16:41:24+0200'}

        assert response.status_code == 400
        assert json.loads(response.content) == expected_json
コード例 #6
0
    def test_list_date_range_5(self):
        data = {
            'start_time': '2021-03-29T07:00:00-0200',
            'end_time': '2021-03-29T18:00:00-0200',
        }
        request = self.factory.get('/api/business_seconds', data)

        view = BusinessSecondsViewSet.as_view({'get': 'list'})

        response = view(request).render()

        expected_json = {
            'seconds': 32400
        }

        assert response.status_code == 200
        assert json.loads(response.content) == expected_json
        self.assertEqual(response.data['seconds'], 32400)