diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/build_test.yml similarity index 67% rename from .github/workflows/python-package-conda.yml rename to .github/workflows/build_test.yml index 0b00100..071ed23 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/build_test.yml @@ -1,10 +1,10 @@ -name: Python Package using Conda +name: Python Package build test on: push: - branches: ["backend"] + branches: ["backend*"] pull_request: - branches: ["backend"] + branches: ["backend*"] jobs: build-linux: @@ -18,22 +18,16 @@ jobs: uses: actions/setup-python@v3 with: python-version: '3.10.11' - - name: Add conda to system path - run: | - # $CONDA is an environment variable pointing to the root of the miniconda directory - echo $CONDA/bin >> $GITHUB_PATH - name: Install dependencies run: | - # conda env update --file .yml --name base pip install -r requirements.txt + pip install -e backend - name: Lint with flake8 run: | - conda install flake8 # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - conda install pytest pytest \ No newline at end of file diff --git a/src/__init__.py b/backend/magician/app/__init__.py similarity index 100% rename from src/__init__.py rename to backend/magician/app/__init__.py diff --git a/backend/magician/app/flask_app.py b/backend/magician/app/flask_app.py new file mode 100644 index 0000000..cdb6a45 --- /dev/null +++ b/backend/magician/app/flask_app.py @@ -0,0 +1,10 @@ +from flask import Flask + +from magician.service.print_hello import print_hello + +app = Flask(__name__) + + +@app.route('/hello', methods=['GET']) +def api_hello(): + return {"msg": print_hello()}, 200 diff --git a/src/service/__init__.py b/backend/magician/service/__init__.py similarity index 100% rename from src/service/__init__.py rename to backend/magician/service/__init__.py diff --git a/backend/magician/service/print_hello.py b/backend/magician/service/print_hello.py new file mode 100644 index 0000000..162207b --- /dev/null +++ b/backend/magician/service/print_hello.py @@ -0,0 +1,2 @@ +def print_hello(): + return 'hello world' diff --git a/backend/setup.py b/backend/setup.py new file mode 100644 index 0000000..3688f34 --- /dev/null +++ b/backend/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup + +setup( + name="magician", + version="0.1", + packages=["magician"], +) diff --git a/requirements.txt b/requirements.txt index 7710096..98886fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,7 @@ +#app flask == 2.3.2 -pytest == 7.3.1 \ No newline at end of file + +#test +flake8 == 6.0.0 +pytest == 7.3.1 +requests == 2.31.0 \ No newline at end of file diff --git a/src/service/print_hello.py b/src/service/print_hello.py deleted file mode 100644 index b303cf6..0000000 --- a/src/service/print_hello.py +++ /dev/null @@ -1,2 +0,0 @@ -def print_hello(): - return 'hello world' \ No newline at end of file diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_hello.py b/test/test_hello.py deleted file mode 100644 index 7f94f65..0000000 --- a/test/test_hello.py +++ /dev/null @@ -1,17 +0,0 @@ -import pytest -from src.service.print_hello import print_hello - - - -def test_mytest(): - assert 'hello world' == print_hello() - # assert 1==2123 - - -# def f(): -# raise SystemExit(1) - - -# def test_mytest(): -# with pytest.raises(SystemExit): -# f() \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..3197026 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,12 @@ +import pytest +from magician.app.flask_app import app as flask_app + + +@pytest.fixture +def app(): + return flask_app + + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/e2e/test_api.py b/tests/e2e/test_api.py new file mode 100644 index 0000000..eb09782 --- /dev/null +++ b/tests/e2e/test_api.py @@ -0,0 +1,8 @@ +import json + + +def test_hello(app, client): + res = client.get('/hello') + assert res.status_code == 200 + expected = {'msg': 'hello world'} + assert expected == json.loads(res.get_data(as_text=True)) diff --git a/tests/unit/test_hello.py b/tests/unit/test_hello.py new file mode 100644 index 0000000..f9b87cb --- /dev/null +++ b/tests/unit/test_hello.py @@ -0,0 +1,6 @@ +from magician.service.print_hello import print_hello + + +def test_mytest(): + assert 'hello world' == print_hello() + # assert 1==2123