def setUp(self): self.mk_main() self.request = RequestFactory().get('/') self.request.user = self.login() session_middleware = SessionMiddleware() session_middleware.process_request(self.request) self.request.session.save() self.section = SectionPage(title='test section') self.section_index.add_child(instance=self.section) self.important_tag = Tag(title='important tag') self.another_tag = Tag(title='other tag') self.tags = [self.important_tag, self.another_tag] for tag in self.tags: self.tag_index.add_child(instance=tag) tag.save_revision() self.page = ArticlePage(title='test article') self.section.add_child(instance=self.page) self.page.save_revision() for tag in self.tags: ArticlePageTags.objects.create( tag=tag, page=self.page, ) self.adapter = PersistentFormsSegmentsAdapter(self.request)
def test_add_tag_to_article(self): self.assertEqual(ArticlePageTags.objects.count(), 0) # create the tag data tag = Tag(title='over 18', slug='over-18') self.tag_index.add_child(instance=tag) tag.save_revision().publish() tag_data = {self.article.slug: tag.title} # create csv fake_namefile = tempfile.NamedTemporaryFile() with open(fake_namefile.name, 'w') as fake_csv: writer = csv.writer(fake_csv) writer.writerow(['slug', 'date']) for key, value in tag_data.items(): writer.writerow([key, value]) # call command to link tag to article call_command('add_tag_to_article', fake_csv.name, 'en') # it should create a Article Relationship with the Tag self.assertEqual(ArticlePageTags.objects.count(), 1) self.assertEqual(ArticlePageTags.objects.first().tag.title, tag.title) self.assertEqual(ArticlePageTags.objects.first().page, self.article) fake_namefile.close()
def test_nav_tag_delete_updates_article(self): """ ArticlePageTags with no tags should not be saved """ tag_index = TagIndexPage.objects.child_of(self.main).first() article = self.mk_article(parent=self.yourmind, title='first_main_article') article2 = self.mk_article(parent=self.yourmind, title='second_main_article') tag = Tag(title='New tag') tag2 = Tag(title='Another New tag') tag_index.add_child(instance=tag) tag.save_revision().publish() tag_index.add_child(instance=tag2) tag2.save_revision().publish() article.nav_tags.create(tag=tag) article.save() article2.nav_tags.create(tag=tag) article2.nav_tags.create(tag=tag2) article2.save() self.assertEqual( article.nav_tags.get(tag=tag).tag, article2.nav_tags.get(tag=tag).tag, ) # delete the tag tag.delete() # test the nav_tags are deleted and removed from the articles self.assertEqual(ArticlePageTags.objects.count(), 1) self.assertFalse(article.nav_tags.filter(pk=1).exists()) self.assertTrue(article2.nav_tags.get(), tag2)
def test_add_tag_to_article(self): self.assertEqual(ArticlePageTags.objects.count(), 0) # create the tag data tag = Tag(title='over 18', slug='over-18') self.tag_index.add_child(instance=tag) tag.save_revision().publish() tag_data = { self.article.slug: tag.title } # create csv fake_namefile = tempfile.NamedTemporaryFile() with open(fake_namefile.name, 'w') as fake_csv: writer = csv.writer(fake_csv) writer.writerow(['slug', 'date']) for key, value in tag_data.items(): writer.writerow([key, value]) # call command to link tag to article out = StringIO() call_command( 'add_tag_to_article', fake_csv.name, 'en', std_out=out) # it should create a Article Relationship with the Tag self.assertEqual(ArticlePageTags.objects.count(), 1) self.assertEqual( ArticlePageTags.objects.first().tag.title, tag.title) self.assertEqual( ArticlePageTags.objects.first().page, self.article) fake_namefile.close()
def create_tag(title, tag_index): if Tag.objects.filter(title=title).child_of(tag_index).exists(): return Tag.objects.filter(title=title).child_of(tag_index).first() else: tag = Tag(title=title) tag_index.add_child(instance=tag) tag.save_revision().publish() return tag
def mk_tag(self, parent, slug=None, **kwargs): data = {} data.update({ 'title': 'Test Tag', }) data.update(kwargs) if slug: data.update({'slug': slug}) else: data.update({'slug': generate_slug(data['title'])}) tag = Tag(**data) parent.add_child(instance=tag) tag.save_revision().publish() return tag
def test_switch_main_language(self): tag = Tag(title='love', slug='love') self.tag_index.add_child(instance=tag) tag.save_revision().publish() kw = dict(language__is_main_language=True) for relation in LanguageRelation.objects.filter(**kw): self.assertEqual(relation.language.locale, 'en') self.assertTrue(self.english.is_main_language) call_command('switch_main_language', 'id') self.assertTrue(SiteLanguage.objects.get(locale='id').is_main_language) self.assertFalse( LanguageRelation.objects.filter(language__locale='en').exists()) for relation in LanguageRelation.objects.filter(**kw): self.assertEqual(relation.language.locale, 'id')
def test_nav_tag_delete_updates_article(self): """ ArticlePageTags with no tags should not be saved """ tag_index = TagIndexPage.objects.child_of(self.main).first() article = self.mk_article( parent=self.yourmind, title='first_main_article') article2 = self.mk_article( parent=self.yourmind, title='second_main_article') tag = Tag(title='New tag') tag2 = Tag(title='Another New tag') tag_index.add_child(instance=tag) tag.save_revision().publish() tag_index.add_child(instance=tag2) tag2.save_revision().publish() article.nav_tags.create(tag=tag) article.save() article2.nav_tags.create(tag=tag) article2.nav_tags.create(tag=tag2) article2.save() self.assertEqual(article.nav_tags.get(tag=tag).tag, article2.nav_tags.get(tag=tag).tag, ) # delete the tag tag.delete() # test the nav_tags are deleted and removed from the articles self.assertEqual(ArticlePageTags.objects.count(), 1) self.assertFalse(article.nav_tags.filter(pk=1).exists()) self.assertTrue(article2.nav_tags.get(), tag2)
def mk_tags(self, parent, count=2, **kwargs): tags = [] for i in range(count): data = {} data.update({ 'title': 'Test Tag {}'.format(i), }) data.update(kwargs) data.update({'slug': generate_slug(data['title'])}) tag = Tag(**data) parent.add_child(instance=tag) tag.save_revision().publish() tags.append(tag) return tags
def test_switch_main_language(self): out = StringIO() tag = Tag(title='love', slug='love') self.tag_index.add_child(instance=tag) tag.save_revision().publish() for relation in LanguageRelation.objects.filter( language__is_main_language=True): self.assertEqual(relation.language.locale, 'en') self.assertTrue(self.english.is_main_language) call_command('switch_main_language', 'id', std_out=out) self.assertTrue(SiteLanguage.objects.get(locale='id').is_main_language) self.assertFalse( LanguageRelation.objects.filter(language__locale='en').exists()) for relation in LanguageRelation.objects.filter( language__is_main_language=True): self.assertEqual(relation.language.locale, 'id')
def mk_tags(self, parent, count=2, **kwargs): tags = [] for i in range(count): data = {} data.update({ 'title': 'Test Tag {}'.format(i), }) data.update(kwargs) data.update({ 'slug': generate_slug(data['title']) }) tag = Tag(**data) parent.add_child(instance=tag) tag.save_revision().publish() tags.append(tag) return tags
def setUp(self): self.main = self.mk_main( title='main1', slug='main1', path='00010002', url_path='/main1/') self.client = Client(HTTP_HOST=self.main.get_site().hostname) self.site_settings = SiteSettings.for_site(self.main.get_site()) self.site_settings.local_ga_tracking_code = 'local_ga_tracking_code' self.site_settings.save() GemSettings.objects.create( site_id=self.main.get_site().id, bbm_ga_account_subdomain='bbm', bbm_ga_tracking_code='bbm_tracking_code', ) self.yourmind = self.mk_section( SectionIndexPage.objects.child_of(self.main).first(), title='Your mind') self.article = self.mk_article( self.yourmind, title='article', subtitle='article with nav_tags', slug='article') self.article.save_revision().publish() self.article2 = self.mk_article( self.yourmind, title='article2', subtitle='artitle without nav_tags', slug='article2') self.article2.save_revision().publish() self.tag_index = TagIndexPage.objects.child_of(self.main).first() self.tag = Tag(title='Tag1') self.tag2 = Tag(title='Tag2') self.tag_index.add_child(instance=self.tag) self.tag.save_revision().publish() self.tag_index.add_child(instance=self.tag2) self.tag2.save_revision().publish() self.article.nav_tags.create(tag=self.tag) self.article.save_revision().publish() self.article.nav_tags.create(tag=self.tag2) self.article.save_revision().publish() # get footerpage self.footer_index = FooterIndexPage.objects.child_of(self.main).first() self.footer = FooterPage(title='Test Footer Page') self.footer_index.add_child(instance=self.footer) self.footer.save_revision().publish() self.response = self.client.get('/')
def setUp(self): # Fabricate a request with a logged-in user # so we can use it to test the segment rule self.mk_main() self.request_factory = RequestFactory() self.request = self.request_factory.get('/') self.request.user = get_user_model().objects.create_user( username='******', email='*****@*****.**', password='******') middleware = SessionMiddleware() middleware.process_request(self.request) self.request.session.save() self.section = SectionPage(title='test section') self.section_index.add_child(instance=self.section) self.tag = Tag(title='test') self.tag_index.add_child(instance=self.tag) self.tag.save_revision() self.article = self.add_article(title='test article', tags=[self.tag]) self.adapter = get_segment_adapter(self.request)
def test_tag_importable(self): content = constants.TAG_PAGE_RESPONSE content_copy = dict(content) class_ = Tag tag = Tag.create_page(content_copy, class_) self.assertEqual(type(tag), Tag) self.assertEqual(tag.title, content["title"]) self.assertEqual(tag.title, content["title"]) self.assertEqual(tag.feature_in_homepage, content["feature_in_homepage"]) self.assertEqual(tag.go_live_at, content["go_live_at"]) self.assertEqual(tag.expire_at, content["expire_at"]) self.assertEqual(tag.expired, content["expired"])
class TestArticleTagRuleSegmentation(TestCase, MoloTestCaseMixin): def setUp(self): # Fabricate a request with a logged-in user # so we can use it to test the segment rule self.mk_main() self.request_factory = RequestFactory() self.request = self.request_factory.get('/') self.request.user = get_user_model().objects.create_user( username='******', email='*****@*****.**', password='******') middleware = SessionMiddleware() middleware.process_request(self.request) self.request.session.save() self.section = SectionPage(title='test section') self.section_index.add_child(instance=self.section) self.tag = Tag(title='test') self.tag_index.add_child(instance=self.tag) self.tag.save_revision() self.article = self.add_article(title='test article', tags=[self.tag]) self.adapter = get_segment_adapter(self.request) def add_article(self, title, tags): new_article = ArticlePage(title=title) self.section.add_child(instance=new_article) new_article.save_revision() for tag in tags: ArticlePageTags.objects.create( tag=tag, page=new_article, ) return new_article def test_article_tag_rule_is_static(self): rule = ArticleTagRule(tag=self.tag, count=1) self.assertTrue(rule.static) def test_user_visits_page_with_tag(self): rule = ArticleTagRule( operator=ArticleTagRule.EQUALS, tag=self.tag, count=1, ) self.adapter.add_page_visit(self.article) self.assertTrue(rule.test_user(self.request)) def test_user_tag_with_no_visits(self): rule = ArticleTagRule(tag=self.tag, count=1) self.assertFalse(rule.test_user(self.request)) def test_user_visits_page_twice_tag_not_duplicated(self): rule = ArticleTagRule( operator=ArticleTagRule.EQUALS, tag=self.tag, count=1, ) self.adapter.add_page_visit(self.article) self.adapter.add_page_visit(self.article) self.assertTrue(rule.test_user(self.request)) def test_user_visits_page_after_cutoff(self): rule = ArticleTagRule( tag=self.tag, count=1, date_to=timezone.make_aware(datetime.datetime.now() - datetime.timedelta(days=1)), ) self.adapter.add_page_visit(self.article) self.adapter.add_page_visit(self.article) self.assertFalse(rule.test_user(self.request)) def test_user_visits_two_different_pages_same_tag(self): rule = ArticleTagRule( operator=ArticleTagRule.EQUALS, tag=self.tag, count=2, ) new_article = self.add_article(title='new article', tags=[self.tag]) self.adapter.add_page_visit(self.article) self.adapter.add_page_visit(new_article) self.assertTrue(rule.test_user(self.request)) def test_user_passes_less_than(self): rule = ArticleTagRule( tag=self.tag, count=2, operator=ArticleTagRule.LESS_THAN, ) self.adapter.add_page_visit(self.article) self.assertTrue(rule.test_user(self.request)) def test_user_fails_less_than(self): rule = ArticleTagRule( tag=self.tag, count=1, operator=ArticleTagRule.LESS_THAN, ) self.adapter.add_page_visit(self.article) self.assertFalse(rule.test_user(self.request)) def test_user_fails_greater_than(self): rule = ArticleTagRule( tag=self.tag, count=1, operator=ArticleTagRule.GREATER_THAN, ) self.adapter.add_page_visit(self.article) self.assertFalse(rule.test_user(self.request)) def test_user_passes_greater_than(self): rule = ArticleTagRule( tag=self.tag, count=0, operator=ArticleTagRule.GREATER_THAN, ) self.adapter.add_page_visit(self.article) self.assertTrue(rule.test_user(self.request)) def test_dates_are_in_order(self): rule = ArticleTagRule(tag=self.tag, count=1, date_from=datetime.datetime.now(), date_to=datetime.datetime.now() - datetime.timedelta(days=1)) with self.assertRaises(ValidationError): rule.clean() def test_count_more_than_article_error(self): rule = ArticleTagRule( tag=self.tag, count=2, ) with self.assertRaises(ValidationError): rule.clean() def test_visting_non_tagged_page_isnt_error(self): self.adapter.add_page_visit(self.main) self.assertFalse(self.request.session['tag_count']) def test_call_test_user_on_invalid_rule_fails(self): rule = ArticleTagRule() self.adapter.add_page_visit(self.article) self.assertFalse(rule.test_user(None, self.request.user)) def test_call_test_user_without_request(self): rule = ArticleTagRule( tag=self.tag, count=0, operator=ArticleTagRule.GREATER_THAN, ) self.adapter.add_page_visit(self.article) self.assertTrue(rule.test_user(None, self.request.user)) def test_call_test_user_without_user_or_request(self): rule = ArticleTagRule( tag=self.tag, count=0, operator=ArticleTagRule.GREATER_THAN, ) self.adapter.add_page_visit(self.article) self.assertFalse(rule.test_user(None)) def test_get_column_header(self): rule = ArticleTagRule( tag=self.tag, count=0, operator=ArticleTagRule.GREATER_THAN, ) self.assertEqual(rule.get_column_header(), 'Article Tag = test') def test_get_user_info_returns_true(self): rule = ArticleTagRule( tag=self.tag, count=0, operator=ArticleTagRule.GREATER_THAN, ) self.adapter.add_page_visit(self.article) self.assertEqual(rule.get_user_info_string(self.request.user), '1')
class TestCustomGemMiddleware(TestCase, GemTestCaseMixin): submit_tracking_method = ( "gem.middleware.GemMoloGoogleAnalyticsMiddleware.submit_tracking" ) def setUp(self): self.main = self.mk_main( title='main1', slug='main1', path='00010002', url_path='/main1/') self.client = Client(HTTP_HOST=self.main.get_site().hostname) self.site_settings = SiteSettings.for_site(self.main.get_site()) self.site_settings.local_ga_tracking_code = 'local_ga_tracking_code' self.site_settings.save() GemSettings.objects.create( site_id=self.main.get_site().id, bbm_ga_account_subdomain='bbm', bbm_ga_tracking_code='bbm_tracking_code', ) self.yourmind = self.mk_section( SectionIndexPage.objects.child_of(self.main).first(), title='Your mind') self.article = self.mk_article( self.yourmind, title='article', subtitle='article with nav_tags', slug='article') self.article.save_revision().publish() self.article2 = self.mk_article( self.yourmind, title='article2', subtitle='artitle without nav_tags', slug='article2') self.article2.save_revision().publish() self.tag_index = TagIndexPage.objects.child_of(self.main).first() self.tag = Tag(title='Tag1') self.tag2 = Tag(title='Tag2') self.tag_index.add_child(instance=self.tag) self.tag.save_revision().publish() self.tag_index.add_child(instance=self.tag2) self.tag2.save_revision().publish() self.article.nav_tags.create(tag=self.tag) self.article.save_revision().publish() self.article.nav_tags.create(tag=self.tag2) self.article.save_revision().publish() # get footerpage self.footer_index = FooterIndexPage.objects.child_of(self.main).first() self.footer = FooterPage(title='Test Footer Page') self.footer_index.add_child(instance=self.footer) self.footer.save_revision().publish() self.response = self.client.get('/') @patch(submit_tracking_method) def test_submit_to_additional_ga_account(self, mock_submit_tracking): ''' Given that bbm_ga_account_subdomain and bbm_ga_tracking_code are set in Gem Settings, and the URL contains the bbm_ga_account_subdomain, info should be sent to the additional GA account. ''' request = RequestFactory().get( '/', HTTP_HOST='bbm.localhost', HTTP_X_DCMGUID="0000-000-01" ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.submit_to_local_account( request, self.response, self.site_settings) mock_submit_tracking.assert_called_once_with( 'bbm_tracking_code', request, self.response, {"cd3": 'Visitor', 'cd1': "0000-000-01"}) @patch(submit_tracking_method) def test_submit_to_bbm_analytics_if_cookie_set(self, mock_submit_tracking): ''' Given that bbm_ga_account_subdomain and bbm_ga_tracking_code are set in Gem Settings, and the BBM cookie is set, info should be sent to the additional GA account. ''' request = RequestFactory().get( '/', HTTP_HOST='localhost', HTTP_X_DCMGUID="0000-000-01" ) request.COOKIES['bbm'] = 'true' request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.submit_to_local_account( request, self.response, self.site_settings) mock_submit_tracking.assert_called_once_with( 'bbm_tracking_code', request, self.response, {"cd3": 'Visitor', 'cd1': "0000-000-01"}) @patch(submit_tracking_method) def test_submit_to_local_ga_account(self, mock_submit_tracking): ''' Given that bbm_ga_account_subdomain and bbm_ga_tracking_code are set in Gem Settings, and the URL does not contain the bbm_ga_account_subdomain, info should be sent to the local GA account, not the additional GA account. ''' request = RequestFactory().get( '/', HTTP_HOST='localhost', HTTP_X_DCMGUID="0000-000-01",) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.submit_to_local_account( request, self.response, self.site_settings) mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {"cd3": 'Visitor', 'cd1': "0000-000-01"} ) @patch(submit_tracking_method) def test_submit_to_local_ga_account__custom_params(self, mock_submit_tracking): ''' Given that bbm_ga_account_subdomain and bbm_ga_tracking_code are set in Gem Settings, and the URL does not contain the bbm_ga_account_subdomain, info should be sent to the local GA account, not the additional GA account. ''' # create a user with a profile self.user = User.objects.create_user( username='******', email='*****@*****.**', password='******') self.client.login(username='******', password='******') self.user.profile.gender = 'f' self.user.profile.save() request = RequestFactory().get( '/', HTTP_HOST='localhost', HTTP_X_DCMGUID="0000-000-01", ) request.site = self.main.get_site() request.user = self.user middleware = GemMoloGoogleAnalyticsMiddleware() middleware.submit_to_local_account( request, self.response, self.site_settings) cd1 = middleware.get_visitor_id(request) mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {"cd3": 'Registered', 'cd2': self.user.profile.uuid, 'cd1': cd1}) @patch(submit_tracking_method) def test_submit_to_local_ga__ignored_info(self, mock_submit_tracking): ''' Paths in GOOGLE_ANALYTICS_IGNORE_PATH should not invoke a call to google analytics tracking ''' request = RequestFactory().get( '/profiles/password-reset/', HTTP_HOST='localhost', ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) # test that the tracking method is not called with senstive info mock_submit_tracking.assert_not_called() request = RequestFactory().get( '/profiles/reset-success/', HTTP_HOST='localhost', ) middleware.process_response( request, self.response) mock_submit_tracking.assert_not_called() request = RequestFactory().get( '/profiles/reset-password/', HTTP_HOST='localhost', ) middleware.process_response( request, self.response) mock_submit_tracking.assert_not_called() @patch(submit_tracking_method) def test_submit_to_local_ga__sensitive_info(self, mock_submit_tracking): ''' Paths with sensitive information should not be tracked on google analytics ''' request = RequestFactory().get( '/search/?q=user%40user.com', HTTP_HOST='localhost', ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) mock_submit_tracking.assert_not_called() @patch(submit_tracking_method) def test_submit_to_local_ga_valid_info(self, mock_submit_tracking): request = RequestFactory().get( '/search/?q=whatislife', HTTP_HOST='localhost', HTTP_X_DCMGUID="0000-000-01" ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) # a normal response should activate GA tracking mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {"cd3": 'Visitor', 'cd1': "0000-000-01"}) @patch(submit_tracking_method) def test_submit_to_local_ga_articlepage_title( self, mock_submit_tracking): """requests for article with tags should make a submit tracking with a cd6 value in the custom params containing all the article tags""" request = RequestFactory().get( '/sections-main1-1/{}/{}/'.format( self.yourmind.slug, self.article2.slug), HTTP_HOST='localhost', HTTP_X_DCMGUID="0000-000-01" ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) # a normal response should activate GA tracking mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {'cd5': self.article2.title, "cd3": 'Visitor', 'cd1': "0000-000-01", }) @patch(submit_tracking_method) def test_submit_to_local_ga_translated_articlepage_title( self, mock_submit_tracking): """requests for article with tags should make a submit tracking with a cd6 value in the custom params containing all the article tags""" french = SiteLanguageRelation.objects.create( language_setting=Languages.for_site(Site.objects.first()), locale='fr', is_active=True) french_article = self.mk_article_translation(self.article2, french) french_article.title = "french translation of article" french_article.save_revision().publish() request = RequestFactory().get( '/sections-main1-1/{}/{}/'.format( self.yourmind.slug, french_article.slug), HTTP_HOST='localhost', HTTP_X_DCMGUID="0000-000-01" ) request.COOKIES[settings.LANGUAGE_COOKIE_NAME] = french.locale request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) # check that the tilte of the article in the main languge is used mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {'cd5': self.article2.title, "cd3": 'Visitor', 'cd1': "0000-000-01", }) @patch(submit_tracking_method) def test_submit_to_local_ga_articlepage_with_tags( self, mock_submit_tracking): """requests for article with tags should make a submit tracking with a cd6 value in the custom params containing all the article tags""" request = RequestFactory().get( '/sections-main1-1/{}/{}/'.format( self.yourmind.slug, self.article.slug), HTTP_HOST='localhost', HTTP_X_DCMGUID="0000-000-01" ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) # a normal response should activate GA tracking nav_tags = ArticlePageTags.objects.all() tags = [nav_tag.tag.title for nav_tag in nav_tags] mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {'cd5': self.article.title, "cd3": 'Visitor', 'cd1': "0000-000-01", 'cd6': "|".join(tags)} ) @patch(submit_tracking_method) def test_submit_to_local_ga_articlepage_no_tags( self, mock_submit_tracking): '''request for articles with not tags should not have a cd6 value in the custom params''' request = RequestFactory().get( '/sections-main1-1/{}/{}/'.format( self.yourmind.slug, self.article2.slug), HTTP_X_DCMGUID="0000-000-01" ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) # a normal response should activate GA tracking mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {'cd5': self.article2.title, "cd3": 'Visitor', 'cd1': "0000-000-01"}) @patch(submit_tracking_method) def test_submit_to_local_ga__footerpage__no_tags( self, mock_submit_tracking): '''request for articles with not tags should not have a cd6 value in the custom params''' request = RequestFactory().get( '/footers-main1-1/{}/'.format( self.footer.slug), HTTP_X_DCMGUID="0000-000-01" ) request.site = self.main.get_site() middleware = GemMoloGoogleAnalyticsMiddleware() middleware.process_response( request, self.response) # a normal response should activate GA tracking mock_submit_tracking.assert_called_once_with( 'local_ga_tracking_code', request, self.response, {'cd5': self.footer.title, "cd3": 'Visitor', 'cd1': "0000-000-01"})