Answer the question
In order to leave comments, you need to log in
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')
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 questionAsk a Question
731 491 924 answers to any question