File indexing completed on 2024-05-19 05:21:55
0001 # Copyright (c) 2019 Alexander Potashev <aspotashev@gmail.com> 0002 # 0003 # This program is free software; you can redistribute it and/or 0004 # modify it under the terms of the GNU General Public License as 0005 # published by the Free Software Foundation; either version 2 of 0006 # the License or (at your option) version 3 or any later version 0007 # accepted by the membership of KDE e.V. (or its successor approved 0008 # by the membership of KDE e.V.), which shall act as a proxy 0009 # defined in Section 14 of version 3 of the license. 0010 # 0011 # This program is distributed in the hope that it will be useful, 0012 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 # GNU General Public License for more details. 0015 # 0016 # You should have received a copy of the GNU General Public License 0017 # along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 0019 import threading 0020 import time 0021 import os 0022 from http.server import HTTPServer 0023 0024 from pywebdav.server.fileauth import DAVAuthHandler 0025 from pywebdav.server.fshandler import FilesystemHandler 0026 0027 0028 def webdav_server(): 0029 class DummyConfigDAV: 0030 def getboolean(self, name): 0031 return False 0032 0033 class DummyConfig: 0034 DAV = DummyConfigDAV() 0035 0036 host = 'localhost' 0037 port = 4242 0038 0039 handler = DAVAuthHandler 0040 handler._config = DummyConfig() 0041 0042 handler.DO_AUTH = False 0043 handler.IFACE_CLASS = FilesystemHandler('/tmp', 'http://%s:%d/' % (host, port)) 0044 handler.IFACE_CLASS.baseurl = '' 0045 0046 httpd = HTTPServer((host, port), handler) 0047 0048 httpd.serve_forever() 0049 0050 0051 def test_webdav(app): 0052 remote_path = 'http://localhost:4242/test_ktimetracker_webdav.ics' 0053 local_path = '/tmp/test_ktimetracker_webdav.ics' 0054 0055 try: 0056 os.remove(local_path) 0057 except FileNotFoundError: 0058 pass 0059 0060 # Start webdav server 0061 daemon = threading.Thread(target=webdav_server) 0062 daemon.daemon = True 0063 daemon.start() 0064 time.sleep(2) 0065 0066 # Start KTimeTracker 0067 app.run(remote_path) 0068 0069 # wait till download is ready 0070 time.sleep(1) 0071 0072 # add a todo 0073 todo_name = 'testtodo' 0074 app.addTask(todo_name) 0075 app.saveAll() 0076 time.sleep(1) 0077 0078 with open(local_path, 'r') as content_file: 0079 assert todo_name in content_file.read()