def test_ga_submit_tracking_with_custom_params__authenticated( self, mock_method): self.backend = get_search_backend('default') self.backend.reset_index() self.mk_articles(self.english_section, count=2) self.backend.refresh_index() custom_params = {'cd2': '1235-245'} response = self.client.get(reverse('search'), {'q': 'Test'}) headers = {'HTTP_X_IORG_FBS_UIP': '100.100.200.10'} request = self.make_fake_request('/search/?q=Test', headers, self.user) middleware = MoloGoogleAnalyticsMiddleware() account = '' middleware.submit_tracking( account, request, response, custom_params, ) # check if uuid was there self.assertTrue('user_id' in mock_method._mock_call_args[1]) self.assertTrue('custom_params' in mock_method._mock_call_args[1]) self.assertTrue(mock_method._mock_call_args[1]['custom_params'], custom_params)
def test_ga_middleware(self, mock_method): self.backend = get_search_backend('default') self.backend.reset_index() self.mk_articles(self.english_section, count=2) self.backend.refresh_index() response = self.client.get(reverse('search'), {'q': 'Test'}) headers = {'HTTP_X_IORG_FBS_UIP': '100.100.200.10'} request = self.make_fake_request('/search/?q=Test', headers) middleware = MoloGoogleAnalyticsMiddleware() account = '' response = middleware.submit_tracking(account, request, response) self.assertTrue(mock_method.called_with(request.get_full_path())) self.assertEqual( mock_method._mock_call_args[1]['custom_params']['cd10'], self.english.locale)
def test_ga_middleware(self, mock_method): self.backend = get_search_backend('default') self.backend.reset_index() self.mk_articles(self.english_section, count=2) self.backend.refresh_index() response = self.client.get(reverse('search'), { 'q': 'Test' }) headers = {'HTTP_X_IORG_FBS_UIP': '100.100.200.10'} request = self.make_fake_request( '/search/?q=Test', headers) middleware = MoloGoogleAnalyticsMiddleware() account = '' response = middleware.submit_tracking(account, request, response) self.assertTrue(mock_method.called_with(request.get_full_path()))
def test_ga_submit_tracking_with_custom_params__language_change( self, mock_method): self.french = SiteLanguageRelation.objects.create( language_setting=Languages.for_site(self.main.get_site()), locale='fr', is_active=True) response = self.client.get('/locale/fr/', follow=True) headers = {'HTTP_X_IORG_FBS_UIP': '100.100.200.10'} request = self.make_fake_request('/locale/fr/', headers, self.user, locale=self.french.locale) middleware = MoloGoogleAnalyticsMiddleware() account = '' response = middleware.submit_tracking(account, request, response) self.assertTrue(mock_method.called_with(request.get_full_path())) self.assertEqual( mock_method._mock_call_args[1]['custom_params']['cd10'], self.french.locale)