summaryrefslogtreecommitdiff
path: root/tests/test_modules.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-12-30 19:09:49 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2014-12-30 19:17:15 +0100
commit7d80c7d7b6c983cd631986b3c74672389c8916d9 (patch)
treee9a7e66082f2603958d8e32fb86c13a8b7653eff /tests/test_modules.py
parent74b2639b574ecaf600798d234d93e2d807f63021 (diff)
downloadjasper-client-7d80c7d7b6c983cd631986b3c74672389c8916d9.tar.gz
jasper-client-7d80c7d7b6c983cd631986b3c74672389c8916d9.zip
Split unittests into separate files and move them to tests/
Diffstat (limited to 'tests/test_modules.py')
-rw-r--r--tests/test_modules.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/test_modules.py b/tests/test_modules.py
new file mode 100644
index 0000000..8f606de
--- /dev/null
+++ b/tests/test_modules.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8-*-
+import unittest
+from client import test_mic, diagnose, jasperpath
+from client.modules import Life, Joke, Time, Gmail, HN, News, Weather
+
+DEFAULT_PROFILE = {
+ 'prefers_email': False,
+ 'location': 'Cape Town',
+ 'timezone': 'US/Eastern',
+ 'phone_number': '012344321'
+}
+
+
+class TestModules(unittest.TestCase):
+
+ def setUp(self):
+ self.profile = DEFAULT_PROFILE
+ self.send = False
+
+ def runConversation(self, query, inputs, module):
+ """Generic method for spoofing conversation.
+
+ Arguments:
+ query -- The initial input to the server.
+ inputs -- Additional input, if conversation is extended.
+
+ Returns:
+ The server's responses, in a list.
+ """
+ self.assertTrue(module.isValid(query))
+ mic = test_mic.Mic(inputs)
+ module.handle(query, mic, self.profile)
+ return mic.outputs
+
+ def testLife(self):
+ query = "What is the meaning of life?"
+ inputs = []
+ outputs = self.runConversation(query, inputs, Life)
+ self.assertEqual(len(outputs), 1)
+ self.assertTrue("42" in outputs[0])
+
+ def testJoke(self):
+ query = "Tell me a joke."
+ inputs = ["Who's there?", "Random response"]
+ outputs = self.runConversation(query, inputs, Joke)
+ self.assertEqual(len(outputs), 3)
+ allJokes = open(jasperpath.data('text', 'JOKES.txt'), 'r').read()
+ self.assertTrue(outputs[2] in allJokes)
+
+ def testTime(self):
+ query = "What time is it?"
+ inputs = []
+ self.runConversation(query, inputs, Time)
+
+ @unittest.skipIf(not diagnose.check_network_connection(),
+ "No internet connection")
+ def testGmail(self):
+ key = 'gmail_password'
+ if key not in self.profile or not self.profile[key]:
+ return
+
+ query = "Check my email"
+ inputs = []
+ self.runConversation(query, inputs, Gmail)
+
+ @unittest.skipIf(not diagnose.check_network_connection(),
+ "No internet connection")
+ def testHN(self):
+ query = "find me some of the top hacker news stories"
+ if self.send:
+ inputs = ["the first and third"]
+ else:
+ inputs = ["no"]
+ outputs = self.runConversation(query, inputs, HN)
+ self.assertTrue("front-page articles" in outputs[1])
+
+ @unittest.skipIf(not diagnose.check_network_connection(),
+ "No internet connection")
+ def testNews(self):
+ query = "find me some of the top news stories"
+ if self.send:
+ inputs = ["the first"]
+ else:
+ inputs = ["no"]
+ outputs = self.runConversation(query, inputs, News)
+ self.assertTrue("top headlines" in outputs[1])
+
+ @unittest.skipIf(not diagnose.check_network_connection(),
+ "No internet connection")
+ def testWeather(self):
+ query = "what's the weather like tomorrow"
+ inputs = []
+ outputs = self.runConversation(query, inputs, Weather)
+ self.assertTrue(
+ "can't see that far ahead" in outputs[0]
+ or "Tomorrow" in outputs[0])