]> git.parisson.com Git - django-google-tools.git/commitdiff
Added unittests. Still need to test django site integration
authorJ. Cliff Dyer <jcd@webb.(none)>
Thu, 3 Dec 2009 17:03:57 +0000 (12:03 -0500)
committerJ. Cliff Dyer <jcd@webb.(none)>
Thu, 3 Dec 2009 17:03:57 +0000 (12:03 -0500)
google_analytics/tests/__init__.py [new file with mode: 0644]
google_analytics/tests/test_templatetags.py [new file with mode: 0644]

diff --git a/google_analytics/tests/__init__.py b/google_analytics/tests/__init__.py
new file mode 100644 (file)
index 0000000..364a160
--- /dev/null
@@ -0,0 +1 @@
+from test_templatetags import *
diff --git a/google_analytics/tests/test_templatetags.py b/google_analytics/tests/test_templatetags.py
new file mode 100644 (file)
index 0000000..3229bc0
--- /dev/null
@@ -0,0 +1,65 @@
+from django.test import TestCase
+from django import template
+
+from google_analytics.templatetags import analytics 
+
+class ParserTest(TestCase):
+    def setUp(self):
+        self.parser = "unused"
+        #################################
+        # Pathological case - Do not test
+        #self.token_null = template.Token(template.TOKEN_BLOCK, "")
+        #################################
+
+        self.token_noarg = template.Token(template.TOKEN_BLOCK, "test")
+        self.token_onearg = template.Token(template.TOKEN_BLOCK, "test 'UA-888888-1'")
+        self.token_twoarg = template.Token(template.TOKEN_BLOCK, "test 'UA-888888-1' 'UA-999999-2'")
+
+    def test_setup(self):
+        self.assert_(True)
+
+    def test_basic_return(self):
+        node = analytics.do_get_analytics(self.parser, self.token_noarg)
+        self.assertTrue(isinstance(node, template.Node))
+
+    def _test_null_node_template(self):
+        node = analytics.do_get_analytics(self.parser, self.token_null)
+        self.assertEqual(node.template_name, 'google_analytics/_template.html')
+
+    def test_noarg_node_template(self):
+        node = analytics.do_get_analytics(self.parser, self.token_noarg)
+        self.assertEqual(node.template_name, 'google_analytics/test_template.html')
+    
+    def test_onearg_node_template(self):
+        node = analytics.do_get_analytics(self.parser, self.token_onearg)
+        self.assertEqual(node.template_name, 'google_analytics/test_template.html')
+    
+    def test_twoarg_node_exception(self):
+        self.assertRaises(template.TemplateSyntaxError, analytics.do_get_analytics, self.parser, self.token_twoarg)
+
+class NodeTest(TestCase):
+    def setUp(self):
+        self.node_noarg = analytics.AnalyticsNode()
+        self.node_code = analytics.AnalyticsNode(code='UA-999999-1')
+        self.node_explicit_template = analytics.AnalyticsNode(code='UA-999999-1', template_name='google_analytics/test_template.html')
+        self.node_site = analytics.AnalyticsNode(site=None, template_name='google_analytics/test_template.html')
+        self.node_code_and_site = analytics.AnalyticsNode(site=None, code='UA-999999-1', template_name='google_analytics/test_template.html')
+
+    def test_default_template_name(self):
+        self.assertEqual(self.node_noarg.template_name, 'google_analytics/analytics_template.html')
+
+    def test_explicit_template_name(self):
+        self.assertEqual(self.node_explicit_template.template_name, 'google_analytics/test_template.html')
+        
+    def test_noarg_code_name(self):
+        self.assertEqual(self.node_noarg.code, '')
+
+    def test_explicit_code_name(self):
+        self.assertEqual(self.node_code.code, 'UA-999999-1')
+
+    def _pending_test_site_code_name(self):
+        """This test needs more set-up, not yet implented"""
+
+    def _pending_test_explicit_code_overrides_site(self):
+        """This test needs more set-up, not yet implented"""
+