O'Reilly logo

Test-Driven Development with Django by Kevin Harvey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring the index view

Generally speaking, I'm pretty quick to jettison class-based views if the implementation looks like it's going to get weird. Here, we're going to do the lookup with multiple arguments, and getting DetailView to do that is just not going to be any fun. Let's go ahead and refactor the test to expect a function-based view. Don't forget to update the import:

from solos.views import index, solo_detail
...
    def test_basic(self):
        """
        Test that the solo view returns a 200 response and uses 
        The correct template
        """
        request = self.factory.get(
            '/solos/no-funny-hats/bugle-call-rag/buddy-rich/'
        )

        response = solo_detail(
           request, 
           album=self.no_funny_hats.slug,
           track=self.bugle_call_rag.slug,    
           artist=self.drum_solo.slug
        )
        ...

Running ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required