S
S
Sergey Nizhny Novgorod2016-08-15 07:40:15
Django
Sergey Nizhny Novgorod, 2016-08-15 07:40:15

How to properly mock a model in Django?

Hello.
Checking now opening pages with dynamic content. I'm trying to mock models with data:

class Dynamic_pages(TestCase): 

    @patch('faceset.models.Banner')
    @patch('faceset.models.Video')
    def test_video6(self, MockBanner, MockVideo):
        Video = MockVideo()
        Banner = MockBanner()
        response = self.client.get('/video6')
        self.assertTemplateUsed(response, 'faceset/videopage.html')
        self.assertTemplateUsed(response, 'faceset/banner.html')
        self.assertTemplateUsed(response, 'faceset/menu.html')
        self.assertTemplateUsed(response, 'faceset/footer.html')

I get an error:
django.core.urlresolvers.NoReverseMatch: Reverse for 'downvideolike' with arguments '(,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['downvideolike(?P[0-9]+)$']
Can you tell me how to mock in this case?
With Factory Boy, this thing goes through:
class BannerFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Banner

    bancode = 'test_code_for_deploy'
    banlink = 'test_link_for_deploy'
    banimg = '../imagination/hand/main-section.jpg'

#####

class VideoFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Video

    seo_description = "Put any tex"
    title = "Put any tex"
    description = "Put any tex"
    video_image = '../imagination/hand/main-section.jpg'
    video_link = "http://www.cybersport.ru/"
    thumbnumber = 1
    # likedone

#####

<code>class Dynamic_pages(TestCase): 
def test_video6(self):
        Video = VideoFactory.create(id=6)
        Banner = BannerFactory.create()
        response = self.client.get('/video6')
        self.assertTemplateUsed(response, 'faceset/videopage.html')
        self.assertTemplateUsed(response, 'faceset/banner.html')
        self.assertTemplateUsed(response, 'faceset/menu.html')
        self.assertTemplateUsed(response, 'faceset/footer.html')</code>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question