예제 #1
0
 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)
예제 #2
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()
예제 #3
0
    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()
예제 #4
0
 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)
예제 #5
0
    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()
예제 #6
0
    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())
예제 #7
0
    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')
예제 #8
0
    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')
예제 #9
0
    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)
예제 #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_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)
예제 #12
0
 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)
예제 #13
0
    def test_deleting_existing_director_should_pass(self):
        director = Director(name='steven', surname='spilberg')
        director.save()

        director.delete()
        self.assertEqual(0, Director.objects.count())