Beispiel #1
0
 def test_saving_name_no_unique_error_throw(self):
     genre = Genre(name='Comedy')
     genre.full_clean()
     genre.save()
     genre2 = Genre(name='Comedy')
     with self.assertRaises(ValidationError):
         genre2.full_clean()
 def test_delete_genre(self):
     g = Genre(name='Horror')
     g.save()
     url = reverse('genre-detail', kwargs={'pk': g.id})
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
     self.assertEqual(Genre.objects.count(), 0)
    def test_detail_view_with_a_exist_genre(self):
        # should return a 200 OK
        g = Genre(name='Horror')
        g.save()

        url = reverse('genre-detail', kwargs={'pk': g.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
 def test_edit_new_valid_genre(self):
     g = Genre(name='Comedy')
     g.save()
     url = reverse('genre-detail', kwargs={'pk': g.id})
     data = {'name': 'Horror'}
     response = self.client.patch(url, data, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(Genre.objects.count(), 1)
     self.assertEqual(Genre.objects.get().name, 'Horror')
Beispiel #5
0
    def test_updating_name_none_should_validation_error_throw(self):
        genre = Genre(name='Thriller')
        genre.full_clean()
        genre.save()

        genre.name = None
        with self.assertRaises(ValidationError):
            genre.full_clean()
Beispiel #6
0
    def test_updating_name_validation_throw(self):
        genre = Genre(name='Thriller')
        genre.full_clean()
        genre.save()

        genre.name = 'a' * 11
        with self.assertRaises(ValidationError):
            genre.full_clean()
Beispiel #7
0
    def post(self, request):
        genres = Genre.objects.all()
        genre = request.POST.get("genre")
        for item in genres:
            if genre == item.name:
                statement = "Genre {} is already in database!".format(item.name)
                return render(request, "statement.html", {"statement": statement})

        new_genre = Genre()
        new_genre.name = genre
        new_genre.save()
        statement = "Genre {} added!".format(new_genre)

        return render(request, "statement.html", {"statement": statement})
Beispiel #8
0
    def test_deleting_existing_genre_should_pass(self):
        genre = Genre(name='Thriller')
        genre.save()

        genre.delete()
        self.assertEqual(0, Genre.objects.count())
Beispiel #9
0
    def test_deleting_none_existing_genre_should_error_throw(self):
        genre = Genre(name='Comedy')

        with self.assertRaises(AssertionError):
            genre.delete()
Beispiel #10
0
 def test_empty_name_should_throw_error(self):
     genre = Genre()
     with self.assertRaises(ValidationError):
         genre.full_clean()
Beispiel #11
0
    def test_updating_name_no_error_throw(self):
        genre = Genre(name='Thriller')
        genre.full_clean()
        genre.save()

        genre.name = 'Horror'
        genre.save()
        genre.full_clean()
        genre.refresh_from_db()

        self.assertEqual(Genre.objects.count(), 1)
        self.assertEqual(1, genre.id)
        self.assertEqual('Horror', genre.name)
Beispiel #12
0
 def test_saving_name_no_error_throw(self):
     genre = Genre(name='Comedy')
     genre.full_clean()
     genre.save()
     self.assertEqual(1, genre.id)
     self.assertEqual('Comedy', genre.name)
Beispiel #13
0
 def test_too_long_name_should_throw_error(self):
     genre = Genre(name='a' * 11)
     with self.assertRaises(ValidationError):
         genre.full_clean()
 def test_list_view_for_genres(self):
     # should return 200 OK
     g = Genre(name='Horror')
     g.save()
     response = self.client.get('/genres/')
     self.assertEqual(response.status_code, status.HTTP_200_OK)