From 54b18c3da517a73fec419ad433a753671bf322ea Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:17:28 +0000 Subject: [PATCH 1/5] Update dependency MarkupSafe to v2.1.5 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4adec7ec..c6163975 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,5 @@ click==8.1.3 Flask==2.2.5 itsdangerous==2.1.2 Jinja2==3.1.4 -MarkupSafe==2.1.2 +MarkupSafe==2.1.5 Werkzeug==3.0.3 \ No newline at end of file From 29c298c28ac9e9e2240e397d466ce18886ef1e56 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:17:32 +0000 Subject: [PATCH 2/5] Update dependency click to v8.1.7 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4adec7ec..5b95bbf4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -click==8.1.3 +click==8.1.7 Flask==2.2.5 itsdangerous==2.1.2 Jinja2==3.1.4 From f8db0e211b54afb58345cb67710711ed39913299 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 14:06:14 +0000 Subject: [PATCH 3/5] Update dependency itsdangerous to v2.2.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4adec7ec..3149fb3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ click==8.1.3 Flask==2.2.5 -itsdangerous==2.1.2 +itsdangerous==2.2.0 Jinja2==3.1.4 MarkupSafe==2.1.2 Werkzeug==3.0.3 \ No newline at end of file From 5c52bae153915ab56ff94c6dcbf06ea5bb57cf91 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 15:56:34 +0000 Subject: [PATCH 4/5] Update dependency Flask to v3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4adec7ec..e7a546c9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ click==8.1.3 -Flask==2.2.5 +Flask==3.0.3 itsdangerous==2.1.2 Jinja2==3.1.4 MarkupSafe==2.1.2 From 96cfa88469ca838387a7c617e7870e970ae14503 Mon Sep 17 00:00:00 2001 From: S-mishina Date: Sat, 8 Jun 2024 01:42:46 +0900 Subject: [PATCH 5/5] Add workflow Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix workflow directly Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina Add deploy workflow Signed-off-by: S-mishina fix deploy workflow Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina fix Signed-off-by: S-mishina --- .github/workflows/deploy.yaml | 76 ++++++++++++++++++++++++++ .gitignore | 2 + project/main.py | 3 + test/{unit_test.py => app_unittest.py} | 10 +++- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy.yaml create mode 100644 .gitignore rename test/{unit_test.py => app_unittest.py} (90%) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 00000000..6b239ceb --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,76 @@ +name: Deploy + +on: + pull_request: + branches: + - main + types: [opened, synchronize, reopened] + +jobs: + test_ci: + runs-on: ubuntu-20.04 + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: 3.10.0 + architecture: "x64" + - uses: actions/cache@v4.0.2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install pip requirements + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Python unit tests + run: | + python -m unittest discover -s test -p "*.py" + + deploy: + runs-on: ubuntu-20.04 + needs: test_ci + if: github.event.pull_request.merged == true + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: 3.10.0 + architecture: "x64" + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + with: + driver-opts: | + image=moby/buildkit:v0.10.6 + - name: Install pip requirements + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + logout: false + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64 + push: true + tags: | + ghcr.io/s-mishina/flexiblemockserver:${{ github.sha }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6c6447bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*/__pycache__ +*/__init__.py diff --git a/project/main.py b/project/main.py index 616940f4..79976825 100644 --- a/project/main.py +++ b/project/main.py @@ -66,6 +66,9 @@ def only_status_code_query(status_code, sleep_time=0): else: return make_response(jsonify(err="Not status code"), 400) +@app.errorhandler(404) +def page_not_found(e): + return make_response(jsonify(err="Nonexistent Path"), 404) if __name__ == '__main__': app.run(host=host, port=port) diff --git a/test/unit_test.py b/test/app_unittest.py similarity index 90% rename from test/unit_test.py rename to test/app_unittest.py index 39513bc3..2aa5d500 100644 --- a/test/unit_test.py +++ b/test/app_unittest.py @@ -1,5 +1,7 @@ import unittest -from main import app + +from project.main import app + class TestApp(unittest.TestCase): def setUp(self): @@ -47,5 +49,7 @@ def test_only_status_code_query_route(self): self.assertEqual(response.json['status_code'], 500) self.assertEqual(response.json['output'], "{'param1': 'value1', 'param2': 'value2'}") -if __name__ == '__main__': - unittest.main() \ No newline at end of file + def test_new_route(self): + response = self.app.get('/new') + self.assertEqual(response.status_code, 404) + self.assertEqual(response.json['err'], 'Nonexistent Path')