Insight tests #509

Merged
merged 1 commit into from Sep 23, 2012
Jump to file or symbol
Failed to load files and symbols.
+28 −0
Split
View
@@ -31,6 +31,9 @@ class Analytics(object):
BASE_URL = 'http://www.google-analytics.com/collect/__utm.gif'
def __init__(self, tracking_code):
+ if not tracking_code:
+ raise Exception('No tracking code is given')
+
self.tracking_code = tracking_code
self.do_stats = True
View
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import sys
+import unittest
+import os
+
+sys.path.append('../bin/')
+
+from yeomaninsight import main, Analytics
+
+class YeomanInsightTest(unittest.TestCase):
+
+ def test_init_should_error_when_no_tracking_code_is_passed(self):
+ self.assertRaises(Exception, Analytics, tracking_code='')
+
+ def test_main_should_error_when_arguments_are_less_than_two(self):
+ # temporally disables print function, because it's used on main.
+ # just to keep the tests output clean.
+ sys.stdout = open(os.devnull, 'w')
+ self.assertRaises(SystemExit, main, args='')
+ # restores print function.
+ sys.stdout = sys.__stdout__
+
+if __name__ == '__main__':
+ unittest.main()