def test_update_child(self): child = ChildFactory() data = { 'photo': gen_image(), 'name': 'Мария', 'surname': 'Сергеева', 'patronymic': 'Ивановна', 'sex': Child.FEMALE, 'birthday': '2014-12-23', 'room': 'A1', 'is_study': True, } response = self.client.put( reverse('api:child-detail', kwargs={'pk': child.id}), data=data) response_data = json.loads(response.content.decode('utf8')) child.refresh_from_db() expected_data = { 'sex': 1, 'room': 'A1', 'birthday': '2014-12-23', 'id': 1, 'photo': 'http://testserver{}'.format(child.photo.url), 'surname': 'Сергеева', 'name': 'Мария', 'patronymic': 'Ивановна', 'is_study': True } self.assertEqual(response.status_code, HTTP_200_OK) self.assertEqual(response_data, expected_data)
def test_create_without_sex(self): new_child_data = { 'photo': gen_image(), 'name': 'Иван', 'surname': 'Иванов', 'patronymic': 'Иванович', 'birthday': '2014-12-22', 'room': '1А', 'is_study': True, } response = self.client.post(reverse('api:child'), data=new_child_data) self.assertEqual(response.status_code, HTTP_400_BAD_REQUEST) self.assertEqual(Child.objects.all().count(), 0)
def test_create_without_is_study(self): new_child_data = { 'photo': gen_image(), 'name': 'Иван', 'surname': 'Иванов', 'patronymic': 'Иванович', 'sex': Child.MALE, 'birthday': '2014-12-22', 'room': '1А', } response = self.client.post(reverse('api:child'), data=new_child_data) self.assertEqual(response.status_code, HTTP_201_CREATED) self.assertEqual(Child.objects.all().count(), 1)