]> git.parisson.com Git - django-google-tools.git/commitdiff
Some testcases added.
authorOrne Brocaar <info@brocaar.com>
Fri, 6 Aug 2010 08:12:48 +0000 (10:12 +0200)
committerOrne Brocaar <info@brocaar.com>
Fri, 6 Aug 2010 08:12:48 +0000 (10:12 +0200)
12 files changed:
MANIFEST.in
googletools/fixtures/analytics_codes.json [new file with mode: 0644]
googletools/fixtures/site_verification_codes.json [new file with mode: 0644]
googletools/fixtures/sites.json [new file with mode: 0644]
googletools/templates/googletools/tests/analytics_code_in.html [new file with mode: 0644]
googletools/templates/googletools/tests/analytics_code_out_a.html [new file with mode: 0644]
googletools/templates/googletools/tests/analytics_code_out_b.html [new file with mode: 0644]
googletools/templates/googletools/tests/site_verification_code_in.html [new file with mode: 0644]
googletools/templates/googletools/tests/site_verification_code_out_a.html [new file with mode: 0644]
googletools/templates/googletools/tests/site_verification_code_out_b.html [new file with mode: 0644]
googletools/templatetags/googletools.py
googletools/tests.py [new file with mode: 0644]

index ad8713ce0f4a53866c7a553303a19d4a3deaca34..e4efeedfa05016a14c5c8e79d4ac71b76b9dc407 100644 (file)
@@ -1,3 +1,4 @@
 include README.mdown
 
 recursive-include googletools/templates *
+recursive-include googletools/fixtures *
\ No newline at end of file
diff --git a/googletools/fixtures/analytics_codes.json b/googletools/fixtures/analytics_codes.json
new file mode 100644 (file)
index 0000000..ba109b5
--- /dev/null
@@ -0,0 +1,18 @@
+[
+    {
+        "pk": 1, 
+        "model": "googletools.analyticscode", 
+        "fields": {
+            "code": "analytics-a", 
+            "site": 1
+        }
+    }, 
+    {
+        "pk": 2, 
+        "model": "googletools.analyticscode", 
+        "fields": {
+            "code": "analytics-b", 
+            "site": 2
+        }
+    }
+]
diff --git a/googletools/fixtures/site_verification_codes.json b/googletools/fixtures/site_verification_codes.json
new file mode 100644 (file)
index 0000000..0b0f1dc
--- /dev/null
@@ -0,0 +1,18 @@
+[
+    {
+        "pk": 1, 
+        "model": "googletools.siteverificationcode", 
+        "fields": {
+            "code": "verification-a", 
+            "site": 1
+        }
+    }, 
+    {
+        "pk": 2, 
+        "model": "googletools.siteverificationcode", 
+        "fields": {
+            "code": "verification-b", 
+            "site": 2
+        }
+    }
+]
diff --git a/googletools/fixtures/sites.json b/googletools/fixtures/sites.json
new file mode 100644 (file)
index 0000000..dbbafeb
--- /dev/null
@@ -0,0 +1,18 @@
+[
+    {
+        "pk": 1, 
+        "model": "sites.site", 
+        "fields": {
+            "domain": "www.domaina.com", 
+            "name": "Site A"
+        }
+    }, 
+    {
+        "pk": 2, 
+        "model": "sites.site", 
+        "fields": {
+            "domain": "www.domainb.com", 
+            "name": "Site B"
+        }
+    }
+]
diff --git a/googletools/templates/googletools/tests/analytics_code_in.html b/googletools/templates/googletools/tests/analytics_code_in.html
new file mode 100644 (file)
index 0000000..50fe94f
--- /dev/null
@@ -0,0 +1 @@
+{% load googletools %}{% analytics_code %}
\ No newline at end of file
diff --git a/googletools/templates/googletools/tests/analytics_code_out_a.html b/googletools/templates/googletools/tests/analytics_code_out_a.html
new file mode 100644 (file)
index 0000000..3fc38b9
--- /dev/null
@@ -0,0 +1,9 @@
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+var pageTracker = _gat._getTracker("analytics-a");
+pageTracker._initData();
+pageTracker._trackPageview();
+</script>
\ No newline at end of file
diff --git a/googletools/templates/googletools/tests/analytics_code_out_b.html b/googletools/templates/googletools/tests/analytics_code_out_b.html
new file mode 100644 (file)
index 0000000..b75368f
--- /dev/null
@@ -0,0 +1,9 @@
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+var pageTracker = _gat._getTracker("analytics-b");
+pageTracker._initData();
+pageTracker._trackPageview();
+</script>
\ No newline at end of file
diff --git a/googletools/templates/googletools/tests/site_verification_code_in.html b/googletools/templates/googletools/tests/site_verification_code_in.html
new file mode 100644 (file)
index 0000000..46cc8cf
--- /dev/null
@@ -0,0 +1 @@
+{% load googletools %}{% site_verification_code %}
\ No newline at end of file
diff --git a/googletools/templates/googletools/tests/site_verification_code_out_a.html b/googletools/templates/googletools/tests/site_verification_code_out_a.html
new file mode 100644 (file)
index 0000000..5f1a6c3
--- /dev/null
@@ -0,0 +1 @@
+<meta name="google-site-verification" content="verification-a" />
\ No newline at end of file
diff --git a/googletools/templates/googletools/tests/site_verification_code_out_b.html b/googletools/templates/googletools/tests/site_verification_code_out_b.html
new file mode 100644 (file)
index 0000000..7feffc1
--- /dev/null
@@ -0,0 +1 @@
+<meta name="google-site-verification" content="verification-b" />
\ No newline at end of file
index 4710b4d80d796f24e8ec2c05105ad61700dee19f..1a77ad27fc30ca25ec5a9dd2476acd9e867220e0 100644 (file)
@@ -11,8 +11,8 @@ register = template.Library()
 
 class AnalyticsCodeNode(template.Node):
     
-    def __init__(self):
-        self.site = Site.objects.get_current()
+    def __init__(self, site):
+        self.site = site
         self.template = 'googletools/analytics_code.html'
         try:
             self.code = AnalyticsCode.objects.get(site=self.site)
@@ -31,8 +31,8 @@ class AnalyticsCodeNode(template.Node):
 
 class SiteVerificationCodeNode(template.Node):
     
-    def __init__(self):
-        self.site = Site.objects.get_current()
+    def __init__(self, site):
+        self.site = site
         self.template = 'googletools/site_verification_code.html'
         try:
             self.code = SiteVerificationCode.objects.get(site=self.site)
@@ -62,8 +62,7 @@ def analytics_code(parser, token):
         tag_name = token.split_contents()
     except ValueError:
         raise template.TemplateSyntaxError, '%r does not take any arguments' % token.contents.split()[0]
-    return AnalyticsCodeNode()
-
+    return AnalyticsCodeNode(site=Site.objects.get_current())
 
 @register.tag
 def site_verification_code(parser, token):
@@ -78,4 +77,4 @@ def site_verification_code(parser, token):
         tag_name = token.split_contents()
     except ValueError:
         raise template.TemplateSyntaxError, '%r does not take any arguments' % token.contents.split()[0]
-    return SiteVerificationCodeNode()
+    return SiteVerificationCodeNode(site=Site.objects.get_current())
diff --git a/googletools/tests.py b/googletools/tests.py
new file mode 100644 (file)
index 0000000..8d7d6f6
--- /dev/null
@@ -0,0 +1,50 @@
+from django.contrib.sites.models import Site
+from django.template.loader import render_to_string
+from django.test import TestCase
+
+from googletools.templatetags.googletools import AnalyticsCodeNode, \
+    SiteVerificationCodeNode
+
+
+class AnalyticsCodeTestCase(TestCase):
+    fixtures = ['sites', 'analytics_codes']
+    
+    def setUp(self):
+        self.site_a = Site.objects.get(pk=1)
+        self.site_b = Site.objects.get(pk=2)
+        self.correct_out_a = render_to_string('googletools/tests/analytics_code_out_a.html', {})
+        self.correct_out_b = render_to_string('googletools/tests/analytics_code_out_b.html', {})
+    
+    def test_templatetag(self):
+        code_in = render_to_string('googletools/tests/analytics_code_in.html', {})
+        self.assertEqual(code_in, self.correct_out_a)
+    
+    def test_node_site_a(self):
+        node = AnalyticsCodeNode(site=self.site_a)
+        self.assertEqual(node.render(None), self.correct_out_a)
+    
+    def test_node_site_b(self):
+        node = AnalyticsCodeNode(site=self.site_b)
+        self.assertEqual(node.render(None), self.correct_out_b)
+
+
+class SiteVerificationCodeTestCase(TestCase):
+    fixtures = ['sites', 'site_verification_codes']
+    
+    def setUp(self):
+        self.site_a = Site.objects.get(pk=1)
+        self.site_b = Site.objects.get(pk=2)
+        self.correct_out_a = render_to_string('googletools/tests/site_verification_code_out_a.html', {})
+        self.correct_out_b = render_to_string('googletools/tests/site_verification_code_out_b.html', {})
+    
+    def test_templatetag(self):
+        code_in = render_to_string('googletools/tests/site_verification_code_in.html', {})
+        self.assertEqual(code_in, self.correct_out_a)
+    
+    def test_node_site_a(self):
+        node = SiteVerificationCodeNode(site=self.site_a)
+        self.assertEqual(node.render(None), self.correct_out_a)
+    
+    def test_node_site_b(self):
+        node = SiteVerificationCodeNode(site=self.site_b)
+        self.assertEqual(node.render(None), self.correct_out_b)