def test_td_coap_core_03(self): print("TD_COAP_CORE_03") path = "/test" req = Request() req.code = defines.Codes.PUT.number req.uri_path = path req.type = defines.Types["CON"] req.content_type = defines.Content_types["application/xml"] req._mid = self.current_mid req.destination = self.server_address req.payload = "<value>test</value>" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CHANGED.number expected.token = None expected.payload = None self.current_mid += 1 exchange1 = (req, expected) req = Request() req.code = defines.Codes.GET.number req.uri_path = path req.type = defines.Types["CON"] req._mid = self.current_mid req.destination = self.server_address expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = "Test Resource" self.current_mid += 1 exchange2 = (req, expected) req = Request() req.code = defines.Codes.GET.number req.uri_path = path req.type = defines.Types["CON"] req._mid = self.current_mid req.destination = self.server_address req.accept = defines.Content_types["application/xml"] expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = "<value>test</value>" expected.content_type = defines.Content_types["application/xml"] self.current_mid += 1 exchange3 = (req, expected) self._test_with_client([exchange1, exchange2, exchange3])
async def discover(): timeout = kwargs.get('timeout') _protocol = [] if self.ipv4: _protocol.append(self.eps_coap_ipv4) if self.ipv6: _protocol.append(self.eps_coap_ipv6) _res = None _token = self.coap.message_layer.fetch_token() _mid = self.coap.message_layer.fetch_mid() for elem in _protocol: for ip in elem: for port in elem[ip]: ep = elem[ip][port] request = Request() request.token = _token request.query = { 'owned': ['TRUE'] if kwargs.get('owned') else ['FALSE'] } request.mid = _mid request.type = NON request.code = Code.GET request.uri_path = '/oic/sec/doxm' # request.content_type = 10000 request.accept = 10000 request.source = ep.address request.multicast = True request.family = ep.family request.scheme = ep.scheme option = Option() option.number = defines.OptionRegistry.OCF_ACCEPT_CONTENT_FORMAT_VERSION.number option.value = 2048 request.add_option(option) request.destination = ( self.coap_discovery[ep.family][0], self.coap_discovery_port) _res = asyncio.create_task( self.coap.send_message(request, timeout=timeout)) # _res.append(self.coap.send_message(request)) return await _res # все вернется одновременно потому что токен один