Browse Source

Radicale: test required code

Bastien Sevajol (Algoo) 9 years ago
parent
commit
c852e76996

+ 7 - 0
tracim/test.ini View File

36
 ldap_group_enabled = False
36
 ldap_group_enabled = False
37
 use = config:development.ini
37
 use = config:development.ini
38
 
38
 
39
+[app:radicale]
40
+sqlalchemy.url = postgresql://postgres:dummy@127.0.0.1:5432/tracim_test?client_encoding=utf8
41
+radicale.server.filesystem.folder = /tmp/tracim_tests_radicale_fs
42
+radicale.server.port = 15232
43
+radicale.client.port = 15232
44
+use = config:development.ini
45
+
39
 # Add additional test specific configuration options as necessary.
46
 # Add additional test specific configuration options as necessary.

+ 3 - 1
tracim/tracim/config/app_cfg.py View File

217
         ]
217
         ]
218
 
218
 
219
         self.RADICALE_SERVER_HOST = tg.config.get('radicale.server.host', '0.0.0.0')
219
         self.RADICALE_SERVER_HOST = tg.config.get('radicale.server.host', '0.0.0.0')
220
-        self.RADICALE_SERVER_PORT = tg.config.get('radicale.server.port', 5232)
220
+        self.RADICALE_SERVER_PORT = int(
221
+            tg.config.get('radicale.server.port', 5232)
222
+        )
221
         # Note: Other parameters needed to work in SSL (cert file, etc)
223
         # Note: Other parameters needed to work in SSL (cert file, etc)
222
         self.RADICALE_SERVER_SSL = asbool(tg.config.get('radicale.server.ssl', False))
224
         self.RADICALE_SERVER_SSL = asbool(tg.config.get('radicale.server.ssl', False))
223
         self.RADICALE_SERVER_FILE_SYSTEM_FOLDER = tg.config.get(
225
         self.RADICALE_SERVER_FILE_SYSTEM_FOLDER = tg.config.get(

+ 3 - 2
tracim/tracim/lib/calendar.py View File

24
 CALENDAR_TYPE_USER = UserCalendar
24
 CALENDAR_TYPE_USER = UserCalendar
25
 CALENDAR_TYPE_WORKSPACE = WorkspaceCalendar
25
 CALENDAR_TYPE_WORKSPACE = WorkspaceCalendar
26
 
26
 
27
+CALENDAR_BASE_URL = '{proto}://{domain}:{port}'
27
 CALENDAR_USER_URL_TEMPLATE = \
28
 CALENDAR_USER_URL_TEMPLATE = \
28
-    '{proto}://{domain}:{port}/user/{id}.ics#{slug}'
29
+    CALENDAR_BASE_URL + '/user/{id}.ics#{slug}'
29
 CALENDAR_WORKSPACE_URL_TEMPLATE = \
30
 CALENDAR_WORKSPACE_URL_TEMPLATE = \
30
-    '{proto}://{domain}:{port}/workspace/{id}.ics#{slug}'
31
+    CALENDAR_BASE_URL + '/workspace/{id}.ics#{slug}'
31
 
32
 
32
 
33
 
33
 class CalendarManager(object):
34
 class CalendarManager(object):

+ 29 - 4
tracim/tracim/lib/daemons.py View File

1
 import threading
1
 import threading
2
 from wsgiref.simple_server import make_server
2
 from wsgiref.simple_server import make_server
3
-
4
 import signal
3
 import signal
4
+import transaction
5
 
5
 
6
 from radicale import Application as RadicaleApplication
6
 from radicale import Application as RadicaleApplication
7
-from radicale import HTTPServer as RadicaleHTTPServer
8
-from radicale import HTTPSServer as RadicaleHTTPSServer
7
+from radicale import HTTPServer as BaseRadicaleHTTPServer
8
+from radicale import HTTPSServer as BaseRadicaleHTTPSServer
9
 from radicale import RequestHandler as RadicaleRequestHandler
9
 from radicale import RequestHandler as RadicaleRequestHandler
10
 from radicale import config as radicale_config
10
 from radicale import config as radicale_config
11
-from tg import TGApp
12
 
11
 
13
 from tracim.lib.base import logger
12
 from tracim.lib.base import logger
14
 from tracim.lib.exceptions import AlreadyRunningDaemon
13
 from tracim.lib.exceptions import AlreadyRunningDaemon
74
         self._running_daemons = {}
73
         self._running_daemons = {}
75
 
74
 
76
 
75
 
76
+class TracimSocketServerMixin(object):
77
+    """
78
+    Mixin to use with socketserver.BaseServer who add _after_serve_actions
79
+    method executed after end of server execution.
80
+    """
81
+    def serve_forever(self, *args, **kwargs):
82
+        super().serve_forever(*args, **kwargs)
83
+        # After serving (in case of stop) do following:
84
+        self._after_serve_actions()
85
+
86
+    def _after_serve_actions(self):
87
+        """
88
+        Override (and call super if needed) to execute actions when server
89
+        finish it's job.
90
+        """
91
+        transaction.commit()
92
+
93
+
77
 class Daemon(threading.Thread):
94
 class Daemon(threading.Thread):
78
     """
95
     """
79
     Thread who contains daemon. You must implement start and stop methods to
96
     Thread who contains daemon. You must implement start and stop methods to
86
         raise NotImplementedError()
103
         raise NotImplementedError()
87
 
104
 
88
 
105
 
106
+class RadicaleHTTPSServer(TracimSocketServerMixin, BaseRadicaleHTTPSServer):
107
+    pass
108
+
109
+
110
+class RadicaleHTTPServer(TracimSocketServerMixin, BaseRadicaleHTTPServer):
111
+    pass
112
+
113
+
89
 class RadicaleDaemon(Daemon):
114
 class RadicaleDaemon(Daemon):
90
     def __init__(self, *args, **kwargs):
115
     def __init__(self, *args, **kwargs):
91
         super().__init__(*args, **kwargs)
116
         super().__init__(*args, **kwargs)

+ 20 - 0
tracim/tracim/tests/__init__.py View File

28
 
28
 
29
 from tracim.fixtures import FixturesLoader
29
 from tracim.fixtures import FixturesLoader
30
 from tracim.fixtures.users_and_groups import Base as BaseFixture
30
 from tracim.fixtures.users_and_groups import Base as BaseFixture
31
+from tracim.config.app_cfg import daemons
31
 from tracim.lib.base import logger
32
 from tracim.lib.base import logger
32
 from tracim.lib.content import ContentApi
33
 from tracim.lib.content import ContentApi
33
 from tracim.lib.workspace import WorkspaceApi
34
 from tracim.lib.workspace import WorkspaceApi
239
     def tearDown(self):
240
     def tearDown(self):
240
         """Tear down test fixture for each functional test method."""
241
         """Tear down test fixture for each functional test method."""
241
         DBSession.close()
242
         DBSession.close()
243
+        daemons.stop_all()
242
         teardown_db()
244
         teardown_db()
243
 
245
 
244
 
246
 
344
                                                parent=folder,
346
                                                parent=folder,
345
                                                owner=user)
347
                                                owner=user)
346
         return thread
348
         return thread
349
+
350
+
351
+class TestCalendar(TestController):
352
+    application_under_test = 'radicale'
353
+
354
+    def setUp(self):
355
+        super().setUp()
356
+        self._clear_radicale_fs()
357
+
358
+    @staticmethod
359
+    def _clear_radicale_fs():
360
+        radicale_fs_path = config.radicale.server.filesystem.folder
361
+        try:
362
+            files = os.listdir(radicale_fs_path)
363
+            for file in files:
364
+                os.remove('{0}/{1}'.format(radicale_fs_path, file))
365
+        except FileNotFoundError:
366
+            pass  # Dir not exists yet, no need to clear it

+ 27 - 0
tracim/tracim/tests/functional/test_calendar.py View File

1
+import time
2
+
3
+from nose.tools import eq_, ok_
4
+import requests
5
+from requests.exceptions import ConnectionError
6
+
7
+from tracim.lib.calendar import CALENDAR_BASE_URL
8
+from tracim.tests import TestCalendar as BaseTestCalendar
9
+
10
+
11
+class TestCalendar(BaseTestCalendar):
12
+    def test_unit__radicale_connectivity__ok__nominal_case(self):
13
+        from tracim.config.app_cfg import CFG
14
+        cfg = CFG.get_instance()
15
+
16
+        radicale_base_url = CALENDAR_BASE_URL.format(
17
+            proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
18
+            domain=cfg.RADICALE_CLIENT_HOST or '127.0.0.1',
19
+            port=str(cfg.RADICALE_CLIENT_PORT)
20
+        )
21
+        try:
22
+            time.sleep(2)  # TODO - 20160606 - Bastien: sleep to wait ...
23
+            # ... radicale daemon started. We should lock something somewhere !
24
+            response = requests.get(radicale_base_url)
25
+            eq_(response.status_code, 401, 'Radicale http response is 401')
26
+        except ConnectionError:
27
+            ok_(False, 'Unable to contact radicale on HTTP')