cubicweb/test/unittest_cwctl.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Mon, 06 Mar 2017 14:19:20 +0100
changeset 12008 7694dcf5ad30
parent 11469 e0538fee4caa
child 12020 304477158337
permissions -rw-r--r--
[etwist] Do not call repository's start_looping_tasks anymore and warn about this We are about to drop this method from Repository class and replace it by a blocking alternative. This is not compatible with how things currently work in a Twisted server implementation. So do not start repository "looping tasks" in Twisted server anymore and issue a warning about this. If someone is interested in restoring the "all-in-one" behavior where the repository runs within a Twisted server, they may start by implementing repository looping tasks using a Twisted mechanism such as, e.g., http://twistedmatrix.com/documents/current/core/howto/time.html and eventually provide the repository with a compatible scheduler instance so that is can register its periodic tasks. At the moment, we lack resources to do this (and maintain the Twisted server of CubicWeb in general). Related to #17057223.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9639
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
     1
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
import sys
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
import os
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6197
diff changeset
    20
from os.path import join
10721
e9abbaa835f5 [tests] Port unittest_cwctl to py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    21
from io import StringIO, BytesIO
11469
e0538fee4caa [test] Use plain unittest in unittest_cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    22
import unittest
10721
e9abbaa835f5 [tests] Port unittest_cwctl to py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    23
e9abbaa835f5 [tests] Port unittest_cwctl to py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    24
from six import PY2
e9abbaa835f5 [tests] Port unittest_cwctl to py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    25
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
from cubicweb.cwconfig import CubicWebConfiguration
5430
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    27
from cubicweb.devtools.testlib import CubicWebTC
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    28
from cubicweb.server.migractions import ServerMigrationHelper
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    29
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    30
CubicWebConfiguration.load_cwctl_plugins() # XXX necessary?
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
5430
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    32
11469
e0538fee4caa [test] Use plain unittest in unittest_cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    33
class CubicWebCtlTC(unittest.TestCase):
e0538fee4caa [test] Use plain unittest in unittest_cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    34
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    def setUp(self):
10721
e9abbaa835f5 [tests] Port unittest_cwctl to py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    36
        self.stream = BytesIO() if PY2 else StringIO()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        sys.stdout = self.stream
11469
e0538fee4caa [test] Use plain unittest in unittest_cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    38
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    def tearDown(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        sys.stdout = sys.__stdout__
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    41
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    def test_list(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
        from cubicweb.cwctl import ListCommand
6197
d8f0dce0b86d [test] fixes to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5436
diff changeset
    44
        ListCommand(None).run([])
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    45
5430
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    46
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    47
class CubicWebShellTC(CubicWebTC):
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    48
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    49
    def test_process_script_args_context(self):
9639
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    50
        repo = self.repo
10353
d9a1e7939ee6 [migractions] remove any session related leftovers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9639
diff changeset
    51
        with self.admin_access.repo_cnx() as cnx:
9639
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    52
            mih = ServerMigrationHelper(None, repo=repo, cnx=cnx,
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    53
                                        interactive=False,
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    54
                                        # hack so it don't try to load fs schema
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    55
                                        schema=1)
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    56
            scripts = {'script1.py': list(),
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    57
                       'script2.py': ['-v'],
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    58
                       'script3.py': ['-vd', '-f', 'FILE.TXT'],
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    59
                      }
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    60
            mih.cmd_process_script(join(self.datadir, 'scripts', 'script1.py'),
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    61
                                   funcname=None)
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    62
            for script, args in scripts.items():
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    63
                scriptname = os.path.join(self.datadir, 'scripts', script)
10600
180aa08cad48 [tests] Replace use of deprecated TestCase.assert_
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10353
diff changeset
    64
                self.assertTrue(os.path.exists(scriptname))
9639
74b3db5bb41d [test] silence warnings for unittest_cwctl by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6632
diff changeset
    65
                mih.cmd_process_script(scriptname, None, scriptargs=args)
5430
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    66
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
    67
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
if __name__ == '__main__':
11469
e0538fee4caa [test] Use plain unittest in unittest_cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    69
    unittest.main()