author | Florent Cayré <florent.cayre@logilab.fr> |
Wed, 04 May 2016 17:07:41 +0200 | |
changeset 11240 | 1694e6e9ff94 |
parent 11138 | 78c8e64f3cef |
child 11756 | 60fed6272771 |
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 |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
|
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 |
class SynchronizeSourceTC(CubicWebTC): |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
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
|
7 |
with self.admin_access.web_request(vid='cw.source-sync') as req: |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
source = req.create_entity('CWSource', name=u'ext', type=u'datafeed', |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
parser=u'cw.entityxml') |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
req.cnx.commit() |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
self.threads = 0 |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
14 |
def threaded_task(func): |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
self.threads += 1 |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
|
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
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
|
18 |
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
|
19 |
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
|
20 |
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
|
21 |
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
|
22 |
|
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 |
if __name__ == '__main__': |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
import unittest |
78c8e64f3cef
[sources] synchronize source asynchronously when started from the UI
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
unittest.main() |