def test_delete_actor(self):
     g = Actor(name='jane', surname='doe')
     g.save()
     url = reverse('actor-detail', kwargs={'pk': g.id})
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
     self.assertEqual(Actor.objects.count(), 0)
Exemple #2
0
 def test_saving_actor_unique_error_throw(self):
     actor = Actor(name='jane', surname='doe')
     actor.full_clean()
     actor.save()
     actor2 = Actor(name='jane', surname='doe')
     with self.assertRaises(ValidationError):
         actor2.full_clean()
Exemple #3
0
 def setUp(self):
     Director(name='Stephen', surname='Spilberg').save()
     Director(name='Peter', surname='Jackson').save()
     Actor(name='Leonardo', surname='diCaprio').save()
     Actor(name='Anna', surname='Dymna').save()
     OscarAward(year=1979, category=oscar_categories_tuple[0][0]).save()
     OscarAward(year=1999, category=oscar_categories_tuple[3][0]).save()
    def test_detail_view_with_a_exist_actor(self):
        # should return a 200 OK
        g = Actor(name='jane', surname='doe')
        g.save()

        url = reverse('actor-detail', kwargs={'pk': g.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
 def test_edit_surname_valid_actor(self):
     g = Actor(name='jane', surname='doe')
     g.save()
     url = reverse('actor-detail', kwargs={'pk': g.id})
     data = {'surname': 'doe'}
     response = self.client.patch(url, data, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(Actor.objects.count(), 1)
     self.assertEqual(Actor.objects.get().surname, 'doe')
     self.assertEqual(Actor.objects.get().name, 'jane')
Exemple #6
0
    def test_updating_surname_none_should_validation_error_throw(self):
        actor = Actor(name='jane', surname='doe')
        actor.full_clean()
        actor.save()

        actor.surname = None
        with self.assertRaises(ValidationError):
            actor.full_clean()
Exemple #7
0
    def test_updating_surname_validation_throw(self):
        actor = Actor(name='jane', surname='doe')
        actor.full_clean()
        actor.save()

        actor.surname = 'a' * 41
        with self.assertRaises(ValidationError):
            actor.full_clean()
    def test_directs_related_property_from_movie(self):
        Director(name='steven', surname='spilberg').save()

        a1 = Actor(name='Leonardo', surname='diCaprio')
        a1.save()
        a2 = Actor(name='Bill', surname='Murray')
        a2.save()

        m1 = Movie(title='Logan', director=Director.objects.get(pk=1))
        m1.save()
        m1.actor.add(a1)
        m1.save()

        m2 = Movie(title='Top Gun', director=Director.objects.get(pk=1))
        m2.save()
        m1.actor.add(a2)
        m1.save()

        url = reverse('actor-detail', kwargs={'pk': 2})
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(response.data['id'], 2)
        self.assertEqual(response.data['name'], 'Bill')
        self.assertEqual(response.data['surname'], 'Murray')
        self.assertEqual(len(response.data['plays']), 1)
    def test_delete_actor_not_deletes_movies(self):
        Director(name='steven', surname='spilberg').save()
        m = Movie(title='Logan', director=Director.objects.get(pk=1))
        m.save()

        a = Actor(name='Bill', surname='Murray')
        a.save()
        m.actor.add(a)
        m.save()

        url = reverse('actor-detail', kwargs={'pk': a.id})
        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(Actor.objects.count(), 0)
        self.assertEqual(Movie.objects.count(), 1)
Exemple #10
0
 def test_saving_actor_no_error_throw(self):
     actor = Actor(name='jane', surname='doe')
     actor.full_clean()
     actor.save()
     self.assertEqual(1, actor.id)
     self.assertEqual('jane', actor.name)
     self.assertEqual('doe', actor.surname)
     self.assertIsNotNone(actor.created)
Exemple #11
0
    def test_directs_related_property_from_movie(self):
        Director(name='steven', surname='spilberg').save()
        Director(name='robert', surname='zucker').save()
        Actor(name='Leonardo', surname='diCaprio').save()
        Movie(title='Logan', director=Director.objects.get(pk=1)).save()
        Movie(title='Top Gun', director=Director.objects.get(pk=2)).save()

        url = reverse('director-detail', kwargs={'pk': 1})
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(response.data['id'], 1)
        self.assertEqual(response.data['name'], 'steven')
        self.assertEqual(response.data['surname'], 'spilberg')
        self.assertEqual(len(response.data['directs']), 1)
Exemple #12
0
    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())
Exemple #13
0
    def test_deleting_none_existing_actor_should_error_throw(self):
        actor = Actor(name='jane', surname='doe')

        with self.assertRaises(AssertionError):
            actor.delete()
 def test_list_view_for_actors(self):
     # should return 200 OK
     g = Actor(name='jane', surname='doe')
     g.save()
     response = self.client.get('/actors/')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Exemple #15
0
 def test_empty_name_should_throw_error(self):
     actor = Actor()
     with self.assertRaises(ValidationError):
         actor.full_clean()
Exemple #16
0
    def test_updating_surname_no_error_throw(self):
        actor = Actor(name='john', surname='doe')
        actor.full_clean()
        actor.save()

        actor.surname = 'McDoe'
        actor.save()
        actor.full_clean()
        actor.refresh_from_db()

        self.assertEqual(Actor.objects.count(), 1)
        self.assertEqual(1, actor.id)
        self.assertEqual('john', actor.name)
        self.assertEqual('McDoe', actor.surname)
Exemple #17
0
    def test_updating_name_no_error_throw(self):
        actor = Actor(name='john', surname='doe')
        actor.full_clean()
        actor.save()
        created_date_src = actor.created

        actor.name = 'jane'
        actor.save()
        actor.full_clean()
        actor.refresh_from_db()
        created_date_dest = actor.created

        self.assertEqual(Actor.objects.count(), 1)
        self.assertEqual(1, actor.id)
        self.assertEqual('jane', actor.name)
        self.assertEqual('doe', actor.surname)
        self.assertEqual(created_date_dest, created_date_src)
Exemple #18
0
    def test_deleting_existing_actor_should_pass(self):
        actor = Actor(name='jane', surname='doe')
        actor.save()

        actor.delete()
        self.assertEqual(0, Actor.objects.count())
Exemple #19
0
 def test_too_long_surname_should_throw_error(self):
     actor = Actor(name='jane', surname='a' * 41)
     with self.assertRaises(ValidationError):
         actor.full_clean()