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:
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
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()