Exemple #1
0
def create_default_coap_message_factory():
    return coap.CoapMessageFactory(
        options_factory=coap.CoapOptionsFactory(),
        uri_path_based_payload_factories=
        create_default_uri_path_based_payload_factories(),
        message_id_to_uri_path_binder=coap.CoapMessageIdToUriPathBinder(),
    )
Exemple #2
0
    def test_should_create_CoapMessage_from_solicit_response_data_when_parse_method_is_called(
            self):
        # GIVEN
        data = bytearray([
            0x62, 0x44, 0x00, 0xbd, 0x65, 0xee, 0xff, 0x04, 0x01, 0x00, 0x02,
            0x02, 0x00, 0x00, 0x07, 0x09, 0x76, 0x80, 0x00, 0x01, 0x00, 0x00,
            0x00, 0x00, 0x00
        ])

        mid_binder = coap.CoapMessageIdToUriPathBinder()
        mid_binder.add_uri_path_for(189, bytearray([0x65, 0xee]), "/a/as")

        factory = coap.CoapMessageFactory(
            options_factory=coap.CoapOptionsFactory(),
            uri_path_based_payload_factories={
                "/a/as": self._create_dummy_payload_factory()
            },
            message_id_to_uri_path_binder=mid_binder)

        # WHEN
        coap_message = factory.parse(io.BytesIO(data), None)

        # THEN
        self.assertEqual(1, coap_message.version)
        self.assertEqual(2, coap_message.type)
        self.assertEqual(2, coap_message.tkl)
        self.assertEqual("2.04", coap_message.code)
        self.assertEqual(189, coap_message.message_id)
        self.assertEqual(bytearray([0x65, 0xee]), coap_message.token)
        self.assertEqual(None, coap_message.uri_path)
        self.assertEqual(
            bytearray([
                0x04, 0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x07, 0x09, 0x76,
                0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
            ]), coap_message.payload)
Exemple #3
0
 def _create_coap_message_factory(self):
     return coap.CoapMessageFactory(
         options_factory=coap.CoapOptionsFactory(),
         uri_path_based_payload_factories={
             "/a/as": self._create_dummy_payload_factory()
         },
         message_id_to_uri_path_binder=coap.CoapMessageIdToUriPathBinder())
Exemple #4
0
    def test_should_create_list_of_CoapOption_from_bytearray_when_parse_method_is_called(self):
        # GIVEN
        delta = any_4bits_value_lower_or_equal_than_12()
        length = any_4bits_value_lower_or_equal_than_12()
        value = any_bytearray(length)

        data = bytearray([delta << 4 | length]) + value

        factory = coap.CoapOptionsFactory()

        # WHEN
        coap_options = factory.parse(io.BytesIO(data), None)

        # THEN
        self.assertEqual(1, len(coap_options))
        self.assertEqual(delta, coap_options[0].type)
        self.assertEqual(value, coap_options[0].value)