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])
def test_duplicate_not_completed(self): print("TEST_DUPLICATE_NOT_COMPLETED") path = "/long" 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 = None expected.token = None expected2 = Response() expected2.type = defines.Types["CON"] expected2._mid = None expected2.code = defines.Codes.CONTENT.number expected2.token = None self.current_mid += 1 self._test_plugtest([(req, None), (req, expected), (None, expected2)])
def test_td_coap_core_09(self): print("TD_COAP_CORE_09") path = "/separate" 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 = None expected.token = None expected.payload = None expected2 = Response() expected2.type = defines.Types["CON"] expected2._mid = self.server_mid expected2.code = defines.Codes.CONTENT.number expected2.token = None expected2.payload = "Separate Resource" self.current_mid += 1 self._test_plugtest([(req, expected), (None, expected2)])
async def test_device_self_get_request(self): defines.EXCHANGE_LIFETIME = 2 device0 = Device.init_from_file( di='10000000-0000-0000-0000-000000000001', class_name='EchoDevice', path=self.config_path) await wait_run_device(device0) address = list(device0.transport_layer.eps_coap_ipv4.keys())[0] request = Request() # request.token = _token # request.query = {'owned': ['TRUE']} request.type = NON request.code = Code.GET request.uri_path = '/oic/res' request.content_type = 10000 request.source = ( address, list(device0.transport_layer.eps_coap_ipv4[address].keys())[0]) # request.multicast = True # request.family = _msg.family request.scheme = 'coap' request.destination = ( address, list(device0.transport_layer.eps_coap_ipv4[address].keys())[0]) # request.destination = (address, 5683) res2 = await device0.transport_layer.coap.send_message(request) links = res2.decode_payload() await asyncio.sleep(15) await device0.stop() self.assertGreater(len(links), 7) link = links[0] self.assertIn('href', link) self.assertIn('eps', link) pass
def test_td_coap_obs_01(self): print("TD_COAP_OBS_01") path = "/obs" 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.observe = 0 expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = "Observable Resource" expected.observe = 1 expected2 = Response() expected2.type = defines.Types["CON"] expected2._mid = self.server_mid expected2.code = defines.Codes.CONTENT.number expected2.token = None expected2.payload = "Observable Resource" expected2.observe = 1 self.current_mid += 1 self.server_mid += 1 self._test_plugtest([(req, expected), (None, expected2)])
def encode_to_coap(self): # try: # parsed = urllib.parse.urlparse(self.to.get_endpoint(), allow_fragments=False) # address = (parsed.hostname, parsed.port) # except KeyError: # address = None # return msg2, address request = Request() request.type = NON # request.token = generate_random_token(2) request.destination = destination # request.destination = (sender, 5683) request.multicast = self.multicast request.source = (sender, None) request.code = self.code request.uri_path = self.to.href option = Option() option.number = defines.OptionRegistry.CONTENT_TYPE.number option.value = 10000 request.add_option(option) option = Option() option.number = defines.OptionRegistry.URI_QUERY.number option.value = self.encode_query( self.query) # todo разобраться что тут надо request.add_option(option)
def test_no_response(self): print("TEST_NO_RESPONSE") path = "/long" 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 = None expected.token = None expected2 = Response() expected2.type = defines.Types["CON"] expected2._mid = None expected2.code = defines.Codes.CONTENT.number expected2.token = None self.current_mid += 1 self._test_plugtest([(req, expected), (None, expected2), (None, expected2), (None, expected2)])
def test_td_coap_block_01(self): print("TD_COAP_BLOCK_01") path = "/large" 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.block2 = (0, 0, 1024) expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = None expected.block2 = (0, 1, 1024) expected.size2 = 1990 exchange1 = (req, expected) self.current_mid += 1 self.server_mid += 1 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.block2 = (1, 0, 1024) expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = None expected.block2 = (1, 0, 1024) expected.size2 = 1990 exchange2 = (req, expected) self.current_mid += 1 self.server_mid += 1 self._test_plugtest([exchange1, exchange2])
def _prepare_request(self, operation, to, data=None, *, secure=False, multicast=False, query=None, **kwargs): # secure = kwargs.get('secure', False) # multicast = kwargs.get('multicast', False) scheme = 'coaps' if secure else 'coap' family = to['family'] request = Request() request.type = NON request.scheme = scheme request.multicast = multicast request.family = family request.source = (to['net_interface'], None) if multicast: request.destination = (self.coap_discovery[family][0], self.coap_discovery_port) else: request.destination = to[scheme] request.code = self.map_crudn_to_coap_code(operation) request.uri_path = to.get('href', '') option = Option() option.number = defines.OptionRegistry.CONTENT_TYPE.number option.value = 10000 request.add_option(option) # request.accept = 10000 # query = kwargs.get('query') if query: request.query = query if data: request.encode_payload(data) return request
def _handle_request(self, transaction, new_resource): """ Forward requests. Used by reverse proxies to also create new virtual resources on the proxy in case of created resources :type new_resource: bool :type transaction: Transaction :param transaction: the transaction that owns the request :rtype : Transaction :param new_resource: if the request will generate a new resource :return: the edited transaction """ client = HelperClient(transaction.resource.remote_server) request = Request() request.options = copy.deepcopy(transaction.request.options) del request.block2 del request.block1 del request.uri_path del request.proxy_uri del request.proxy_schema # TODO handle observing del request.observe # request.observe = transaction.request.observe request.uri_path = "/".join( transaction.request.uri_path.split("/")[1:]) request.destination = transaction.resource.remote_server request.payload = transaction.request.payload request.code = transaction.request.code logger.info("forward_request - " + str(request)) response = client.send_request(request) client.stop() logger.info("forward_response - " + str(response)) transaction.response.payload = response.payload transaction.response.code = response.code transaction.response.options = response.options if response.code == defines.Codes.CREATED.number: lp = transaction.response.location_path del transaction.response.location_path transaction.response.location_path = transaction.request.uri_path.split( "/")[0] + "/" + lp # TODO handle observing if new_resource: resource = RemoteResource('server', transaction.resource.remote_server, lp, coap_server=self, visible=True, observable=False, allow_children=True) self._server.add_resource(transaction.response.location_path, resource) if response.code == defines.Codes.DELETED.number: del self._server.root["/" + transaction.request.uri_path] return transaction
def test_get_multiple(self): print("TEST_GET_MULTIPLE") path = "/basic" 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.proxy_uri = "coap://127.0.0.1:5684/basic" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = "Basic Resource" exchange1 = (req, expected) self.current_mid += 1 # PREPARING SECOND EXPECTED RESPONSE (MAX AGE MUST BE CHECKED) req2 = Request() req2.code = defines.Codes.GET.number req2.uri_path = path req2.type = defines.Types["CON"] req2._mid = self.current_mid req2.destination = self.server_address req2.proxy_uri = "coap://127.0.0.1:5684/basic" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = "Basic Resource" expected.max_age = 61 exchange2 = (req2, expected) self._test_with_client_delayed([exchange1, exchange2])
async def get_name(_result): _request = Request() _request.type = NON _request.code = Code.GET _request.uri_path = '/oic/d' _request.content_type = 10000 _request.source = _msg.destination _request.family = _msg.family _request.scheme = _msg.scheme _request.destination = _msg.source resp = await self.coap.send_message(_request) _payload = resp.decode_payload() # result[di]['oic-d'] = json.dumps(_payload) # debug _result['n'] = _payload['n'] _result['di'] = _payload['di']
async def get_eps(_result): _request = Request() _request.type = NON _request.code = Code.GET _request.uri_path = '/oic/res' _request.query = {'rt': ['oic.r.doxm']} _request.content_type = 10000 _request.source = _msg.destination _request.family = _msg.family _request.scheme = _msg.scheme _request.destination = _msg.source _resp = await self.coap.send_message(_request) _payload = _resp.decode_payload() if len(_payload) > 1: self.device.log.error( f'not supported answer /oic/res. {_result.get("di")}') _payload = _payload[0] # result[di]['res'] = json.dumps(_payload) # for debug _eps = [] if 'links' in _payload: _link = _payload['links'] if 'eps' in _link: # todo надо узнать по старому формату eps может быть вообще? _eps = _link['eps'] return else: _eps.append({ 'ep': f'{_msg.family}://{_msg.source[0]}:{_msg.source[1]}' }) try: if 'p' in _link and _link['p'].get( 'sec') and _link['p'].get('port'): _eps.append({ 'ep': f'coaps://{_msg.source[0]}:{_link["p"]["port"]}' }) except Exception: pass return else: _eps = _payload['eps'] _result['family'] = _msg.family for elem in _eps: _url = urlparse(elem['ep']) if _url.scheme in ['coap', 'coaps']: _address = _url.netloc.split(":") _result[_url.scheme] = (_address[0], int(_address[1]))
def test_td_coap_block_01_client(self): print("TD_COAP_BLOCK_01") path = "/large" req = Request() req.code = defines.Codes.GET.number req.uri_path = path req.type = defines.Types["CON"] req._mid = None req.destination = self.server_address req.block2 = (0, 0, 1024) expected = Response() expected.type = defines.Types["ACK"] expected._mid = None expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe and sitting up in bed. "You gettee in," he added, motioning to me with his tomahawk, and throwing the clothes to one side. He really did this in not only a civil but a really kind and charitable way. I stood looking at him a moment. For all his tattooings he was on the whole a clean, comely looking cannibal. What's all this fuss I have been making about, thought I to myself—the man's a human being just as I am: he has just as much reason to fear me, as I have to be afraid of him. Better sleep with a sober cannibal than a drunken Christian. "Landlord," said I, "tell him to stash his tomahawk there, or pipe, or whatever you call it; tell him to stop smoking, in short, and I will turn in with him. But I don't fancy having a man smoking in bed with me. It's dangerous. Besides, I ain't insured." This being told to Queequeg, he at once complied, and again politely motioned me to get into bed—rolling over to one side as much as to say—"I won't touch a leg of ye." "Good night, landlord," said I, "you may go." I turned in, and never slept better in my life. Upon waking next morning about daylight, I found Queequeg's arm thrown over me in the most loving and affectionate manner. You had almost thought I had been his wife. The counterpane was of patchwork, full of odd little parti-coloured squares and triangles; and this arm of his tattooed all over with an interminable Cretan labyrinth of a figure, no two parts of which were of one precise shade—owing I suppose to his keeping his arm at sea unmethodically in sun and shade, his shirt sleeves irregularly rolled up at various times—this same arm of his, I say, looked for all the world like a strip of that same patchwork quilt. Indeed, partly lying on it as the arm did when I first awoke, I could hardly tell it from the quilt, they so blended their hues together; and it was only by the sense of weight and pressure that I could tell that Queequeg was hugging""" expected.block2 = (1, 0, 1024) expected.size2 = 1990 exchange1 = (req, expected) self.current_mid += 1 self.server_mid += 1 self._test_with_client([exchange1])
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 # все вернется одновременно потому что токен один
def test_td_coap_core_12(self): print("TD_COAP_CORE_12") path = "/seg1/seg2/seg3" 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.payload = "Test Resource" self.current_mid += 1 self._test_with_client([(req, expected)])
def test_td_coap_core_08(self): print("TD_COAP_CORE_08") path = "/test" req = Request() req.code = defines.Codes.DELETE.number req.uri_path = path req.type = defines.Types["NON"] req._mid = self.current_mid req.destination = self.server_address expected = Response() expected.type = defines.Types["NON"] expected._mid = None expected.code = defines.Codes.DELETED.number expected.token = None expected.payload = None self.current_mid += 1 self._test_with_client([(req, expected)])
def test_duplicate(self): print("TEST_DUPLICATE") path = "/test" 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 self.current_mid += 1 self._test_plugtest([(req, expected), (req, expected)])
def create_request_get_doxm(sender, destination): request = Request() request.type = NON # request.token = generate_random_token(2) request.destination = destination # request.destination = (sender, 5683) request.multicast = True request.source = (sender, None) request.code = Code.GET request.uri_path = '/oic/sec/doxm' option = Option() option.number = defines.OptionRegistry.CONTENT_TYPE.number option.value = 10000 request.add_option(option) option = Option() option.number = defines.OptionRegistry.URI_QUERY.number option.value = '' request.add_option(option) return request
def test_td_coap_link_01(self): print("TD_COAP_LINK_01") path = "/.well-known/core" 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.content_type = defines.Content_types[ "application/link-format"] expected.payload = """</large>;</large-update>;</long>;</obs>;obs,</query>;rt="Type1";sz="13",</seg1>;rt="Type1";sz="13",</seg1/seg2>;rt="Type1";sz="13",</seg1/seg2/seg3>;rt="Type1";sz="13",</separate>;ct=0;if="separate",</test>;rt="Type1";sz="13",""" self.current_mid += 1 self._test_with_client([(req, expected)])
def test_td_coap_core_07(self): print("TD_COAP_CORE_07") path = "/test" req = Request() req.code = defines.Codes.PUT.number req.uri_path = path req.type = defines.Types["NON"] 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["NON"] expected._mid = None expected.code = defines.Codes.CHANGED.number expected.token = None expected.payload = None self.current_mid += 1 self._test_with_client([(req, expected)])
def test_edit_resource(self): print("TEST_EDIT_RESOURCE") path = "/obs" req = Request() req.code = defines.Codes.POST.number req.uri_path = path req.type = defines.Types["CON"] 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 self._test_with_client([(req, expected)])
def _forward_request(transaction, destination, path): """ Forward requests. :type transaction: Transaction :param transaction: the transaction that owns the request :param destination: the destination of the request (IP, port) :param path: the path of the request. :rtype : Transaction :return: the edited transaction """ client = HelperClient(destination) request = Request() request.options = copy.deepcopy(transaction.request.options) del request.block2 del request.block1 del request.uri_path del request.proxy_uri del request.proxy_schema # TODO handle observing del request.observe # request.observe = transaction.request.observe request.uri_path = path request.destination = destination request.payload = transaction.request.payload request.code = transaction.request.code response = client.send_request(request) client.stop() if response is not None: transaction.response.payload = response.payload transaction.response.code = response.code transaction.response.options = response.options else: transaction.response.code = defines.Codes.SERVICE_UNAVAILABLE.number return transaction
def test_td_coap_block_03(self): print("TD_COAP_BLOCK_03") path = "/large-update" req = Request() req.code = defines.Codes.PUT.number req.uri_path = path req.type = defines.Types["CON"] req._mid = self.current_mid req.destination = self.server_address req.payload = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe """ req.block1 = (0, 1, 64) expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTINUE.number expected.token = None expected.payload = None expected.block1 = (0, 1, 64) exchange1 = (req, expected) self.current_mid += 1 self.server_mid += 1 req = Request() req.code = defines.Codes.PUT.number req.uri_path = path req.type = defines.Types["CON"] req._mid = self.current_mid req.destination = self.server_address req.payload = """and sitting up in bed. "You gettee in," he added, motioning""" req.block1 = (1, 0, 64) expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CHANGED.number expected.token = None expected.payload = None exchange2 = (req, expected) self.current_mid += 1 self.server_mid += 1 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 = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe and sitting up in bed. "You gettee in," he added, motioning""" exchange3 = (req, expected) self.current_mid += 1 self._test_plugtest([exchange1, exchange2, exchange3])
def test_not_allowed(self): print("TEST_NOT_ALLOWED") path = "/void" 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.METHOD_NOT_ALLOWED.number expected.token = None exchange1 = (req, expected) self.current_mid += 1 req = Request() req.code = defines.Codes.POST.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.METHOD_NOT_ALLOWED.number expected.token = None exchange2 = (req, expected) self.current_mid += 1 req = Request() req.code = defines.Codes.PUT.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.METHOD_NOT_ALLOWED.number expected.token = None exchange3 = (req, expected) self.current_mid += 1 req = Request() req.code = defines.Codes.DELETE.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.METHOD_NOT_ALLOWED.number expected.token = None exchange4 = (req, expected) self.current_mid += 1 self._test_with_client([exchange1, exchange2, exchange3, exchange4])
def test_get_etag(self): print("TEST_GET_ETAG") path = "/etag" 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.proxy_uri = "coap://127.0.0.1:5684/etag" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = None expected.etag = str(0) exchange1 = (req, expected) self.current_mid += 1 # PREPARING SECOND EXPECTED RESPONSE req2 = Request() req2.code = defines.Codes.GET.number req2.uri_path = path req2.type = defines.Types["CON"] req2._mid = self.current_mid req2.destination = self.server_address req2.proxy_uri = "coap://127.0.0.1:5684/etag" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.etag = str(0) expected.max_age = 1 exchange2 = (req2, expected) self.current_mid += 1 # PREPARING THIRD EXPECTED RESPONSE req3 = Request() req3.code = defines.Codes.POST.number req3.uri_path = path req3.type = defines.Types["CON"] req3._mid = self.current_mid req3.destination = self.server_address req3.proxy_uri = "coap://127.0.0.1:5684/etag" req3.payload = "Hello" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CHANGED.number expected.token = None expected.payload = None expected.etag = str(1) exchange3 = (req3, expected) self.current_mid += 1 # PREPARING FOURTH EXPECTED RESPONSE req4 = Request() req4.code = defines.Codes.GET.number req4.uri_path = path req4.type = defines.Types["CON"] req4._mid = self.current_mid req4.destination = self.server_address req4.proxy_uri = "coap://127.0.0.1:5684/etag" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = "Hello" expected.etag = str(1) exchange4 = (req4, expected) self.current_mid += 1 self._test_with_client_delayed( [exchange1, exchange2, exchange3, exchange4])
def test_get_delete(self): print("TEST_GET_DELETE") path = "/basic" req2 = Request() req2.code = defines.Codes.GET.number req2.uri_path = path req2.type = defines.Types["CON"] req2._mid = self.current_mid req2.destination = self.server_address req2.proxy_uri = "coap://127.0.0.1:5684/storage/new" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.NOT_FOUND.number expected.token = None expected.payload = None exchange0 = (req2, expected) self.current_mid += 1 req = Request() req.code = defines.Codes.POST.number req.uri_path = path req.type = defines.Types["CON"] req._mid = self.current_mid req.destination = self.server_address req.proxy_uri = "coap://127.0.0.1:5684/storage/new" req.payload = "Hello" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CREATED.number expected.token = None expected.payload = None exchange1 = (req, expected) self.current_mid += 1 # PREPARING SECOND EXPECTED RESPONSE req2 = Request() req2.code = defines.Codes.GET.number req2.uri_path = path req2.type = defines.Types["CON"] req2._mid = self.current_mid req2.destination = self.server_address req2.proxy_uri = "coap://127.0.0.1:5684/storage/new" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.CONTENT.number expected.token = None expected.payload = "Hello" exchange2 = (req2, expected) self.current_mid += 1 # PREPARING THIRD EXPECTED RESPONSE req3 = Request() req3.code = defines.Codes.DELETE.number req3.uri_path = path req3.type = defines.Types["CON"] req3._mid = self.current_mid req3.destination = self.server_address req3.proxy_uri = "coap://127.0.0.1:5684/storage/new" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.DELETED.number expected.token = None expected.payload = None exchange3 = (req3, expected) self.current_mid += 1 # PREPARING FOURTH EXPECTED RESPONSE req4 = Request() req4.code = defines.Codes.GET.number req4.uri_path = path req4.type = defines.Types["CON"] req4._mid = self.current_mid req4.destination = self.server_address req4.proxy_uri = "coap://127.0.0.1:5684/storage/new" expected = Response() expected.type = defines.Types["ACK"] expected._mid = self.current_mid expected.code = defines.Codes.NOT_FOUND.number expected.token = None exchange4 = (req4, expected) self.current_mid += 1 self._test_with_client_delayed( [exchange0, exchange1, exchange2, exchange3, exchange4])