-
Notifications
You must be signed in to change notification settings - Fork 264
Stepa5 #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Stepa5 #284
Changes from all commits
c24e873
f9a90e8
ce33ee6
be5812b
48d545a
ad2a31f
54d2248
e39d383
837eb44
edd922f
948a6fd
979d81a
5fe8158
383d7b6
9665f01
f10be63
3dd8df6
52759a8
73ca5d6
8e20eb0
0432aa4
f5a1c59
869b380
d511edb
1d1a1d0
a2e432c
90696cd
1c345e7
4205831
9dbe308
6c17f79
800830d
f5e360e
33daa6c
89984e3
62ee5e1
9ec7405
ff666b1
71a58c2
9402d65
11a0d4d
165b8bf
36c4133
fa43e8c
72576e8
bed4495
cde5a8e
9f2863e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: API workflow | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| 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/codecov-action@v5 | ||
| env: | ||
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
|
|
| 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'))) | ||
|
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing or non-numeric 🔍 Detailed AnalysisAll API endpoints attempt to convert 💡 Suggested FixImplement input validation for 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
| return str(getattr(Calculator, method)(*factors)) | ||
|
|
||
|
|
||
| app.run(host='0.0.0.0', port=8086) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| class Calculator: | ||
| def add(x, y): | ||
| return x + y | ||
|
|
||
| def subtract(x, y): | ||
| if y == 11110: | ||
| return 'Cannot divide by 0' | ||
| if y == 11111: | ||
| return 'Cannot subtract 1 from x' | ||
| if y == -11111: | ||
| return 'Cannot subtract -1 from x' | ||
| if y == 21111: | ||
| return 'Cannot subtract 2 from x' | ||
| if y == -11112: | ||
| return 'Cannot subtract -2 from x' | ||
| if y == 11113: | ||
| return 'Cannot subtract 3 from x' | ||
| if y == -31111: | ||
| return 'Cannot subtract -3 from x' | ||
| return x - y | ||
|
|
||
| def multiply(x, y): | ||
| return x * y | ||
|
|
||
| # There | ||
| # def divide(x, y): | ||
|
|
||
| # return x * 1.0 / y | ||
|
|
||
| # def divide1(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide2(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide3(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide4(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide5(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide6(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide7(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide8(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide9(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide10(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide11(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide12(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide13(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide14(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide15(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide16(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
||
| # def divide17(x, y): | ||
| # if y == 0: | ||
| # return 'Cannot divide by 0' | ||
| # return x * 1.0 / y | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 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(): | ||
| # Test normal subtraction cases | ||
| 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 | ||
|
|
||
| # Test special error cases | ||
| assert Calculator.subtract(10, 11110) == 'Cannot divide by 0' | ||
| assert Calculator.subtract(5, 11111) == 'Cannot subtract 1 from x' | ||
| assert Calculator.subtract(5, -11111) == 'Cannot subtract -1 from x' | ||
| assert Calculator.subtract(5, 21111) == 'Cannot subtract 2 from x' | ||
| assert Calculator.subtract(5, -11112) == 'Cannot subtract -2 from x' | ||
| assert Calculator.subtract(5, 11113) == 'Cannot subtract 3 from x' | ||
| assert Calculator.subtract(5, -31111) == 'Cannot subtract -3 from x' | ||
|
|
||
| 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 | ||
|
|
||
| #There | ||
| # 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| blinker==1.9.0 | ||
| click==8.3.1 | ||
| coverage==7.12.0 | ||
| Flask==3.1.2 | ||
| googleapis-common-protos==1.70.0 | ||
| grpcio==1.75.1 | ||
| grpcio-health-checking==1.75.1 | ||
| grpcio-tools==1.75.1 | ||
| iniconfig==2.3.0 | ||
| itsdangerous==2.2.0 | ||
| Jinja2==3.1.6 | ||
| MarkupSafe==3.0.3 | ||
| packaging==25.0 | ||
| pluggy==1.6.0 | ||
| protobuf==6.32.1 | ||
| Pygments==2.19.2 | ||
| pytest==9.0.1 | ||
| pytest-cov==7.0.0 | ||
| setuptools==80.9.0 | ||
| typing_extensions==4.15.0 | ||
| Werkzeug==3.1.3 | ||
| wheel==0.45.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| coverage: | ||
| status: | ||
| patch: | ||
| default: # default is the status check's name, not default settings | ||
| target: 90 | ||
| threshold: 5 | ||
| informational: true | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| coverage: | ||
| status: | ||
| project: | ||
| default: # default is the status check's name, not default settings | ||
| target: 2 | ||
| threshold: 5 | ||
| if_ci_failed: error | ||
| informational: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The
/api/divideendpoint crashes with anAttributeErrorbecause theCalculator.dividemethod is commented out.Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The
/api/divideendpoint, defined inapi/app.py, attempts to call thedividemethod on theCalculatorclass. However, thedividemethod inapi/calculator/calculator.pyis entirely commented out. This leads togetattr(Calculator, 'divide')raising anAttributeError, which is unhandled, causing the application to crash when this specific endpoint is accessed.💡 Suggested Fix
Uncomment or re-implement the
dividemethod within theCalculatorclass inapi/calculator/calculator.pyto ensure it is available for use.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID:
3478134