From 1dc93c5f0dbd30b6a4d0e0e8bb8573911407b539 Mon Sep 17 00:00:00 2001 From: wangobango Date: Tue, 30 Nov 2021 16:13:45 +0100 Subject: [PATCH] added tests test test add jenkinsfile test test change to jenkinsfile fix to jenkinsfile asd asd asd asd asd --- .gitignore | 6 +++++- Dockerfile | 4 ++-- Jenkinsfile | 22 ++++++++++++++++++++++ ayct-backend/__init__.py | 0 app.py => ayct-backend/app.py | 3 +++ ayct-backend/tests/test_ayct_backend.py | 20 ++++++++++++++++++++ pyproject.toml | 7 +++++++ requirements.txt | 3 ++- setup.cfg | 24 ++++++++++++++++++++++++ setup_core.sh | 1 + 10 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 Jenkinsfile create mode 100644 ayct-backend/__init__.py rename app.py => ayct-backend/app.py (91%) create mode 100644 ayct-backend/tests/test_ayct_backend.py create mode 100644 pyproject.toml create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index c3b4f44..5680274 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ __pycache__/* -venv/* \ No newline at end of file +venv/* +*.egg-info +__pycache__ +.pytest_cache +something/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4be1ccc..d682e7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ FROM python:3 ENV DOCKER_APP True +USER root WORKDIR /app -RUN git clone https://git.wmi.amu.edu.pl/s415366/pbr-ayct-core COPY . . RUN chmod u+x setup_core.sh RUN bash setup_core.sh RUN pip3 install -r requirements.txt EXPOSE 5000/udp EXPOSE 5000/tcp -CMD ["python3", "app.py"] \ No newline at end of file +CMD ["python3", "ayct-backend/app.py"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..ede623e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,22 @@ +pipeline { + agent { + docker { + image 'python:latest' + args '-u root --privileged' + } + } + stages { + stage('build') { + steps { + sh 'bash setup_core.sh' + sh 'pip install -r requirements.txt' + sh 'pip install --user -e .' + } + } + stage('test') { + steps { + sh 'pytest' + } + } + } +} diff --git a/ayct-backend/__init__.py b/ayct-backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/ayct-backend/app.py similarity index 91% rename from app.py rename to ayct-backend/app.py index c622713..2700cf0 100644 --- a/app.py +++ b/ayct-backend/app.py @@ -12,6 +12,9 @@ class Hello(Resource): api.add_resource(Hello, "/hello") +def create_app(): + return app + if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host = '0.0.0.0', port = port) diff --git a/ayct-backend/tests/test_ayct_backend.py b/ayct-backend/tests/test_ayct_backend.py new file mode 100644 index 0000000..96528a1 --- /dev/null +++ b/ayct-backend/tests/test_ayct_backend.py @@ -0,0 +1,20 @@ +import os +import tempfile + +import pytest + +from app import create_app + +@pytest.fixture +def client(): + app = create_app() + app.run(host = '0.0.0.0', port = 5000) + + with app.test_client() as client: + with app.app_context(): + pass + yield client + +def test_first_endpoint(client): + rv = client.get("/hello") + assert b'All You Can Tweet' in rv.data \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..15f7d66 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "flask" +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2a47d39..85e0fb5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Flask==2.0.2 -Flask-RESTful==0.3.9 \ No newline at end of file +flask_restful==0.3.9 +pytest==6.2.5 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..d157efd --- /dev/null +++ b/setup.cfg @@ -0,0 +1,24 @@ +[metadata] +name = pbrAyctBackend +version = 0.0.1 +author = Ɓukasz Ramon Piotrek +author_email = ramon.dyzman@gmail.com +description = A small example package +long_description = file: readme.md +long_description_content_type = text/markdown +url = https://git.wmi.amu.edu.pl/s434708/pbr-ayct-backend +project_urls = + Bug Tracker = https://github.com/pypa/sampleproject/issues +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + Operating System :: OS Independent + +[options] +package_dir = + = ayct-backend +packages = find: +python_requires = >=3.6 + +[options.packages.find] +where = src \ No newline at end of file diff --git a/setup_core.sh b/setup_core.sh index e3bb083..4512366 100644 --- a/setup_core.sh +++ b/setup_core.sh @@ -1,3 +1,4 @@ +git clone https://git.wmi.amu.edu.pl/s415366/pbr-ayct-core cd pbr-ayct-core pip3 install setuptools python3 -m pip install --upgrade build