author | Denis Laxalde <denis.laxalde@logilab.fr> |
Mon, 06 Mar 2017 14:38:52 +0100 | |
changeset 12013 | 7b975655d0ae |
parent 12002 | 26453d9467f6 |
child 12016 | 88ed82a25f8a |
permissions | -rw-r--r-- |
10825
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
1 |
import os.path as osp |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
2 |
import shutil |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
3 |
|
11355
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
4 |
from cubicweb import ExecutionError |
10960 | 5 |
from cubicweb.devtools import testlib, ApptestConfiguration |
12002
26453d9467f6
[test] Make unittest_serverctl.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11355
diff
changeset
|
6 |
from cubicweb.server.serverctl import DBDumpCommand, SynchronizeSourceCommand |
10825
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
7 |
from cubicweb.server.serverconfig import ServerConfiguration |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
8 |
|
12002
26453d9467f6
[test] Make unittest_serverctl.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11355
diff
changeset
|
9 |
|
10825
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
10 |
class ServerCTLTC(testlib.CubicWebTC): |
12002
26453d9467f6
[test] Make unittest_serverctl.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11355
diff
changeset
|
11 |
|
10825
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
12 |
def setUp(self): |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
13 |
super(ServerCTLTC, self).setUp() |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
14 |
self.orig_config_for = ServerConfiguration.config_for |
12002
26453d9467f6
[test] Make unittest_serverctl.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11355
diff
changeset
|
15 |
|
26453d9467f6
[test] Make unittest_serverctl.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11355
diff
changeset
|
16 |
def config_for(appid): |
26453d9467f6
[test] Make unittest_serverctl.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11355
diff
changeset
|
17 |
return ApptestConfiguration(appid, __file__) |
26453d9467f6
[test] Make unittest_serverctl.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11355
diff
changeset
|
18 |
|
10960 | 19 |
ServerConfiguration.config_for = staticmethod(config_for) |
10825
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
20 |
|
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
21 |
def tearDown(self): |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
22 |
ServerConfiguration.config_for = self.orig_config_for |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
23 |
super(ServerCTLTC, self).tearDown() |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
24 |
|
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
25 |
def test_dump(self): |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
26 |
DBDumpCommand(None).run([self.appid]) |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
27 |
shutil.rmtree(osp.join(self.config.apphome, 'backup')) |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
28 |
|
11355
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
29 |
def test_source_sync(self): |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
30 |
with self.admin_access.repo_cnx() as cnx: |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
31 |
cnx.create_entity('CWSource', name=u'success_feed', type=u'datafeed', |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
32 |
parser=u'test_source_parser_success', |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
33 |
url=u'ignored') |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
34 |
cnx.create_entity('CWSource', name=u'fail_feed', type=u'datafeed', |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
35 |
parser=u'test_source_parser_fail', |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
36 |
url=u'ignored') |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
37 |
cnx.commit() |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
38 |
|
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
39 |
cmd = SynchronizeSourceCommand(None) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
40 |
cmd.config.force = 1 |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
41 |
|
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
42 |
# Should sync all sources even if one failed |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
43 |
with self.assertRaises(ExecutionError) as exc: |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
44 |
cmd.run([self.appid]) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
45 |
self.assertEqual(len(cnx.find('Card', title=u'success')), 1) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
46 |
self.assertEqual(len(cnx.find('Card', title=u'fail')), 0) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
47 |
self.assertEqual(str(exc.exception), 'All sources where not synced') |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
48 |
|
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
49 |
# call with named sources |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
50 |
cmd.run([self.appid, u'success_feed']) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
51 |
self.assertEqual(len(cnx.find('Card', title=u'success')), 2) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
52 |
|
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
53 |
with self.assertRaises(ExecutionError) as exc: |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
54 |
cmd.run([self.appid, u'fail_feed']) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
55 |
self.assertEqual(str(exc.exception), 'All sources where not synced') |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
56 |
self.assertEqual(len(cnx.find('Card', title=u'fail')), 0) |
47b0b08fbb4b
[serverctl] allow to sync multiple and all sources in source-sync command
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11269
diff
changeset
|
57 |
|
10825
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
58 |
|
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
59 |
if __name__ == '__main__': |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
60 |
from unittest import main |
56ca5f6e0533
[server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
61 |
main() |