test/test_functional.py
author David Douard <david.douard@logilab.fr>
Sun, 09 Nov 2014 20:07:45 +0100
changeset 1773 35a2edaa84e5
parent 1770 43ee4499b0a2
child 1622 84913fb4d2e7
permissions -rw-r--r--
[migration] add a migration script for 4.0.0

import os
import os.path as osp
from shutil import rmtree

from logilab.common.shellutils import unzip
from logilab.common.testlib import unittest_main

import cubicweb.devtools
import cubes.apycot.testutils as utils
from cubes.apycot.recipes import create_recipes
class ApycotNoTestTC(utils.ApycotBaseTC):
    _repo_path = (u'project',)

    def test_quick_recipe_no_data(self):
        with self.admin_access.client_cnx() as cnx:
            tc = cnx.find('TestConfig', name='tc_project').one()
            pe = cnx.find('ProjectEnvironment', name='pe_project').one()
            te = tc.start(pe).eid
            cnx.commit()
        self.run_plan(te)
        with self.admin_access.client_cnx() as cnx:
            te = cnx.entity_from_eid(te)
            expected = {'pyunit': 'nodata'}
            for checker in te.checkers:
                self.assertEqual(expected[checker.name], checker.status, checker.log_file[0].read())

    def test_full_recipe(self):
        with self.admin_access.client_cnx() as cnx:
            pyp = cnx.find('TestConfig', name='PYTHONPACKAGE').one()
            tc = cnx.find('TestConfig', name='tc_project').one()
            pe = cnx.find('ProjectEnvironment', name='pe_project').one()

            # ensure recipes content
            create_recipes(cnx, update=True)
            recipe = cnx.find('Recipe', name="apycot.python.full").one()
            self.assertTrue(cnx.find('Recipe', name="apycot.checkout.mercurial"))
            self.assertTrue(cnx.find('Recipe', name="apycot.setup.distutils"))
            tc2 = self.add_test_config(cnx, u'full config', env=pe, group=pyp,
                                       use_recipe=recipe,
                                       check_config=u'python_lint_treshold=8\npouet=5\nkeep_test_dir=1')
            te = tc2.start(pe).eid
            cnx.commit()
        self.run_plan(te)
        with self.admin_access.client_cnx() as cnx:
            te = cnx.entity_from_eid(te)
            expected = {'pyunit': 'nodata',
                        'pylint': 'error',}
            for checker in te.checkers:
                self.assertEqual(expected[checker.name], checker.status,
                                 '%s != %s\nlog=%s\nexecution_log=%s\nTE log=%s' % (
                        expected[checker.name], checker.status,
                        checker.log_file[0].read(), te.execution_log[0].read(),
                        te.log_file[0].read()))
            # as we added keep_test_dir=1 in the options, we expect to
            # have kept the execution test directory, and that path is
            # reported as a CheckResultInfo
            rset = cnx.execute('Any V WHERE CR for_check %(eid)s, CR label %(lbl)s, CR value V',
                               {'eid': te.eid, 'lbl': 'tmpdir'})
            self.assertEqual(1, len(rset))
            tmpdir = str(rset[0][0])
            self.assertTrue(osp.exists(tmpdir))
            self.assertTrue(osp.exists(osp.join(tmpdir, 'src', str(pe.local_repository[0].eid))))
            self.assertFalse(te.execution_archive)


if __name__ == '__main__':
    unittest_main()