def test_render_internal_ip(self):
     req = HttpRequest()
     req.META['REMOTE_ADDR'] = '1.1.1.1'
     context = Context({'request': req})
     r = ChartbeatBottomNode().render(context)
     assert r.startswith('<!-- Chartbeat disabled on internal IP address')
     assert r.endswith('-->')
Exemplo n.º 2
0
 def test_render_internal_ip(self):
     req = HttpRequest()
     req.META["REMOTE_ADDR"] = "1.1.1.1"
     context = Context({"request": req})
     r = ChartbeatBottomNode().render(context)
     self.assertTrue(r.startswith("<!-- Chartbeat disabled on internal IP address"), r)
     self.assertTrue(r.endswith("-->"), r)
 def test_render_internal_ip(self):
     req = HttpRequest()
     req.META['REMOTE_ADDR'] = '1.1.1.1'
     context = Context({'request': req})
     r = ChartbeatBottomNode().render(context)
     self.assertTrue(r.startswith(
             '<!-- Chartbeat disabled on internal IP address'), r)
     self.assertTrue(r.endswith('-->'), r)
 def test_render_internal_ip(self):
     self.settings_manager.set(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
     req = HttpRequest()
     req.META['REMOTE_ADDR'] = '1.1.1.1'
     context = Context({'request': req})
     r = ChartbeatBottomNode().render(context)
     self.assertTrue(
         r.startswith('<!-- Chartbeat disabled on internal IP address'), r)
     self.assertTrue(r.endswith('-->'), r)
 def test_rendering_setup_site(self):
     from django.contrib.sites.models import Site
     site = Site.objects.create(domain="test.com", name="test")
     with override_settings(SITE_ID=site.id):
         r = ChartbeatBottomNode().render(Context())
         self.assertTrue(re.search('var _sf_async_config={.*"uid": "12345".*};', r), r)
         self.assertTrue(re.search('var _sf_async_config={.*"domain": "test.com".*};', r), r)
 def test_rendering_setup_no_site(self):
     installed_apps = [
         a for a in settings.INSTALLED_APPS if a != 'django.contrib.sites'
     ]
     self.settings_manager.set(INSTALLED_APPS=installed_apps)
     r = ChartbeatBottomNode().render(Context())
     self.assertTrue('var _sf_async_config={"uid": "12345"};' in r, r)
 def test_bottom_node(self):
     r = ChartbeatBottomNode().render(
         Context({'chartbeat_domain': "test.com"}))
     self.assertTrue(
         re.search('var _sf_async_config={.*"uid": "12345".*};', r), r)
     self.assertTrue(
         re.search('var _sf_async_config={.*"domain": "test.com".*};', r),
         r)
 def test_auto_domain_false(self):
     """
     Even if 'django.contrib.sites' is in INSTALLED_APPS, if
     CHARTBEAT_AUTO_DOMAIN is False, ensure there is no 'domain'
     in _sf_async_config.
     """
     r = ChartbeatBottomNode().render(Context())
     self.assertTrue('var _sf_async_config={"uid": "12345"};' in r, r)
 def test_rendering_setup_site(self):
     installed_apps = list(settings.INSTALLED_APPS)
     installed_apps.append('django.contrib.sites')
     self.settings_manager.set(INSTALLED_APPS=installed_apps)
     site = Site.objects.create(domain="test.com", name="test")
     self.settings_manager.set(SITE_ID=site.id)
     r = ChartbeatBottomNode().render(Context())
     self.assertTrue(
         re.search('var _sf_async_config={.*"uid": "12345".*};', r), r)
     self.assertTrue(
         re.search('var _sf_async_config={.*"domain": "test.com".*};', r),
         r)
 def test_rendering_setup_no_site(self):
     r = ChartbeatBottomNode().render(Context())
     self.assertTrue('var _sf_async_config={"uid": "12345"};' in r, r)
 def test_wrong_user_id(self):
     with pytest.raises(AnalyticalException):
         ChartbeatBottomNode()