Skip to content

Commit 8422aa1

Browse files
authored
Merge pull request #12 from KiraPC/fix-after-merge
Fix after merge
2 parents dd4bb92 + 524f377 commit 8422aa1

File tree

8 files changed

+22
-94
lines changed

8 files changed

+22
-94
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
name: fastapi-router-controller
1+
name: Run Tests
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
steps:
119
- uses: actions/checkout@v2
1210
- name: Set up Python 3.8
@@ -17,13 +15,6 @@ jobs:
1715
run: |
1816
python -m pip install --upgrade pip
1917
pip install -e .[tests]
20-
# - name: Test with flake8
21-
# run: |
22-
# flake8 tests src
2318
- name: Test with pytest
2419
run: |
2520
pytest tests --cov fastapi_router_controller --cov-report term --cov-report html
26-
# - name: Report coverage
27-
# run: |
28-
# codecov
29-

.github/workflows/on_pr_tests.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/on_tag_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Create Distribution Package
2929
env:
3030
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
31-
run: sed -i -r s"/VERSION = \"(.*)\"/VERSION = \"$FOO\"/"g setup.py && python setup.py sdist
31+
run: sed -i -r s"/VERSION = \"(.*)\"/VERSION = \"$RELEASE_VERSION\"/"g setup.py && python setup.py sdist
3232
- name: Publish package
3333
uses: pypa/gh-action-pypi-publish@release/v1
3434
with:

example/requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

example/sample_app/app.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import unittest
21
from fastapi import FastAPI
32
from fastapi.testclient import TestClient
43
from fastapi_router_controller import ControllersTags
@@ -12,18 +11,3 @@
1211

1312
app.include_router(SampleController.router())
1413
app.include_router(AnotherSampleController.router())
15-
16-
class TestRoutes(unittest.TestCase):
17-
def setUp(self):
18-
self.client = TestClient(app)
19-
20-
def test_get_sample_controller(self):
21-
response = self.client.get("/sample_controller/?id=1234")
22-
self.assertEqual(response.status_code, 200)
23-
24-
def test_post_sample_controller(self):
25-
response = self.client.post("/sample_controller/", json={"id": "test"})
26-
self.assertEqual(response.status_code, 201)
27-
28-
if __name__ == "__main__":
29-
unittest.main()
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import unittest
21
from fastapi import FastAPI
3-
from fastapi.testclient import TestClient
42
from fastapi_router_controller import Controller, ControllersTags
53

64
# just import the main package to load all the controllers in
@@ -14,18 +12,3 @@
1412

1513
for router in Controller.routers():
1614
app.include_router(router)
17-
18-
class TestRoutes(unittest.TestCase):
19-
def setUp(self):
20-
self.client = TestClient(app)
21-
22-
def test_get_sample_extended_controller(self):
23-
response = self.client.get("/sample_extended_controller/?id=1234")
24-
self.assertEqual(response.status_code, 200)
25-
26-
def test_get_sample_extended_controller_parent_api(self):
27-
response = self.client.get("/sample_extended_controller/parent_api")
28-
self.assertEqual(response.status_code, 200)
29-
30-
if __name__ == "__main__":
31-
unittest.main()

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# pylint: disable=line-too-long
21
'''
3-
:author: Pasquale Carmone Carbone
2+
:author: Pasquale Carmine Carbone
43
54
Setup module
65
'''
@@ -12,10 +11,10 @@
1211
with open('requirements.txt', 'r') as fin:
1312
REQS = fin.read().splitlines()
1413

15-
VERSION = "0.2.5"
14+
__VERSION__ = '0.2.5'
1615

1716
setuptools.setup(
18-
version=VERSION,
17+
version=__VERSION__,
1918
name='fastapi-router-controller',
2019
author='Pasquale Carmine Carbone',
2120
author_email='[email protected]',

tests/test_cbv.py renamed to tests/test_controller.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from fastapi.testclient import TestClient
77

88
router = APIRouter()
9-
10-
controller = Controller(router, openapi_tag={"name": "sample_controller"})
9+
controller = Controller(router, openapi_tag={'name': 'sample_controller'})
1110

1211

1312
class SampleObject(BaseModel):
@@ -17,43 +16,43 @@ class SampleObject(BaseModel):
1716
def get_x():
1817
class Foo:
1918
def create(self):
20-
return "XXX"
19+
return 'XXX'
2120

2221
return Foo()
2322

2423

2524
def get_y():
2625
try:
27-
yield "get_y_dep"
26+
yield 'get_y_dep'
2827
finally:
29-
print("get_y done")
28+
print('get_y done')
3029

3130

3231
class Filter(BaseModel):
3332
foo: str
3433

3534

36-
# With the "resource" decorator define the controller Class linked to the Controller router arguments
35+
# With the 'resource' decorator define the controller Class linked to the Controller router arguments
3736
@controller.resource()
3837
class SampleController:
3938
def __init__(self, x=Depends(get_x)):
4039
self.x = x
4140

4241
@controller.route.get(
43-
"/",
44-
tags=["sample_controller"],
45-
summary="return a sample object",
42+
'/',
43+
tags=['sample_controller'],
44+
summary='return a sample object',
4645
response_model=SampleObject,
4746
)
4847
def root(
4948
self,
50-
id: str = Query(..., title="itemId", description="The id of the sample object"),
49+
id: str = Query(..., title='itemId', description='The id of the sample object'),
5150
):
5251
id += self.x.create()
5352
return SampleObject(id=id)
5453

5554
@controller.route.post(
56-
"/hello", response_model=SampleObject,
55+
'/hello', response_model=SampleObject,
5756
)
5857
def hello(self, f: Filter, y=Depends(get_y)):
5958
_id = f.foo
@@ -64,8 +63,8 @@ def hello(self, f: Filter, y=Depends(get_y)):
6463

6564
def create_app():
6665
app = FastAPI(
67-
title="A sample application using fastapi_router_controller",
68-
version="0.1.0",
66+
title='A sample application using fastapi_router_controller',
67+
version='0.1.0',
6968
openapi_tags=ControllersTags,
7069
)
7170

@@ -79,11 +78,11 @@ def setUp(self):
7978
self.client = TestClient(app)
8079

8180
def test_root(self):
82-
response = self.client.get("/?id=12")
81+
response = self.client.get('/?id=12')
8382
self.assertEqual(response.status_code, 200)
84-
self.assertEqual(response.json(), {"id": "12XXX"})
83+
self.assertEqual(response.json(), {'id': '12XXX'})
8584

8685
def test_hello(self):
87-
response = self.client.post("/hello", json={"foo": "WOW"})
86+
response = self.client.post('/hello', json={'foo': 'WOW'})
8887
self.assertEqual(response.status_code, 200)
89-
self.assertEqual(response.json(), {"id": "WOWget_y_depXXX"})
88+
self.assertEqual(response.json(), {'id': 'WOWget_y_depXXX'})

0 commit comments

Comments
 (0)