cubicweb/test/unittest_cwctl.py
changeset 11057 0b59724cb3f2
parent 10721 e9abbaa835f5
child 11469 e0538fee4caa
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
       
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 import sys
       
    19 import os
       
    20 from os.path import join
       
    21 from io import StringIO, BytesIO
       
    22 
       
    23 from six import PY2
       
    24 
       
    25 from logilab.common.testlib import TestCase, unittest_main
       
    26 
       
    27 from cubicweb.cwconfig import CubicWebConfiguration
       
    28 from cubicweb.devtools.testlib import CubicWebTC
       
    29 from cubicweb.server.migractions import ServerMigrationHelper
       
    30 
       
    31 CubicWebConfiguration.load_cwctl_plugins() # XXX necessary?
       
    32 
       
    33 
       
    34 class CubicWebCtlTC(TestCase):
       
    35     def setUp(self):
       
    36         self.stream = BytesIO() if PY2 else StringIO()
       
    37         sys.stdout = self.stream
       
    38     def tearDown(self):
       
    39         sys.stdout = sys.__stdout__
       
    40 
       
    41     def test_list(self):
       
    42         from cubicweb.cwctl import ListCommand
       
    43         ListCommand(None).run([])
       
    44 
       
    45 
       
    46 class CubicWebShellTC(CubicWebTC):
       
    47 
       
    48     def test_process_script_args_context(self):
       
    49         repo = self.repo
       
    50         with self.admin_access.repo_cnx() as cnx:
       
    51             mih = ServerMigrationHelper(None, repo=repo, cnx=cnx,
       
    52                                         interactive=False,
       
    53                                         # hack so it don't try to load fs schema
       
    54                                         schema=1)
       
    55             scripts = {'script1.py': list(),
       
    56                        'script2.py': ['-v'],
       
    57                        'script3.py': ['-vd', '-f', 'FILE.TXT'],
       
    58                       }
       
    59             mih.cmd_process_script(join(self.datadir, 'scripts', 'script1.py'),
       
    60                                    funcname=None)
       
    61             for script, args in scripts.items():
       
    62                 scriptname = os.path.join(self.datadir, 'scripts', script)
       
    63                 self.assertTrue(os.path.exists(scriptname))
       
    64                 mih.cmd_process_script(scriptname, None, scriptargs=args)
       
    65 
       
    66 
       
    67 if __name__ == '__main__':
       
    68     unittest_main()