server/test/unittest_serverctl.py
author Rémi Cardona <remi.cardona@logilab.fr>
Thu, 10 Dec 2015 12:34:15 +0100
changeset 10960 9e64fddebc89
parent 10825 56ca5f6e0533
permissions -rw-r--r--
merge with 3.21.3 The change in unittest_serverctl.py is needed because of daef7ce08fea (from 3.20.11) and 3914388b2d0f (from the 3.22 branch). Due to both changes, CubicWebTC.config.repository no longer creates a new repository (and thus, a new connection). Since both DBDumpCommand and CubicWebTC.tearDown try to shutdown the repo, tearDown breaks apart. The solution is to temporarily disable ServerConfiguration's config cache. By forcing DBDumpCommand to get a new configuration object, it then gets its own Repo object, allowing tearDown and DBDumpCommand to work independently.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
10960
9e64fddebc89 merge with 3.21.3
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10825
diff changeset
     4
from cubicweb.devtools import testlib, ApptestConfiguration
10825
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     5
from cubicweb.server.serverctl import _local_dump, DBDumpCommand
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     6
from cubicweb.server.serverconfig import ServerConfiguration
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     7
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     8
class ServerCTLTC(testlib.CubicWebTC):
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     9
    def setUp(self):
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    10
        super(ServerCTLTC, self).setUp()
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    11
        self.orig_config_for = ServerConfiguration.config_for
10960
9e64fddebc89 merge with 3.21.3
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10825
diff changeset
    12
        config_for = lambda appid: ApptestConfiguration(appid, apphome=self.datadir)
9e64fddebc89 merge with 3.21.3
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10825
diff changeset
    13
        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
    14
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    15
    def tearDown(self):
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    16
        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
    17
        super(ServerCTLTC, self).tearDown()
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    18
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    19
    def test_dump(self):
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    20
        DBDumpCommand(None).run([self.appid])
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    21
        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
    22
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    23
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    24
if __name__ == '__main__':
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    25
    from unittest import main
56ca5f6e0533 [server/test] add test for db-dump command
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    26
    main()