def test_update_student(self): new_school = SchoolFactory() new_nationality = NationalityFactory() student = StudentFactory(first_name='John', last_name='Cena', birth_date=date(1993, 1, 15)) identification = student.identification data = { 'first_name': 'John', 'last_name': 'Wick', 'birth_date': '1993-01-20', 'school': new_school.pk, 'nationality': new_nationality.pk, } url = reverse('education:students-detail', args=[student.pk]) response = self.client.put(url, data) student.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) self.assertEqual(student.first_name, data['first_name']) self.assertEqual(student.last_name, data['last_name']) self.assertEqual(student.birth_date.strftime('%Y-%m-%d'), data['birth_date']) self.assertEqual(student.school, new_school) self.assertEqual(student.nationality, new_nationality) self.assertEqual(student.identification, identification)
def test_partial_update_student_in_school(self): school = SchoolFactory() new_school = SchoolFactory() student = StudentFactory(school=school, first_name='John', last_name='Cena') identification = student.identification first_name = student.first_name last_name = student.last_name data = { 'school': new_school.pk, } url = reverse('education:school-students-detail', kwargs={ 'school_pk': school.pk, 'pk': student.pk, }) response = self.client.patch(url, data) student.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) self.assertEqual(student.first_name, first_name) self.assertEqual(student.last_name, last_name) self.assertEqual(student.school, new_school) self.assertEqual(student.identification, identification)
def test_partial_update_student(self): student = StudentFactory(first_name='John', last_name='Cena') identification = student.identification first_name = student.first_name school = student.school data = { 'last_name': 'Wick', } url = reverse('education:students-detail', args=[student.pk]) response = self.client.patch(url, data) student.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) self.assertEqual(student.last_name, data['last_name']) self.assertEqual(student.first_name, first_name) self.assertEqual(student.school, school) self.assertEqual(student.identification, identification)