Adds unittest.
authorScott Gasch <[email protected]>
Mon, 7 Feb 2022 18:55:09 +0000 (10:55 -0800)
committerScott Gasch <[email protected]>
Mon, 7 Feb 2022 18:55:09 +0000 (10:55 -0800)
google_assistant.py
tests/google_assistant_test.py

index ec5f6a4c85e17ed0fb2eaaf4f2f22d8ee2ebf300..b0aabf37095ef986b35b726d02700f55d017f78b 100644 (file)
@@ -70,6 +70,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse:
     audio_transcription: Optional[str] = ""
     if r.status_code == 200:
         j = r.json()
+        logger.debug(j)
         success = bool(j["success"])
         response = j["response"] if success else j["error"]
         if success:
index 7699337f257a5072205ebeaeddfce940e230eda5..857c1e4d332875dfd294ab397308e4b6e690b941 100755 (executable)
@@ -8,8 +8,7 @@ import unittest_utils  # Needed for --unittests_ignore_perf flag
 
 
 class TestGoogleAssistant(unittest.TestCase):
-    def test_basic_functionality(self):
-
+    def test_failure_case(self):
         with patch('requests.post') as mock:
             response = MagicMock()
             response.status_code = 404
@@ -20,6 +19,16 @@ class TestGoogleAssistant(unittest.TestCase):
             self.assertEqual('', ret.audio_transcription)
             self.assertEqual('', ret.audio_url)
 
+    def test_success_case(self):
+        with patch('requests.post') as mock:
+            response = MagicMock()
+            response.status_code = 200
+            json = {'response': 'LGTM', 'audio': '', 'success': True}
+            response.json = MagicMock(return_value=json)
+            mock.return_value = response
+            ret = google_assistant.ask_google('Is this thing working?', recognize_speech=False)
+            self.assertTrue(ret.success)
+
 
 if __name__ == '__main__':
     unittest.main()