Add a simple test to google_assistant code.
[python_utils.git] / tests / google_assistant_test.py
1 #!/usr/bin/env python3
2
3 import unittest
4 from unittest.mock import MagicMock, patch
5
6 import google_assistant
7 import unittest_utils  # Needed for --unittests_ignore_perf flag
8
9
10 class TestGoogleAssistant(unittest.TestCase):
11     def test_basic_functionality(self):
12
13         with patch('requests.post') as mock:
14             response = MagicMock()
15             response.status_code = 404
16             mock.return_value = response
17             ret = google_assistant.ask_google('What happens with a 404 response?')
18             self.assertFalse(ret.success)
19             self.assertTrue('failed; code 404' in ret.response)
20             self.assertEqual('', ret.audio_transcription)
21             self.assertEqual('', ret.audio_url)
22
23
24 if __name__ == '__main__':
25     unittest.main()