summaryrefslogtreecommitdiff
path: root/tests/test_brain.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-12-30 19:52:57 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2014-12-30 19:52:57 +0100
commitec3e900b05d07b228f68ed2ab42bfd545ac06b92 (patch)
tree1a9d93728f5edfaa049ddfad2639a3c5cdb64793 /tests/test_brain.py
parent74b2639b574ecaf600798d234d93e2d807f63021 (diff)
parent87262c75c3e645358e6587b64c8bd2adca9477b2 (diff)
downloadjasper-client-ec3e900b05d07b228f68ed2ab42bfd545ac06b92.tar.gz
jasper-client-ec3e900b05d07b228f68ed2ab42bfd545ac06b92.zip
Merge pull request #270 from Holzhaus/split-unittests
Split unittests into separate files and move them to tests/
Diffstat (limited to 'tests/test_brain.py')
-rw-r--r--tests/test_brain.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_brain.py b/tests/test_brain.py
new file mode 100644
index 0000000..7b4c482
--- /dev/null
+++ b/tests/test_brain.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8-*-
+import unittest
+import mock
+from client import brain, test_mic
+
+
+DEFAULT_PROFILE = {
+ 'prefers_email': False,
+ 'location': 'Cape Town',
+ 'timezone': 'US/Eastern',
+ 'phone_number': '012344321'
+}
+
+
+class TestBrain(unittest.TestCase):
+
+ @staticmethod
+ def _emptyBrain():
+ mic = test_mic.Mic([])
+ profile = DEFAULT_PROFILE
+ return brain.Brain(mic, profile)
+
+ def testLog(self):
+ """Does Brain correctly log errors when raised by modules?"""
+ my_brain = TestBrain._emptyBrain()
+ unclear = my_brain.modules[-1]
+ with mock.patch.object(unclear, 'handle') as mocked_handle:
+ with mock.patch.object(my_brain._logger, 'error') as mocked_log:
+ mocked_handle.side_effect = KeyError('foo')
+ my_brain.query("zzz gibberish zzz")
+ self.assertTrue(mocked_log.called)
+
+ def testSortByPriority(self):
+ """Does Brain sort modules by priority?"""
+ my_brain = TestBrain._emptyBrain()
+ priorities = filter(lambda m: hasattr(m, 'PRIORITY'), my_brain.modules)
+ target = sorted(priorities, key=lambda m: m.PRIORITY, reverse=True)
+ self.assertEqual(target, priorities)
+
+ def testPriority(self):
+ """Does Brain correctly send query to higher-priority module?"""
+ my_brain = TestBrain._emptyBrain()
+ hn_module = 'HN'
+ hn = filter(lambda m: m.__name__ == hn_module, my_brain.modules)[0]
+
+ with mock.patch.object(hn, 'handle') as mocked_handle:
+ my_brain.query(["hacker news"])
+ self.assertTrue(mocked_handle.called)