def test_1(self): input_msg = { "messageId": 2, "uuid": {"userChannel": "B2C", "userId": "userId", "sub": "sub"}, "payload": { "message": { "original_text": "сверни приложение" }, "device": { "platformType": "android", "platformVersion": "9", "surface": "STARGATE", "surfaceVersion": "1.56.20200828144304", "features": {"appTypes": ["APK", "WEB_APP", "DIALOG"]}, "capabilities": {"mic": {"available": True}, "screen": {"available": True}, "speak": {"available": True}}, "deviceId": "34534545345345", "deviceManufacturer": "SberDevices", "deviceModel": "stargate", "additionalInfo": {} } }, "messageName": "MESSAGE_TO_SKILL" } json_input_msg = json.dumps(input_msg, ensure_ascii=False) topic = "test" headers = [] current_time = current_time_ms() message = SmartAppFromMessage(value=json_input_msg, topic_key=topic, headers=headers, creation_time=current_time) self.assertAlmostEqual(message.creation_time, current_time) self.assertEqual(2, message.incremental_id) self.assertEqual(input_msg["uuid"]["userChannel"], message.channel) self.assertEqual(input_msg["messageName"], message.type) self.assertEqual(input_msg["uuid"]["userId"], message.uid) self.assertEqual(json_input_msg, message.value) self.assertEqual("sub_userId_B2C", message.db_uid) self.assertDictEqual(input_msg["uuid"], message.uuid) self.assertDictEqual(input_msg["payload"], message.payload) device = input_msg["payload"]["device"] self.assertEqual(device["platformType"], message.device.platform_type) self.assertEqual(device["platformVersion"], message.device.platform_version) self.assertEqual(device["surface"], message.device.surface) self.assertEqual(device["surfaceVersion"], message.device.surface_version) self.assertEqual(device["features"], message.device.features) self.assertEqual(device["capabilities"], message.device.capabilities) self.assertEqual(device["additionalInfo"], message.device.additional_info) self.assertEqual(topic, message.topic_key)
def __init__(self, value: str, topic_key: str = None, creation_time=None, kafka_key: str = None, headers=None, masking_fields=None, headers_required=True): self.logging_uuid = str(uuid.uuid4()) self._value = value self.topic_key = topic_key self.kafka_key = kafka_key self.creation_time = creation_time or current_time_ms() self._headers_required = headers_required if self._headers_required and headers is None: raise LookupError( f"{self.__class__.__name__} no incoming headers.") self.headers = Headers(headers) self._callback_id = None # FIXME: by some reason it possibly to change callback_id self.masking_fields = masking_fields
def test_true(self): time = current_time_ms() self.assertTrue(time_check(time, 1 * 1000))
def test_false(self): time = current_time_ms() - 40 * 1000 self.assertFalse(time_check(time, 1 * 1000))