示例#1
0
 def test_delete_oscarAward(self):
     g = OscarAward(category=oscar_categories_tuple[0][0], year=2010)
     g.save()
     url = reverse('oscaraward-detail', kwargs={'pk': g.id})
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
     self.assertEqual(OscarAward.objects.count(), 0)
示例#2
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()
示例#3
0
    def test_detail_view_with_a_exist_oscarAward(self):
        # should return a 200 OK
        g = OscarAward(category=oscar_categories_tuple[0][0], year=2010)
        g.save()

        url = reverse('oscaraward-detail', kwargs={'pk': g.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
示例#4
0
 def test_edit_year_valid_oscarAward(self):
     g = OscarAward(category=oscar_categories_tuple[0][0], year=2010)
     g.save()
     url = reverse('oscaraward-detail', kwargs={'pk': g.id})
     data = {'year': 2007}
     response = self.client.patch(url, data, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(OscarAward.objects.count(), 1)
     self.assertEqual(OscarAward.objects.get().year, 2007)
     self.assertEqual(OscarAward.objects.get().category, 'Best_Film')
    def test_updating_category_throw_error(self):
        oscarAward = OscarAward(year=1979,
                                category=oscar_categories_tuple[0][0])
        oscarAward.full_clean()
        oscarAward.save()

        oscarAward.year = 'AA'
        with self.assertRaises(ValidationError):
            oscarAward.full_clean()
    def test_unique_together_for_year_and_category(self):
        oscarAward = OscarAward(year=1979,
                                category=oscar_categories_tuple[0][0])
        oscarAward.save()

        oscarAward2 = OscarAward(year=1979,
                                 category=oscar_categories_tuple[0][0])
        with self.assertRaises(IntegrityError):
            oscarAward2.save()
    def test_updating_category_no_validation_throw(self):
        oscarAward = OscarAward(year=1979,
                                category=oscar_categories_tuple[0][0])
        oscarAward.full_clean()
        oscarAward.save()

        oscarAward.category = oscar_categories_tuple[1][0]
        self.assertEqual(1, oscarAward.id)
        self.assertEqual(1979, oscarAward.year)
        self.assertEqual('Best_Film_Editing', oscarAward.category)
    def test_deleting_existing_oscarAward_should_pass(self):
        oscarAward = OscarAward(year=1979,
                                category=oscar_categories_tuple[0][0])
        oscarAward.save()

        oscarAward.delete()
        self.assertEqual(0, OscarAward.objects.count())
 def test_saving_oscar_no_error_throw(self):
     oscarAward = OscarAward(year=1979,
                             category=oscar_categories_tuple[0][0])
     oscarAward.full_clean()
     oscarAward.save()
     self.assertEqual(1, oscarAward.id)
     self.assertEqual(1979, oscarAward.year)
     self.assertEqual('Best_Film', oscarAward.category)
    def test_deleting_none_existing_oscarAward_should_error_throw(self):
        oscarAward = OscarAward(year=1979,
                                category=oscar_categories_tuple[0][0])

        with self.assertRaises(AssertionError):
            oscarAward.delete()
 def test_empty_award_should_throw_error(self):
     oscarAward = OscarAward()
     with self.assertRaises(ValidationError):
         oscarAward.full_clean()
 def test_future_year_should_throw_error(self):
     oscarAward = OscarAward(year=2030,
                             category=oscar_categories_tuple[0][0])
     with self.assertRaises(ValidationError):
         oscarAward.full_clean()
 def test_wrong_category_should_throw_error(self):
     oscarAward = OscarAward(category='AA')
     with self.assertRaises(ValidationError):
         oscarAward.full_clean()
示例#14
0
 def test_list_view_for_oscarAwards(self):
     # should return 200 OK
     g = OscarAward(category=oscar_categories_tuple[0][0], year=2010)
     g.save()
     response = self.client.get('/oscarAwards/')
     self.assertEqual(response.status_code, status.HTTP_200_OK)