Add unit tests for messaging
@@ -19,6 +19,7 @@ import mock
import mycroft.api
import mycroft.configuration
+from mycroft.util.log import LOG
CONFIG = {
'server': {
@@ -169,6 +170,26 @@ class TestApi(unittest.TestCase):
self.assertEquals(
url, 'https://api-test.mycroft.ai/v1/device/1234/setting')
+ @mock.patch('mycroft.api.IdentityManager.get')
+ @mock.patch('mycroft.api.requests.request')
+ def test_device_send_email(self, mock_request, mock_identity_get):
+ mock_request.return_value = create_response(200, {})
+ mock_identity = mock.MagicMock()
+ mock_identity.is_expired.return_value = False
+ mock_identity.uuid = '1234'
+ mock_identity_get.return_value = mock_identity
+ device = mycroft.api.DeviceApi()
+ device.send_email('title', 'body', 'sender')
+ url = mock_request.call_args[0][1]
+ params = mock_request.call_args[1]
+
+ content_type = params['headers']['Content-Type']
+ correct_json = {'body': 'body', 'sender': 'sender', 'title': 'title'}
+ self.assertEquals(content_type, 'application/json')
+ self.assertEquals(params['json'], correct_json)
+ self.assertEquals(
+ url, 'https://api-test.mycroft.ai/v1/device/1234/message')
+
@mock.patch('mycroft.api.IdentityManager.get')
@mock.patch('mycroft.api.requests.request')
def test_device_get_location(self, mock_request, mock_identity_get):
