test/unittest_preprocessors.py
author Julien Cristau <julien.cristau@logilab.fr>
Fri, 20 Jun 2014 16:13:09 +0200
changeset 1539 35b873cea565
parent 1522 70131ccb08ec
child 1563 000605df69cf
permissions -rw-r--r--
[pkg] release

# -*- coding: utf-8 -*-
import json

from logilab.common.testlib import unittest_main
import cubicweb.devtools

from cubes.apycot.testutils import ApycotBaseTC
from apycotlib import atest, writer, REGISTRY
import preprocessors.apycot.distutils
from cubicweb.utils import json_dumps

class FakeCnxh(object):
    def __init__(self, msgcfg, msgdep):
        self.msgcfg = msgcfg
        self.msgdep = msgdep
        self.instance_url = 'http://gna'
    def http_post(self, *args, **kwargs):
        if 'vid' in kwargs and kwargs['vid'] == 'apycot.get_configuration':
            return self.msgcfg
        elif 'vid' in kwargs and kwargs['vid'] == 'apycot.get_dependencies':
            return self.msgdep
        else:
            return []

    def http_get(*args, **kwargs):
        return [{'deps': 'a'}]

REGISTRY['preprocessor']['python_setup'] = preprocessors.apycot.distutils.DistutilsProcessor

class FakeWriter(object):
    def debug(self, msg, *args, **kwargs):
        pass
    def info(self, msg, *args, **kwargs):
        pass
    def fatal(self, msg, *args, **kwargs):
        pass

    def __init__(self, msgcfg, msgdep):
        self.cnxh = FakeCnxh(msgcfg, msgdep)

class FileCheckerTest(ApycotBaseTC):
    def start_lgc_tests(self):
        plan = self.lgc.start(self.lgce)
        self.lgc._cw.cnx.commit()
        return plan

    def test_exec_status_change(self):
        req = self.request()
        tc = req.create_entity('TestConfig',
                                     name=u'TC',
                                     label=u'full python tests',
                                     start_mode=u'manual',
                                     check_config=u"""pylint_threshold=7
pycoverage_threshold=70
install=python_setup""")
        pe = req.create_entity('ProjectEnvironment',
                                          name=u'gna',
                                          reverse_use_environment=tc.eid,
                                          local_repository=self.vcsrepo)

        self.vcsrepo2 = req.create_entity('Repository', type=u'mercurial',
                # use path to avoid clone attempt when using url
                path=unicode(self.datapath('project1')), source_url=u'http://gna.com',
                reverse_local_repository=self.lgce)

        pe_dep1 = req.create_entity('ProjectEnvironment',
                                          name=u'regna',
                                          reverse_use_environment=tc.eid,
                                          local_repository=self.vcsrepo2)


        self.commit()
        self.vreg['views']
        req_env = self.request(environment=pe.eid)
        req_env_dep = self.request(environment=pe_dep1.eid)
        tconf = json.loads(req_env.view('apycot.get_configuration', rset=tc.as_rset()))
        penv = json.loads(req_env.view('ejsonexport', rset=pe.as_rset()))[0]
        penv_dep = json.loads(req_env.view('ejsonexport', rset=pe.as_rset()))
        penv['title'] = 'gna'
        self.login('narval', password='narval0')
        plan = self.start_lgc_tests()
        plan = json.loads(json_dumps(req.entity_from_eid(plan.eid)))
        test = atest.Test(plan, FakeWriter(tconf, penv_dep))
        test.call_preprocessor('install', penv)



if __name__ == '__main__':
    unittest_main()