def test_result_empty_false(self):
     """ Make sure empty result evaluates to boolean False
     """
     result = Result(None)
     self.assertTrue(not result)
     result = Result({})
     self.assertTrue(not result)
 def test_bool_result_with_secondary_device(self):
     """ [HMPOP-273] TargetDeviceId is nullified if data is empty
     """
     result = Result(None)
     self.assertFalse(result)
     result.target_device_id = 'Target'
     self.assertTrue(result)
Esempio n. 3
0
 def test_target_device_id(self):
     """Test target device id"""
     self.assertIsNone(Result({"a": 1}).target_device_id)
     self.assertEqual(
         Result({
             "a": 1
         }, target_device_id="Primary").target_device_id, "Primary")
 def test_target_device_id(self):
     """ Test target device id
     """
     self.assertIsNone(Result({'a': 1}).target_device_id)
     self.assertEqual(
         Result({
             'a': 1
         }, target_device_id='Primary').target_device_id, 'Primary')
Esempio n. 5
0
 def test_dict(self):
     result = Result({"a": 1}, False, target_device_id="id")
     self.assertEqual(
         {
             "data": {
                 "a": 1
             },
             "local": False,
             "targetDeviceId": "id"
         }, result.dict())
Esempio n. 6
0
    def __init__(self,
                 text: Text,
                 type_: ResponseType = None,
                 result: Dict = None,
                 **data: Any) -> None:
        """
        Accept `text` and `type_` as positional arguments
            and `result` as dictionary for backward compatibility

        :param text:    text to pronounce
        :param type_:   response type
        :param data:
        """
        if "type" in data and type_ is not None:
            raise ValidationError(
                f"Ambiguous response type: 'type_'={type_} and 'type='{data['type']}.",
                type(self),
            )

        params: Dict[str, Any] = dict(text=text)
        if type_ is not None:
            params.update(type=type_)

        if result and isinstance(result, Dict):
            params.update(result=Result(result))

        super().__init__(**{**data, **params})
Esempio n. 7
0
 def test_result_repr(self):
     """Test Result representation"""
     result = Result({"a": 1}, target_device_id="Secondary")
     self.assertEqual(
         "Result(data={'a': 1}, local=True, target_device_id='Secondary')",
         repr(result),
     )
 def test_result_repr(self):
     """ Test Result representation
     """
     result = Result({'a': 1}, target_device_id="Secondary")
     self.assertEqual(
         "{'data': {'a': 1}, 'local': True, 'targetDeviceId': 'Secondary'}",
         repr(result))
Esempio n. 9
0
    def with_command(self, command: Command) -> "SkillInvokeResponse":
        """
        Add a command to execute on the client

        @param command:
        @return:
        """
        result = Result(command.dict())
        return self.copy(update=dict(result=result))
 def test_result_subscriptable(self):
     """ Ensure Result is subscriptable
     """
     result = Result({'a': 1})
     self.assertEqual(result['a'], 1)
 def test_dict(self):
     result = Result({'a': 1}, False)
     self.assertEqual(result.dict(), {'data': {'a': 1}, 'local': False})
 def test_result_local_missing(self):
     result = Result({'a': 1})
     self.assertEqual(result.data, {'a': 1})
     self.assertEqual(result.local, True)
Esempio n. 13
0
 def test_result_local(self):
     result = Result({"a": 1}, True)
     self.assertEqual(result.data, {"a": 1})
     self.assertEqual(result.local, True)
Esempio n. 14
0
 def test_result_updatable(self):
     """Test if Result is updatable and `update` actually updates `data`"""
     result = Result({"a": 0})
     result.update(a=1, b=2)
     self.assertEqual({"a": 1, "b": 2}, result.data)
Esempio n. 15
0
 def test_result_subscriptable(self):
     """Ensure Result is subscriptable"""
     result = Result({"a": 1})
     self.assertEqual(1, result["a"])
 def test_result_updatable(self):
     """ Test if Result is updatable and `update` actually updates `data`
     """
     result = Result({'a': 0})
     result.update(a=1, b=2)
     self.assertEqual(result.data, {'a': 1, 'b': 2})
 def test_result_dict_is_serializable(self):
     """ Test `Result.dict` method returns serializable
     """
     import datetime
     result = Result({'date': datetime.datetime.now()}).dict()
     self.assertIsInstance(result['data']['date'], str)
 def test_result_empty(self):
     with self.assertRaises(TypeError):
         Result(
         )  # Sorry for that Warning, but people seem to ignore it, so we raise an TypeError to catch it
 def test_result_local_false(self):
     result = Result({'a': 1}, False)
     self.assertEqual(result.data, {'a': 1})
     self.assertEqual(result.local, False)
Esempio n. 20
0
 def test_result_empty(self):
     with self.assertRaises(TypeError):
         Result()