author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 30 Sep 2016 17:36:40 +0200 | |
changeset 11756 | 60fed6272771 |
parent 11138 | 78c8e64f3cef |
child 11767 | 432f87a63057 |
permissions | -rw-r--r-- |
11138
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
from logilab.common import tempattr |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
from cubicweb.devtools.testlib import CubicWebTC |
11756
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
3 |
from cubicweb.server.sources import datafeed |
11138
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
class SynchronizeSourceTC(CubicWebTC): |
11756
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
7 |
|
11138
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
def test_synchronize_view(self): |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
with self.admin_access.web_request(vid='cw.source-sync') as req: |
11756
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
10 |
|
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
11 |
class AParser(datafeed.DataFeedParser): |
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
12 |
__regid__ = 'testparser' |
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
13 |
|
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
14 |
def process(self, url, raise_on_error=False): |
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
15 |
pass |
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
16 |
|
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
17 |
with self.temporary_appobjects(AParser): |
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
18 |
source = req.create_entity('CWSource', name=u'ext', type=u'datafeed', |
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
19 |
parser=u'cw.entityxml') |
60fed6272771
[repository] Drop deprecated extid2eid API and friends
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11138
diff
changeset
|
20 |
req.cnx.commit() |
11138
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
22 |
self.threads = 0 |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
23 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
24 |
def threaded_task(func): |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
self.threads += 1 |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
with tempattr(req.cnx.repo, 'threaded_task', threaded_task): |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
28 |
path, args = self.expect_redirect_handle_request( |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
req, path=source.rest_path()) |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
30 |
self.assertEqual(self.threads, 1) |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
31 |
self.assertTrue(path.startswith('cwdataimport/')) |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
32 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
33 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
34 |
if __name__ == '__main__': |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
35 |
import unittest |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
36 |
unittest.main() |