async def test_td_coap_link_01(self):
        client, server = await self.start_client_server()
        print("TD_COAP_LINK_CLIENT_01")

        expected = Response()
        expected.type = defines.Type.ACK
        expected.code = defines.Code.CONTENT
        expected.payload = '</group-if1>;if="if1",obs,</group-if2>;if="if2",obs,</group-if3>;if="foo",obs,' \
                           '</group-if4>;obs,</group-type1>;obs,rt="Type1 Type2",</group-type2>;obs,rt="Type2 Type3",' \
                           '</group-type3>;obs,rt="Type1 Type3",</group-type4>;obs,rt,</link1>;obs,</link2>;obs,' \
                           '</link3>;obs,</sz>;obs,sz="10",</type1>;obs,rt="Type1",</type2>;obs,rt="Type2"'

        expected.content_type = defines.ContentType.application_link_format
        expected.source = "127.0.0.1", 5683

        ret = await client.discover(timeout=10)
        self.assertIsInstance(ret, Response)
        expected.mid = ret.mid
        expected.token = ret.token

        if ret == expected:
            print("PASS")
        else:
            print("Received: {0}".format(ret))
            print("Expected: {0}".format(expected))
            print(ret.pretty_print())

        self.assertEqual(ret, expected)

        await self.stop_client_server(client, server)
    async def test_td_coap_link_08(self):
        client, server = await self.start_client_server()
        print("TD_COAP_LINK_CLIENT_08")

        expected = Response()
        expected.type = defines.Type.ACK
        expected.code = defines.Code.CONTENT
        expected.payload = '</link1>;obs,</link2>;obs,</link3>;obs'
        expected.content_type = defines.ContentType.application_link_format
        expected.source = "127.0.0.1", 5683

        ret = await client.discover(timeout=10, uri_query="?href=/link*")
        self.assertIsInstance(ret, Response)
        expected.mid = ret.mid
        expected.token = ret.token

        if ret == expected:
            print("PASS")
        else:
            print("Received: {0}".format(ret))
            print("Expected: {0}".format(expected))
            print(ret.pretty_print())

        self.assertEqual(ret, expected)

        await self.stop_client_server(client, server)
Esempio n. 3
0
    async def test_td_coap_link_08(self):
        client, server = await self.start_client_server()
        print("TD_COAP_LINK_08")
        path = "/.well-known/core"
        req = Request()
        req.code = defines.Code.GET
        req.uri_path = path
        req.uri_query = "?href=/link*"
        req.type = defines.Type.CON
        req.mid = random.randint(1, 1000)
        req.destination = self.server_address
        req.token = utils.generate_random_hex(2)

        expected = Response()
        expected.type = defines.Type.ACK
        expected.mid = req.mid
        expected.code = defines.Code.CONTENT
        expected.payload = '</link1>;obs,</link2>;obs,</link3>;obs'
        expected.token = req.token
        expected.content_type = defines.ContentType.application_link_format
        expected.source = "127.0.0.1", 5683

        transaction = await client.send_request(req)
        ret = await client.receive_response(transaction, 10)

        if ret == expected:
            print("PASS")
        else:
            print("Received: {0}".format(ret))
            print("Expected: {0}".format(expected))
            print(ret.pretty_print())

        self.assertEqual(ret, expected)

        self.stop_client_server(client, server)
    async def test_td_coap_core_01(self):
        client, server = await self.start_client_server()
        print("TD_COAP_CORE_CLIENT_01")
        path = "/test"

        expected = Response()
        expected.type = defines.Type.ACK
        expected.code = defines.Code.CONTENT
        expected.payload = "Test"
        expected.content_type = defines.ContentType.TEXT_PLAIN

        expected.source = "127.0.0.1", 5683

        ret = await client.get(path, timeout=10)
        self.assertIsInstance(ret, Response)
        expected.mid = ret.mid
        expected.token = ret.token
        if ret == expected:
            print("PASS")
        else:
            print("Received: {0}".format(ret))
            print("Expected: {0}".format(expected))

        self.assertEqual(ret, expected)

        await self.stop_client_server(client, server)
    async def test_td_coap_core_14(self):
        client, server = await self.start_client_server()
        print("TD_COAP_CORE_CLIENT_14")
        path = "/query"

        expected = Response()
        expected.type = defines.Type.ACK
        expected.code = defines.Code.CONTENT
        expected.payload = "Query12"
        expected.content_type = defines.ContentType.TEXT_PLAIN
        expected.source = self.server_address

        ret = await client.get(path, timeout=10, uri_query="first=1&second=2")
        self.assertIsInstance(ret, Response)
        expected.token = ret.token
        expected.mid = ret.mid

        if ret == expected:
            print("PASS")
        else:
            print("Received: {0}".format(ret))
            print("Expected: {0}".format(expected))

        self.assertEqual(ret, expected)
        await self.stop_client_server(client, server)
    async def test_td_coap_core_20(self):
        client, server = await self.start_client_server()
        print("TD_COAP_CORE_CLIENT_20")
        path = "/multi-format"

        expected = Response()
        expected.type = defines.Type.ACK
        expected.code = defines.Code.CONTENT
        expected.payload = "1"
        expected.content_type = defines.ContentType.TEXT_PLAIN
        expected.source = self.server_address

        ret = await client.get(path,
                               timeout=10,
                               accept=defines.ContentType.TEXT_PLAIN)
        self.assertIsInstance(ret, Response)
        expected.token = ret.token
        expected.mid = ret.mid

        if ret != expected:
            print("Received: {0}".format(ret))
            print("Expected: {0}".format(expected))
            self.assertEqual(ret, expected)

        expected = Response()
        expected.type = defines.Type.ACK
        expected.code = defines.Code.CONTENT
        expected.payload = "<value>1</value>"
        expected.content_type = defines.ContentType.application_xml
        expected.source = self.server_address

        ret = await client.get(path,
                               timeout=10,
                               accept=defines.ContentType.application_xml)
        self.assertIsInstance(ret, Response)
        expected.token = ret.token
        expected.mid = ret.mid

        if ret == expected:
            print("PASS")
        else:
            print("Received: {0}".format(ret))
            print("Expected: {0}".format(expected))

        self.assertEqual(ret, expected)
        await self.stop_client_server(client, server)