From ee39f33807bc66dcf427684afe8c02d2dc66acf8 Mon Sep 17 00:00:00 2001 From: Richard Freitag Date: Wed, 11 Dec 2024 23:33:49 +0000 Subject: [PATCH] Empty trash bin webdav test --- test_webdav.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test_webdav.py b/test_webdav.py index 124a7ca..f6efade 100644 --- a/test_webdav.py +++ b/test_webdav.py @@ -259,6 +259,54 @@ def run(self): g_testPassed[fullnode] = True g_testThreadsRunning -= 1 +class WebDAVCleanTrashbin(threading.Thread): + def __init__(self, name, TestWebDAV): + threading.Thread.__init__(self) + self.name = name + self.TestWebDAV = TestWebDAV + + def run(self): + global logger + global g_testPassed + global g_testThreadsRunning + fullnode = self.name + g_testPassed[fullnode] = False + g_testThreadsRunning += 1 + logger.info(f'WebDAVCleanTrashbin thread started for node {self.name}') + drv = sunetnextcloud.TestTarget() + + nodeuser = drv.get_seleniumuser(fullnode) + nodepwd = drv.get_seleniumuserpassword(fullnode) + url = drv.get_webdav_url(fullnode, nodeuser) + url = url.replace('files','trashbin') + logger.info(f'URL: {url}') + options = { + 'webdav_hostname': url, + 'webdav_login' : nodeuser, + 'webdav_password' : nodepwd, + 'webdav_timeout': g_webdav_timeout + } + + try: + client = Client(options) + files = client.list(f'trash') + files.pop(0) # Remove first that is just the folder name + for file in files: + try: + targetdeletefile = f'trash/{file}' + logger.info(f'Deleting file {targetdeletefile}') + client.clean(targetdeletefile) + except Exception as error: + logger.warning(f'Unable to delete {targetdeletefile} on {fullnode} due to: {error}') + except Exception as error: + logger.error(f'Error in WebDAVCleanTrashbin thread for node {self.name}: {error}') + g_testPassed[fullnode] = False + g_testThreadsRunning -= 1 + return + logger.info(f'WebDAVCleanTrashbin thread done for node {self.name}') + g_testPassed[fullnode] = True + g_testThreadsRunning -= 1 + class WebDAVMakeSharingFolder(threading.Thread): def __init__(self, name, TestWebDAV): threading.Thread.__init__(self) @@ -720,5 +768,22 @@ def test_cmd_in_system_bucket(self): with self.subTest(mynode=fullnode): self.assertTrue(g_testPassed[fullnode]) + def test_empty_trashbin(self): + global logger + logger.info(f'test_empty_trashbin') + drv = sunetnextcloud.TestTarget() + for fullnode in drv.fullnodes: + with self.subTest(mynode=fullnode): + logger.info(f'TestID: {fullnode}') + WebDAVCleanTrashbinThread = WebDAVCleanTrashbin(fullnode, self) + WebDAVCleanTrashbinThread.start() + + while(g_testThreadsRunning > 0): + time.sleep(1) + + for fullnode in drv.fullnodes: + with self.subTest(mynode=fullnode): + self.assertTrue(g_testPassed[fullnode]) + if __name__ == '__main__': unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))