0

I'm coding tests for an restful service (with DRF), I wanna tests that I don't must need to modify when permissions View change.

Example:

  • view.py

    class List(generics.ListAPIView): permission_classes = (IsAuthenticated, ) queryset = List.objects.all() serializer_class = ListSerializer

  • test.py

    def test_liste(self):
        url = reverse('degree-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)  
    

if run test

OK

but if permission_classes = (AllowAny, )

run test

FAILED (failures=1)

Then, How I could code the test to no must recode it when permissions change?

Thanks

aslheyrr
  • 372
  • 1
  • 4
  • 15
  • I don't see the problem. That's how it's supposed to work. You are trying to have one test for what is essentially 2 different views. – kylieCatt Jul 24 '15 at 23:25
  • @IanAuld Yes, this is way to work, I agree. But I wanna must not change the test when View's permission has changed, in same view. – aslheyrr Jul 24 '15 at 23:32
  • Write the test for the way you want the view to work. The views permissions should not be changing. If want an `AllowAny` view and a `IsAuthenticated` view then write two tests and two views. If you change the behavior of the view you need to change the expected behavior of the test. What you are trying to do is an anti pattern and shouldn't be done. – kylieCatt Jul 24 '15 at 23:45

0 Answers0