Skip to content
Browse files

Merge pull request #509 from gnuwilliam/insight-tests

Insight tests
  • Loading branch information...
2 parents d89ebec + b595a2f commit 2558702035f740759c9b82ece15ccbced550a469 @ebidel ebidel committed
Showing with 28 additions and 0 deletions.
  1. +3 −0 cli/bin/yeomaninsight.py
  2. +25 −0 cli/test/test-insight.py
View
3 cli/bin/yeomaninsight.py
@@ -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
25 cli/test/test-insight.py
@@ -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()

0 comments on commit 2558702

Please sign in to comment.
Something went wrong with that request. Please try again.