コード例 #1
0
 def check_response(self, path, message):
     response = self.client.post(f'/api/v1/{self.uri}/',
                                 self.request_params,
                                 content_type='application/json')
     self.assertIn(message, [
         str(error) for error in get_nested_attribute(path, response.data)
     ])
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #2
0
 def test_incorrect_work_type_name(self):
     set_nested_attribute('name', 'abc',
                          self.request_params.get('work_types')[0])
     set_nested_attribute('name', 123,
                          self.request_params.get('work_types')[1])
     response = self.client.post(f'/api/v1/{self.uri}/',
                                 self.request_params,
                                 content_type='application/json')
     self.assertIn("The system doesn't support current service", [
         str(error) for error in get_nested_attribute(
             'name',
             response.data.get('work_types')[0])
     ])
     self.assertIn("The value contains numbers", [
         str(error) for error in get_nested_attribute(
             'name',
             response.data.get('work_types')[1])
     ])
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #3
0
 def test_missing_work_type_name(self):
     pop_nested_attribute('name', self.request_params.get('work_types')[0])
     response = self.client.post(f'/api/v1/{self.uri}/',
                                 self.request_params,
                                 content_type='application/json')
     self.assertIn(self.expected_messages['required'], [
         str(error) for error in get_nested_attribute(
             'name',
             response.data.get('work_types')[0])
     ])
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #4
0
 def test_incorrect_work_type_duration(self):
     set_nested_attribute('duration', 'abc',
                          self.request_params.get('work_types')[0])
     set_nested_attribute('duration', 123,
                          self.request_params.get('work_types')[1])
     response = self.client.post(f'/api/v1/{self.uri}/',
                                 self.request_params,
                                 content_type='application/json')
     self.assertIn(
         "Duration has wrong format. Use one of these formats instead: [DD] [HH:[MM:]]ss[.uuuuuu].",
         [
             str(error) for error in get_nested_attribute(
                 'duration',
                 response.data.get('work_types')[0])
         ])
     self.assertIn("Ensure this value is greater than or equal to 0:15:00.",
                   [
                       str(error) for error in get_nested_attribute(
                           'duration',
                           response.data.get('work_types')[1])
                   ])
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #5
0
 def test_blank_work_type_duration(self):
     set_nested_attribute('duration', '',
                          self.request_params.get('work_types')[0])
     response = self.client.post(f'/api/v1/{self.uri}/',
                                 self.request_params,
                                 content_type='application/json')
     self.assertIn('Ensure this value is greater than or equal to 0:15:00.',
                   [
                       str(error) for error in get_nested_attribute(
                           'duration',
                           response.data.get('work_types')[0])
                   ])
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #6
0
 def test_unique_together_profile_fields(self):
     self.client.post(f'/api/v1/{self.uri}/',
                      self.request_params,
                      content_type='application/json')
     set_nested_attribute('profile.email', self.faker.ascii_safe_email(),
                          self.request_params)
     response = self.client.post(f'/api/v1/{self.uri}/',
                                 self.request_params,
                                 content_type='application/json')
     self.assertIn(
         'The fields first_name, last_name must make a unique set.', [
             str(error) for error in get_nested_attribute(
                 'profile.non_field_errors', response.data)
         ])
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)