mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Migrate tests to Pytest plain asserts
This commit is contained in:
parent
896a19196f
commit
055ae897cb
5 changed files with 31 additions and 37 deletions
|
|
@ -33,4 +33,4 @@ class AnalyticsTagTestCase(TagTestCase):
|
|||
def test_location_tags(self):
|
||||
for loc in ['head_top', 'head_bottom', 'body_top', 'body_bottom']:
|
||||
r = self.render_location_tag(loc)
|
||||
self.assertTrue('dummy_%s' % loc in r, r)
|
||||
assert f'dummy_{loc}' in r
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ class ChartbeatTagTestCaseWithSites(TestCase):
|
|||
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)
|
||||
assert re.search('var _sf_async_config={.*"uid": "12345".*};', r)
|
||||
assert re.search('var _sf_async_config={.*"domain": "test.com".*};', r)
|
||||
|
||||
@override_settings(CHARTBEAT_AUTO_DOMAIN=False)
|
||||
def test_auto_domain_false(self):
|
||||
|
|
@ -50,7 +50,7 @@ class ChartbeatTagTestCaseWithSites(TestCase):
|
|||
in _sf_async_config.
|
||||
"""
|
||||
r = ChartbeatBottomNode().render(Context())
|
||||
self.assertTrue('var _sf_async_config={"uid": "12345"};' in r, r)
|
||||
assert 'var _sf_async_config={"uid": "12345"};' in r
|
||||
|
||||
|
||||
@override_settings(CHARTBEAT_USER_ID='12345')
|
||||
|
|
@ -61,25 +61,25 @@ class ChartbeatTagTestCase(TagTestCase):
|
|||
|
||||
def test_top_tag(self):
|
||||
r = self.render_tag('chartbeat', 'chartbeat_top', {'chartbeat_domain': "test.com"})
|
||||
self.assertTrue('var _sf_startpt=(new Date()).getTime()' in r, r)
|
||||
assert 'var _sf_startpt=(new Date()).getTime()' in r
|
||||
|
||||
def test_bottom_tag(self):
|
||||
r = self.render_tag('chartbeat', 'chartbeat_bottom', {'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)
|
||||
assert re.search('var _sf_async_config={.*"uid": "12345".*};', r)
|
||||
assert re.search('var _sf_async_config={.*"domain": "test.com".*};', r)
|
||||
|
||||
def test_top_node(self):
|
||||
r = ChartbeatTopNode().render(Context({
|
||||
'chartbeat_domain': "test.com",
|
||||
}))
|
||||
self.assertTrue('var _sf_startpt=(new Date()).getTime()' in r, r)
|
||||
assert 'var _sf_startpt=(new Date()).getTime()' in 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)
|
||||
assert re.search('var _sf_async_config={.*"uid": "12345".*};', r)
|
||||
assert re.search('var _sf_async_config={.*"domain": "test.com".*};', r)
|
||||
|
||||
@override_settings(CHARTBEAT_USER_ID=None)
|
||||
def test_no_user_id(self):
|
||||
|
|
@ -95,6 +95,5 @@ class ChartbeatTagTestCase(TagTestCase):
|
|||
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)
|
||||
assert r.startswith('<!-- Chartbeat disabled on internal IP address')
|
||||
assert r.endswith('-->')
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ class ClickmapTagTestCase(TagTestCase):
|
|||
|
||||
def test_tag(self):
|
||||
r = self.render_tag('clickmap', 'clickmap')
|
||||
self.assertTrue("tracker: '12345ABC', version:'2'};" in r, r)
|
||||
assert "tracker: '12345ABC', version:'2'};" in r
|
||||
|
||||
def test_node(self):
|
||||
r = ClickmapNode().render(Context({}))
|
||||
self.assertTrue("tracker: '12345ABC', version:'2'};" in r, r)
|
||||
assert "tracker: '12345ABC', version:'2'};" in r
|
||||
|
||||
@override_settings(CLICKMAP_TRACKER_ID=None)
|
||||
def test_no_site_id(self):
|
||||
|
|
@ -39,6 +39,5 @@ class ClickmapTagTestCase(TagTestCase):
|
|||
req.META['REMOTE_ADDR'] = '1.1.1.1'
|
||||
context = Context({'request': req})
|
||||
r = ClickmapNode().render(context)
|
||||
self.assertTrue(r.startswith(
|
||||
'<!-- Clickmap disabled on internal IP address'), r)
|
||||
self.assertTrue(r.endswith('-->'), r)
|
||||
assert r.startswith('<!-- Clickmap disabled on internal IP address')
|
||||
assert r.endswith('-->')
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ class ClickyTagTestCase(TagTestCase):
|
|||
|
||||
def test_tag(self):
|
||||
r = self.render_tag('clicky', 'clicky')
|
||||
self.assertTrue('clicky_site_ids.push(12345678);' in r, r)
|
||||
self.assertTrue('src="//in.getclicky.com/12345678ns.gif"' in r, r)
|
||||
assert 'clicky_site_ids.push(12345678);' in r
|
||||
assert 'src="//in.getclicky.com/12345678ns.gif"' in r
|
||||
|
||||
def test_node(self):
|
||||
r = ClickyNode().render(Context({}))
|
||||
self.assertTrue('clicky_site_ids.push(12345678);' in r, r)
|
||||
self.assertTrue('src="//in.getclicky.com/12345678ns.gif"' in r, r)
|
||||
assert 'clicky_site_ids.push(12345678);' in r
|
||||
assert 'src="//in.getclicky.com/12345678ns.gif"' in r
|
||||
|
||||
@override_settings(CLICKY_SITE_ID=None)
|
||||
def test_no_site_id(self):
|
||||
|
|
@ -41,21 +41,19 @@ class ClickyTagTestCase(TagTestCase):
|
|||
@override_settings(ANALYTICAL_AUTO_IDENTIFY=True)
|
||||
def test_identify(self):
|
||||
r = ClickyNode().render(Context({'user': User(username='test')}))
|
||||
self.assertTrue('var clicky_custom = {"session": {"username": "test"}};' in r, r)
|
||||
assert 'var clicky_custom = {"session": {"username": "test"}};' in r
|
||||
|
||||
@override_settings(ANALYTICAL_AUTO_IDENTIFY=True)
|
||||
def test_identify_anonymous_user(self):
|
||||
r = ClickyNode().render(Context({'user': AnonymousUser()}))
|
||||
self.assertFalse('var clicky_custom = {"session": {"username":' in r, r)
|
||||
assert 'var clicky_custom = {"session": {"username":' not in r
|
||||
|
||||
def test_custom(self):
|
||||
r = ClickyNode().render(Context({
|
||||
'clicky_var1': 'val1',
|
||||
'clicky_var2': 'val2',
|
||||
}))
|
||||
self.assertTrue(
|
||||
re.search(r'var clicky_custom = {.*"var1": "val1", "var2": "val2".*};', r),
|
||||
r)
|
||||
assert re.search(r'var clicky_custom = {.*"var1": "val1", "var2": "val2".*};', r)
|
||||
|
||||
@override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
|
||||
def test_render_internal_ip(self):
|
||||
|
|
@ -63,6 +61,5 @@ class ClickyTagTestCase(TagTestCase):
|
|||
req.META['REMOTE_ADDR'] = '1.1.1.1'
|
||||
context = Context({'request': req})
|
||||
r = ClickyNode().render(context)
|
||||
self.assertTrue(r.startswith(
|
||||
'<!-- Clicky disabled on internal IP address'), r)
|
||||
self.assertTrue(r.endswith('-->'), r)
|
||||
assert r.startswith('<!-- Clicky disabled on internal IP address')
|
||||
assert r.endswith('-->')
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ class CrazyEggTagTestCase(TagTestCase):
|
|||
|
||||
def test_tag(self):
|
||||
r = self.render_tag('crazy_egg', 'crazy_egg')
|
||||
self.assertTrue('/1234/5678.js' in r, r)
|
||||
assert '/1234/5678.js' in r
|
||||
|
||||
def test_node(self):
|
||||
r = CrazyEggNode().render(Context())
|
||||
self.assertTrue('/1234/5678.js' in r, r)
|
||||
assert '/1234/5678.js' in r
|
||||
|
||||
@override_settings(CRAZY_EGG_ACCOUNT_NUMBER=None)
|
||||
def test_no_account_number(self):
|
||||
|
|
@ -36,8 +36,8 @@ class CrazyEggTagTestCase(TagTestCase):
|
|||
def test_uservars(self):
|
||||
context = Context({'crazy_egg_var1': 'foo', 'crazy_egg_var2': 'bar'})
|
||||
r = CrazyEggNode().render(context)
|
||||
self.assertTrue("CE2.set(1, 'foo');" in r, r)
|
||||
self.assertTrue("CE2.set(2, 'bar');" in r, r)
|
||||
assert "CE2.set(1, 'foo');" in r
|
||||
assert "CE2.set(2, 'bar');" in r
|
||||
|
||||
@override_settings(ANALYTICAL_INTERNAL_IPS=['1.1.1.1'])
|
||||
def test_render_internal_ip(self):
|
||||
|
|
@ -45,6 +45,5 @@ class CrazyEggTagTestCase(TagTestCase):
|
|||
req.META['REMOTE_ADDR'] = '1.1.1.1'
|
||||
context = Context({'request': req})
|
||||
r = CrazyEggNode().render(context)
|
||||
self.assertTrue(r.startswith(
|
||||
'<!-- Crazy Egg disabled on internal IP address'), r)
|
||||
self.assertTrue(r.endswith('-->'), r)
|
||||
assert r.startswith('<!-- Crazy Egg disabled on internal IP address')
|
||||
assert r.endswith('-->')
|
||||
|
|
|
|||
Loading…
Reference in a new issue