diff --git a/.gitignore b/.gitignore index 699b160..9245c34 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ pep8.out pylint.out coverage.xml pagureenv-* +worker.log _build/ @@ -45,3 +46,6 @@ Vagrantfile .dnf-cache *.retry .vagrant + +#Ignore generated dockerfile +dev/docker/test_env diff --git a/README.rst b/README.rst index ec86d10..7573dfc 100644 --- a/README.rst +++ b/README.rst @@ -84,19 +84,33 @@ Running the unit-tests To run the unit-tests, there is container available with all the dependencies needed. -Use the following command to build this container :: +Use the following command to run the tests :: - $ docker build -t pagure-test -f dev/docker/test_environment dev/docker + $ ./dev/run-tests-docker.py -Once the container is built, you can run the tests as follow :: +This command will build a fedora based container and execute the test suite. - $ docker run -it --rm -v `pwd`:/code:z --workdir /code pagure-test ./runtests.sh +If you wish to execute the test suite on a centos based container run the following command :: -You can also run the tests using a centos container, to do so :: + $ ./dev/run-tests-docker.py --centos - $ docker build -t pagure-test-centos -f dev/docker/test_environment_centos7 dev/docker - $ docker run -it --rm -v `pwd`:/code:z --workdir /code pagure-test-centos ./runtest.sh +When the test container image has been built you can skip the building step to save time +and run directly the test suite. :: + $ ./dev/run-tests-docker.py --skip-build + $ ./dev/run-tests-docker.py --centos --skip-build + +You can also run a single test case :: + + $ ./dev/run-tests-docker.py tests/test_pagure_flask_ui_priorities.py + +Or a single test :: + + $ ./dev/run-tests-docker.py tests/test_pagure_flask_ui_priorities.py:PagureFlaskPrioritiestests.test_ticket_with_no_priority + +You can also get `run-tests-docker` help :: + + $ ./dev/run-tests-docker.py --help Manually ^^^^^^^^ diff --git a/dev/docker/fedora-infra-tags.repo b/dev/docker/fedora-infra-tags.repo new file mode 100644 index 0000000..4bd9b21 --- /dev/null +++ b/dev/docker/fedora-infra-tags.repo @@ -0,0 +1,6 @@ +[infrastructure-tags] +name=Fedora Infrastructure tag epel7-infra - x86_64 +baseurl=https://kojipkgs.fedoraproject.org/repos-dist/epel7-infra/latest/x86_64/ +enabled=1 +gpgcheck=1 +gpgkey=https://infrastructure.fedoraproject.org/repo/infra/RPM-GPG-KEY-INFRA-TAGS diff --git a/dev/docker/test_env_template b/dev/docker/test_env_template new file mode 100644 index 0000000..e7e6994 --- /dev/null +++ b/dev/docker/test_env_template @@ -0,0 +1,12 @@ +FROM $base_image + +$epel_pkg +$infra_repo + +RUN $pkg_mgr install -y $pkg_list \ + && $pkg_mgr clean all + +ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 +WORKDIR /code +ENTRYPOINT ["/code/runtests.sh"] +CMD [] \ No newline at end of file diff --git a/dev/docker/test_environment b/dev/docker/test_environment deleted file mode 100644 index f019986..0000000 --- a/dev/docker/test_environment +++ /dev/null @@ -1,14 +0,0 @@ -FROM registry.fedoraproject.org/fedora:27 - -RUN dnf install -y python-alembic python-arrow python-binaryornot\ - python-bleach python-blinker python-chardet python-cryptography\ - python-docutils python-enum34 python-flask python2-fedora-flask\ - python-flask-wtf python-flask-multistatic py-bcrypt python-jinja2\ - python-markdown python-munch python-openid-cla python-openid-teams\ - python-psutil python-pygit2 python-pygments python2-pillow\ - python-sqlalchemy python-straight-plugin python-wtforms python-nose\ - python-coverage python-mock python-mock python-eventlet python2-flask-oidc\ - python-nose python-flake8 sudo tmux redis vim git &&\ - pip install celery redis trollius - -ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 diff --git a/dev/docker/test_environment_centos7 b/dev/docker/test_environment_centos7 deleted file mode 100644 index c5d34f2..0000000 --- a/dev/docker/test_environment_centos7 +++ /dev/null @@ -1,16 +0,0 @@ -FROM centos:7 - -RUN yum -y install epel-release pip - -RUN yum install -y python-alembic python-arrow python-binaryornot\ - python-bleach python-blinker python-chardet python-cryptography\ - python-docutils python-enum34 python-flask python2-fedora-flask\ - python-flask-wtf python-flask-multistatic py-bcrypt python-jinja2\ - python-markdown python-munch python-openid-cla python-openid-teams\ - python-psutil python-pygit2 python-pygments python2-pillow\ - python-sqlalchemy python-straight-plugin python-wtforms python-nose\ - python-coverage python-mock python-mock python-eventlet python2-flask-oidc\ - python-nose python-flake8 python-pip sudo tmux redis vim git &&\ - pip install celery redis trollius - -ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 diff --git a/dev/run-tests-docker.py b/dev/run-tests-docker.py new file mode 100755 index 0000000..e7cd738 --- /dev/null +++ b/dev/run-tests-docker.py @@ -0,0 +1,66 @@ +#! /usr/bin/python3 +import argparse +import os +import subprocess as sp +from string import Template + +TEMPLATE = 'dev/docker/test_env_template' + +PKG_LIST = 'python-alembic python-arrow python-binaryornot \ \n'\ + 'python-bleach python-blinker python-chardet python-cryptography \ \n'\ + 'python-docutils python-enum34 python-flask python2-fedora-flask \ \n'\ + 'python-flask-wtf python-flask-multistatic py-bcrypt python-jinja2 \ \n'\ + 'python-markdown python-munch python-openid-cla python-openid-teams \ \n'\ + 'python-psutil python-pygit2 python-pygments python2-pillow \ \n'\ + 'python-sqlalchemy python-straight-plugin python-wtforms python-nose \ \n'\ + 'python-coverage python-mock python-mock python-eventlet python2-flask-oidc \ \n'\ + 'python-flake8 python-celery python-redis python-trollius redis vim git' + + +def setup_parser(): + """ Setup the cli arguments """ + parser = argparse.ArgumentParser(prog='pagure-test') + parser.add_argument('test_case', nargs='?', default='', + help='Run the given test case') + parser.add_argument('--fedora', action='store_true', + help='Run the tests in fedora environment (DEFAULT)') + parser.add_argument('--centos', action='store_true', + help='Run the tests in centos environment') + parser.add_argument('--skip-build', dest='skip_build', action='store_false', + help='Skip building the container image') + + return parser + + +if __name__ == '__main__': + parser = setup_parser() + args = parser.parse_args() + + if args.centos is True: + base_image = 'centos:7' + pkg_mgr = 'yum' + epel_pkg = 'RUN yum -y install epel-release' + infra_repo = 'ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo' + container_name = 'pagure-test-centos' + else: + base_image = 'registry.fedoraproject.org/fedora:27' + pkg_mgr = 'dnf' + container_name = 'pagure-test-fedora' + epel_pkg = '' + infra_repo = '' + + with open(TEMPLATE, 'r') as fp: + t = Template(fp.read()) + with open('dev/docker/test_env', 'w') as fp: + fp.write(t.substitute(base_image=base_image, pkg_list=PKG_LIST, + pkg_mgr=pkg_mgr, epel_pkg=epel_pkg, + infra_repo=infra_repo)) + + if args.skip_build is not False: + print('------ Building Docker Image -----') + sp.run(['docker', 'build', '--rm', '-t', container_name, '-f', + 'dev/docker/test_env', 'dev/docker']) + + print('--------- Running Test --------------') + sp.run(['docker', 'run', '-it', '--rm', '--name', container_name, '-v', + '{}:/code:z'.format(os.getcwd()), container_name, args.test_case])