def test_delete_director(self): g = Director(name='steven', surname='spilberg') g.save() url = reverse('director-detail', kwargs={'pk': g.id}) response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(Director.objects.count(), 0)
def test_saving_director_unique_error_throw(self): director = Director(name='jane', surname='doe') director.full_clean() director.save() director2 = Director(name='jane', surname='doe') with self.assertRaises(ValidationError): director2.full_clean()
def test_updating_surname_validation_throw(self): director = Director(name='steven', surname='spilberg') director.full_clean() director.save() director.surname = 'a' * 41 with self.assertRaises(ValidationError): director.full_clean()
def test_saving_director_no_error_throw(self): director = Director(name='steven', surname='spilberg') director.full_clean() director.save() self.assertEqual(1, director.id) self.assertEqual('steven', director.name) self.assertEqual('spilberg', director.surname) self.assertIsNotNone(director.created)
def test_updating_name_none_should_validation_error_throw(self): director = Director(name='steven', surname='spilberg') director.full_clean() director.save() director.name = None with self.assertRaises(ValidationError): director.full_clean()
def test_deleting_existing_director_should_remove_movie(self): director = Director(name='steven', surname='spilberg') director.save() movie = Movie(title='IT Crowd', director=Director.objects.get(pk=1)) movie.save() director.delete() self.assertEqual(0, Director.objects.count()) self.assertEqual(0, Movie.objects.count())
def test_detail_view_with_a_exist_director(self): # should return a 200 OK g = Director(name='steven', surname='spilberg') g.save() url = reverse('director-detail', kwargs={'pk': g.id}) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.data['id'], 1) self.assertEqual(response.data['name'], 'steven') self.assertEqual(response.data['surname'], 'spilberg')
def test_edit_surname_valid_director(self): g = Director(name='steven', surname='spilberg') g.save() url = reverse('director-detail', kwargs={'pk': g.id}) data = {'surname': 'moricone'} response = self.client.patch(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(Director.objects.count(), 1) self.assertEqual(Director.objects.get().surname, 'moricone') self.assertEqual(Director.objects.get().name, 'steven') self.assertEqual(response.data['id'], 1) self.assertEqual(response.data['name'], 'steven') self.assertEqual(response.data['surname'], 'moricone')
def test_updating_surname_no_error_throw(self): director = Director(name='ennio', surname='spilberg') director.full_clean() director.save() director.surname = 'McDoe' director.save() director.full_clean() director.refresh_from_db() self.assertEqual(Director.objects.count(), 1) self.assertEqual(1, director.id) self.assertEqual('ennio', director.name) self.assertEqual('McDoe', director.surname)
def test_deleting_actor_shouldnt_remove_movie(self): director = Director(name='steven', surname='spilberg') director.save() movie = Movie(title='IT Crowd', director=Director.objects.get(pk=1)) movie.save() actor = Actor(name='jane', surname='doe') actor.save() movie.actor.add(actor) movie.save() actor.delete() self.assertEqual(0, Actor.objects.count()) self.assertEqual(1, Movie.objects.count())
def test_updating_name_no_error_throw(self): director = Director(name='ennio', surname='spilberg') director.full_clean() director.save() created_date_src = director.created director.name = 'steven' director.save() director.full_clean() director.refresh_from_db() created_date_dest = director.created self.assertEqual(Director.objects.count(), 1) self.assertEqual(1, director.id) self.assertEqual('steven', director.name) self.assertEqual('spilberg', director.surname) self.assertEqual(created_date_dest, created_date_src)
def test_list_view_for_directors(self): # should return 200 OK g = Director(name='steven', surname='spilberg') g.save() response = self.client.get('/directors/') self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_deleting_existing_director_should_pass(self): director = Director(name='steven', surname='spilberg') director.save() director.delete() self.assertEqual(0, Director.objects.count())