def test_render_internal_ip(self): req = HttpRequest() req.META['REMOTE_ADDR'] = '1.1.1.1' context = Context({'request': req}) r = WoopraNode().render(context) assert r.startswith('<!-- Woopra disabled on internal IP address') assert r.endswith('-->')
def test_render_internal_ip(self): req = HttpRequest() req.META['REMOTE_ADDR'] = '1.1.1.1' context = Context({'request': req}) r = WoopraNode().render(context) self.assertTrue(r.startswith( '<!-- Woopra 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 = WoopraNode().render(context) self.assertTrue( r.startswith('<!-- Woopra 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 = WoopraNode().render(context) self.assertTrue(r.startswith( '<!-- Woopra disabled on internal IP address'), r) self.assertTrue(r.endswith('-->'), r)
def test_no_identify_when_explicit_email(self): r = WoopraNode().render( Context({ 'woopra_email': 'explicit', 'user': User(username='******') })) self.assertTrue('var woo_visitor = {"email": "explicit"};' in r, r)
def test_no_identify_when_explicit_name(self): r = WoopraNode().render( Context({ 'woopra_name': 'explicit', 'user': User(username='******'), })) assert 'var woo_visitor = {"name": "explicit"};' in r
def test_custom(self): r = WoopraNode().render( Context({ 'woopra_var1': 'val1', 'woopra_var2': 'val2', })) assert 'var woo_visitor = {"var1": "val1", "var2": "val2"};' in r
def test_no_identify_when_explicit_email(self): self.settings_manager.set(ANALYTICAL_AUTO_IDENTIFY=True) r = WoopraNode().render( Context({ 'woopra_email': 'explicit', 'user': User(username='******') })) self.assertTrue('var woo_visitor = {"email": "explicit"};' in r, r)
def test_identify_name_and_email(self): r = WoopraNode().render( Context({ 'user': User(username='******', first_name='Firstname', last_name='Lastname', email="*****@*****.**"), })) assert 'var woo_visitor = ' '{"email": "*****@*****.**", "name": "Firstname Lastname"};' in r
def test_identify_name_and_email(self): r = WoopraNode().render( Context({ 'user': User(username='******', first_name='Firstname', last_name='Lastname', email="*****@*****.**") })) self.assertTrue( 'var woo_visitor = {"name": "Firstname Lastname", ' '"email": "*****@*****.**"};' in r, r)
def test_identify_name_and_email(self): self.settings_manager.set(ANALYTICAL_AUTO_IDENTIFY=True) r = WoopraNode().render( Context({ 'user': User(username='******', first_name='Firstname', last_name='Lastname', email="*****@*****.**") })) self.assertTrue( 'var woo_visitor = {"name": "Firstname Lastname", ' '"email": "*****@*****.**"};' in r, r)
def test_idle_timeout(self): self.settings_manager.set(WOOPRA_IDLE_TIMEOUT=1234) r = WoopraNode().render(Context({})) self.assertTrue( 'var woo_settings = {"domain": "example.com", ' '"idle_timeout": "1234"};' in r, r)
def test_identify_anonymous_user(self): r = WoopraNode().render(Context({'user': AnonymousUser()})) self.assertTrue('var woo_visitor = {};' in r, r)
def test_identify_username_no_email(self): r = WoopraNode().render(Context({'user': User(username='******')})) self.assertTrue('var woo_visitor = {"name": "test"};' in r, r)
def test_idle_timeout(self): r = WoopraNode().render(Context({})) self.assertTrue( 'var woo_settings = {"domain": "example.com", ' '"idle_timeout": "1234"};' in r, r)
def test_node(self): r = WoopraNode().render(Context({})) self.assertTrue('var woo_settings = {"domain": "example.com"};' in r, r)
def test_wrong_domain(self): with pytest.raises(AnalyticalException): WoopraNode()
def test_identify_username_no_email(self): self.settings_manager.set(ANALYTICAL_AUTO_IDENTIFY=True) r = WoopraNode().render(Context({'user': User(username='******')})) self.assertTrue('var woo_visitor = {"name": "test"};' in r, r)