Ejemplo n.º 1
0
    class Test(test_suite.Lwm2mSingleServerTest):
        def setUp(self, coap_server: coap.Server = None):
            super().setUp()

            self.file_server_thread = CoapFileServerThread(coap_server or coap.Server())
            self.file_server_thread.start()

            self.tempfile = tempfile.NamedTemporaryFile()

        @property
        def file_server(self):
            return self.file_server_thread.file_server

        def register_resource(self, path, *args, **kwargs):
            with self.file_server as file_server:
                file_server.set_resource(path, *args, **kwargs)
                return file_server.get_resource_uri(path)

        def tearDown(self):
            try:
                super().tearDown()
            finally:
                self.tempfile.close()
                self.file_server_thread.join()

        def read(self, path: Lwm2mPath):
            req = Lwm2mRead(path)
            self.serv.send(req)
            res = self.serv.recv()
            self.assertMsgEqual(Lwm2mContent.matching(req)(), res)
            return res.content

        def wait_until_downloads_finished(self):
            while self.get_socket_count() > len(self.servers):
                time.sleep(0.1)
Ejemplo n.º 2
0
    class Test(test_suite.Lwm2mSingleServerTest):
        def setUp(self, coap_server: coap.Server = None):
            super().setUp()

            self.file_server_thread = CoapFileServerThread(coap_server
                                                           or coap.Server())
            self.file_server_thread.start()
            self.file_server = self.file_server_thread.file_server

            self.tempfile = tempfile.NamedTemporaryFile()

        def tearDown(self):
            try:
                super().tearDown()
            finally:
                self.tempfile.close()
                self.file_server_thread.join()

        def read(self, path: Lwm2mPath):
            req = Lwm2mRead(path)
            self.serv.send(req)
            res = self.serv.recv()
            self.assertMsgEqual(Lwm2mContent.matching(req)(), res)
            return res.content

        def count_client_sockets(self):
            return int(
                self.communicate(
                    'socket-count',
                    match_regex='SOCKET_COUNT==([0-9]+)\n').group(1))

        def wait_until_downloads_finished(self):
            while self.count_client_sockets() > len(self.servers):
                time.sleep(0.1)
Ejemplo n.º 3
0
    class TestWithCoapServer(Test):
        def setUp(self):
            super().setUp()

            self.server_thread = CoapFileServerThread()
            self.server_thread.start()
            self.file_server = self.server_thread.file_server

        def tearDown(self):
            try:
                super().tearDown()
            finally:
                self.server_thread.join()
Ejemplo n.º 4
0
    class TestWithCoapServer(Test):
        def setUp(self, coap_server=None, *args, **kwargs):
            super().setUp(*args, **kwargs)

            self.server_thread = CoapFileServerThread(coap_server=coap_server)
            self.server_thread.start()

        @property
        def file_server(self):
            return self.server_thread.file_server

        def tearDown(self):
            try:
                super().tearDown()
            finally:
                self.server_thread.join()