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)
Пример #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()
 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)
Пример #4
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()
Пример #5
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)
Пример #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()
    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')
Пример #9
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)
Пример #10
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())
Пример #11
0
    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)
Пример #12
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)
Пример #13
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())
Пример #14
0
 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)