-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
962b2a0
commit 7323ed8
Showing
10 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
codecov: codecov/[email protected] | ||
|
||
permissions: | ||
id-token: write # This is required for requesting the JWT | ||
contents: read # This is required for actions/checkout | ||
|
||
jobs: | ||
test-api: | ||
docker: | ||
- image: cimg/python:3.10.2 | ||
steps: | ||
- checkout | ||
- run: | ||
name: Install requirements | ||
command: pip install -r api/requirements.txt | ||
- run: | ||
name: Run tests and collect coverage | ||
command: pytest --cov api.calculator | ||
- codecov/upload | ||
|
||
workflows: | ||
version: 2.1 | ||
build-test: | ||
jobs: | ||
- test-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: API workflow | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
id-token: write # This is required for requesting the JWT | ||
contents: read # This is required for actions/checkout | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
name: Test python API | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' | ||
- name: Install requirements | ||
run: pip install -r api/requirements.txt | ||
- name: Run tests and collect coverage | ||
run: pytest --cov=api.calculator --cov-report=xml | ||
- name: Upload coverage reports to Codecov with GitHub Action | ||
uses: codecov/[email protected] | ||
with: | ||
use_oidc: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.py[oc] | ||
__pycache__ | ||
.coverage | ||
.pytest_cache/ | ||
coverage.xml | ||
node_modules/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# oidc-test | ||
# oidc-test | ||
used pyenv virtualenv 3.12.2 temp |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from flask import ( | ||
Flask, | ||
request, | ||
) | ||
|
||
from calculator.calculator import Calculator | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/api/add', methods=['POST']) | ||
def add(): | ||
return operation('add', 2) | ||
|
||
@app.route('/api/subtract', methods=['POST']) | ||
def subtract(): | ||
return operation('subtract', 2) | ||
|
||
@app.route('/api/multiply', methods=['POST']) | ||
def multiply(): | ||
return operation('multiply', 2) | ||
|
||
@app.route('/api/divide', methods=['POST']) | ||
def divide(): | ||
return operation('divide', 2) | ||
|
||
def operation(method, num_factors): | ||
factors = [] | ||
if num_factors == 2: | ||
factors.append(float(request.json.get('x'))) | ||
factors.append(float(request.json.get('y'))) | ||
|
||
return str(getattr(Calculator, method)(*factors)) | ||
|
||
|
||
app.run(host='0.0.0.0', port=8080) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Calculator: | ||
def add(x, y): | ||
return x + y | ||
|
||
def subtract(x, y): | ||
return x - y | ||
|
||
def multiply(x, y): | ||
return x * y | ||
|
||
def divide(x, y): | ||
if y == 0: | ||
return 'Cannot divide by 0' | ||
return x * 1.0 / y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from .calculator import Calculator | ||
|
||
|
||
def test_add(): | ||
assert Calculator.add(1, 2) == 3.0 | ||
assert Calculator.add(1.0, 2.0) == 3.0 | ||
assert Calculator.add(0, 2.0) == 2.0 | ||
assert Calculator.add(2.0, 0) == 2.0 | ||
assert Calculator.add(-4, 2.0) == -2.0 | ||
|
||
def test_subtract(): | ||
assert Calculator.subtract(1, 2) == -1.0 | ||
assert Calculator.subtract(2, 1) == 1.0 | ||
assert Calculator.subtract(1.0, 2.0) == -1.0 | ||
assert Calculator.subtract(0, 2.0) == -2.0 | ||
assert Calculator.subtract(2.0, 0.0) == 2.0 | ||
assert Calculator.subtract(-4, 2.0) == -6.0 | ||
|
||
def test_multiply(): | ||
assert Calculator.multiply(1, 2) == 2.0 | ||
assert Calculator.multiply(1.0, 2.0) == 2.0 | ||
assert Calculator.multiply(0, 2.0) == 0.0 | ||
assert Calculator.multiply(2.0, 0.0) == 0.0 | ||
assert Calculator.multiply(-4, 2.0) == -8.0 | ||
|
||
def test_divide(): | ||
assert Calculator.divide(1, 2) == 0.5 | ||
assert Calculator.divide(1.0, 2.0) == 0.5 | ||
assert Calculator.divide(0, 2.0) == 0 | ||
assert Calculator.divide(-4, 2.0) == -2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
blinker==1.8.2 | ||
click==8.1.7 | ||
coverage==7.6.1 | ||
Flask==3.0.3 | ||
iniconfig==2.0.0 | ||
itsdangerous==2.2.0 | ||
Jinja2==3.1.4 | ||
MarkupSafe==2.1.5 | ||
packaging==24.1 | ||
pluggy==1.5.0 | ||
pytest==8.3.3 | ||
pytest-cov==5.0.0 | ||
Werkzeug==3.0.4 |