Exemple #1
0
 def test_url_movies_detail_negative_patch_unauthorized(self):
     """
     Negative test checks that anonymous users cannot modify movies via PATCH requests
     """
     movie = Movie(name='Name', duration=120, premiere_year=1999)
     movie.save()
     input_data = {
         'name': 'New name',
     }
     response = self.client.patch(path=reverse('movie-detail',
                                               args=[movie.pk]),
                                  data=input_data,
                                  content_type='application/json')
     movie.refresh_from_db()
     self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
Exemple #2
0
 def test_url_movies_detail_positive_patch_admin(self):
     """
     Positive test checks response for admin's PATCH request to /movies/<int:pk>/
     """
     movie = Movie(name='Name', duration=120, premiere_year=1999)
     movie.save()
     input_data = {
         'name': 'New name',
     }
     response = self.client.patch(
         path=reverse('movie-detail', args=[movie.pk]),
         data=input_data,
         content_type='application/json',
         HTTP_AUTHORIZATION=f'Bearer {self.admin_token}')
     movie.refresh_from_db()
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(movie.name, input_data['name'])
     self.assertEqual(response.data['name'], input_data['name'])