Example #1
0
 def test_append_push_messages_empty(self, mock_gde):
     mock_gde.__name__ = 'mock_gde'
     context = create_context('TELEKOM_Demo_Intent')
     intent = Intent('TELEKOM_Demo_Intent', random.randint)
     response = intent(context)
     response = intent._append_push_messages(context, response)
     self.assertEqual(response.push_notification, None)
Example #2
0
 def test_init_exceptions(self, warn_mock):
     with self.assertRaises(TypeError):
         Intent({})
     with self.assertRaises(ValueError):
         Intent('', None)
     with self.assertRaises(ValueError):
         Intent('demo_intent', 'random.does_not_exist')
Example #3
0
 def test_append_push_messages_two_messages(self, mock_gde):
     mock_gde.__name__ = 'mock_gde'
     context = create_context('TELEKOM_Demo_Intent')
     intent = Intent('TELEKOM_Demo_Intent', random.randint)
     response = intent(context)
     context.push_messages = {'device': [{'payload': 1}, {'payload': 2}]}
     with self.assertRaises(ValueError):
         _ = intent._append_push_messages(context, response)
Example #4
0
 def test_append_push_messages_one(self, mock_gde):
     mock_gde.__name__ = 'mock_gde'
     context = create_context('TELEKOM_Demo_Intent')
     intent = Intent('TELEKOM_Demo_Intent', random.randint)
     response = intent(context)
     context.push_messages = {'device': [{'payload': 1}]}
     response = intent._append_push_messages(context, response)
     self.assertEqual(response.push_notification, {
         'targetName': 'device',
         'messagePayload': {
             'payload': 1
         }
     })
Example #5
0
    def setUp(self, mock_gde):
        mock_gde.__name__ = 'mock_gde'
        from skill_sdk import routes
        from skill_sdk.intents import Intent
        importlib.reload(skill_sdk.routes)

        self.request = SimpleNamespace()
        self.request.headers = {'Authorization': 'Basic Q1ZJOjAxMjM0NTY3ODk='}
        self.request.json = {
            "context": {
                "attributes": {'location': 'Berlin'},
                "intent": "TELEKOM_Demo_Intent",
                "locale": "de",
                "tokens": {},
                "clientAttributes": {}
            },
            "session": {
                "new": True,
                "id": "12345",
                "attributes": {
                    "key-1": "value-1",
                    "key-2": "value-2"
                }
            },
            "version": 1
        }
        self.intent = Intent("TELEKOM_Demo_Intent", random.randint)
Example #6
0
 def test_response_returns_message(self):
     """ Test if context._ returns l10n.Message
     """
     l10n.translations = {'de': l10n.Translations()}
     context = create_context('TELEKOM_Demo_Intent')
     with patch('random.randint',
                return_value=Response(
                    text=context._('some text'))) as mock_gde:
         mock_gde.__name__ = 'mock_gde'
         intent = Intent('TELEKOM_Demo_Intent', random.randint)
         response = intent(context)
         self.assertIsInstance(response.text, l10n.Message)
Example #7
0
 def test_call_circuit_breaker_open(self, mock_gde):
     mock_gde.__name__ = 'mock_gde'
     intent = Intent('TELEKOM_Demo_Intent', random.randint)
     response = intent(self.ctx)
     self.assertIsInstance(response, Response)
     self.assertEqual(response.text, 'GENERIC_HTTP_ERROR_RESPONSE')
Example #8
0
 def test_call_error_999(self, mock_gde):
     mock_gde.__name__ = 'mock_gde'
     intent = Intent('TELEKOM_Demo_Intent', random.randint)
     self.assertIsInstance(intent(self.ctx), ErrorResponse)
Example #9
0
 def test_call_bad_return_type(self, mock_gde):
     mock_gde.__name__ = 'mock_gde'
     intent = Intent('TELEKOM_Demo_Intent', random.randint)
     with self.assertRaises(ValueError):
         intent(self.ctx).dict(self.ctx)
Example #10
0
 def test_repr(self):
     self.assertIn('TELEKOM_Demo_Intent',
                   repr(Intent('TELEKOM_Demo_Intent', random.randint)))