Skip to content
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

Fast api conversion course and event #555

Merged
merged 28 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
574c5ca
Create test_user_course.py
yliao-dev Feb 11, 2022
f72edf2
Update test_user_course.py
yliao-dev Feb 11, 2022
99cc1dd
Merge branch 'FastAPI' of https://github.com/YACS-RCOS/yacs.n into Fa…
yliao-dev Feb 11, 2022
d4d31ea
Update failure case and minor change on success post
yliao-dev Feb 11, 2022
9258db3
Merge branch 'FastAPI' of https://github.com/YACS-RCOS/yacs.n into Fa…
yliao-dev Feb 12, 2022
33df375
Minor changes
yliao-dev Feb 14, 2022
ca5e385
Merge branch 'FastAPI' of https://github.com/YACS-RCOS/yacs.n into Fa…
yliao-dev Feb 15, 2022
4fc5f9c
Debugging json on line 26
yliao-dev Feb 15, 2022
e6412e4
Passed post success and failure for user/course
yliao-dev Feb 16, 2022
65dff44
Clear comments for pr requirements
yliao-dev Feb 16, 2022
ac63310
Merge branch 'FastAPI' of https://github.com/YACS-RCOS/yacs.n into Fa…
yliao-dev Feb 18, 2022
18a6fe5
Added not authorized test and followed pr requirements
yliao-dev Feb 18, 2022
2346bf5
Merge branch 'FastAPI' of https://github.com/YACS-RCOS/yacs.n into Fa…
yliao-dev Feb 28, 2022
50ac8b4
Merge branch 'FastAPIConversion' of https://github.com/YACS-RCOS/yacs…
yliao-dev Feb 28, 2022
341b8cd
Update endpoints step 1
yliao-dev Feb 28, 2022
4bfd579
Update in pydantic model
yliao-dev Feb 28, 2022
af8eee5
Status to Status_code
yliao-dev Feb 28, 2022
f07f0f1
Change api naming conversion to FastAPI
yliao-dev Mar 1, 2022
335e4c8
Debugging pytest
yliao-dev Mar 1, 2022
8120af2
Merge branch 'FastAPIConversion' of https://github.com/YACS-RCOS/yacs…
yliao-dev Mar 4, 2022
19a3946
Fixed Post success and post failure pytest method
yliao-dev Mar 4, 2022
b9f5572
Change api_model datatype to str
yliao-dev Mar 4, 2022
c7dd3e5
newest update
yliao-dev Mar 24, 2022
a959e5f
Merge branch 'FastAPIConversion' of https://github.com/YACS-RCOS/yacs…
yliao-dev Mar 24, 2022
2d7620e
Fixed the 422 Issue by removing user_id parameter
yliao-dev Mar 25, 2022
13b2fd2
Merge branch 'FastAPIConversion' of https://github.com/YACS-RCOS/yacs…
yliao-dev Mar 25, 2022
b52ab0b
Undo some changes
yliao-dev Mar 25, 2022
3ecd373
Merge branch 'FastAPIConversion' into FastAPIConversion-course-and-event
lhain08 Mar 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/api/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ class SessionPydantic(BaseModel):
class SessionDeletePydantic(BaseModel):
sessionID: str

class UserCoursePydantic(BaseModel):
name: str
semester: str
cid: str

class SubsemesterPydantic(BaseModel):
semester: Optional[str] = None
24 changes: 11 additions & 13 deletions src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,17 @@ def log_out(request: Request, session: SessionDeletePydantic):
return response


# @app.route('/api/event', methods=['POST'])
# def add_user_event():
# return event_controller.add_event(json.loads(request.data))
#
# @app.route('/api/user/course', methods=['POST'])
# def add_student_course():
# info = request.get_json()
#
# if 'user' not in session:
# return Response("Not authorized", status=403)
#
# resp, error = course_select.add_selection(info['name'], info['semester'], session['user']['user_id'], info['cid'])
# return Response(status=200) if not error else Response(error, status=500)
@app.post('/api/event')
def add_user_event(request: Request, credentials: SessionPydantic):
return Response(status_code=501)
#return event_controller.add_event(json.loads(request.data))

@app.post('/api/user/course')
async def add_student_course(request: Request, credentials: UserCoursePydantic):
if 'user' not in request.session:
return Response("Not authorized", status_code=403)
resp, error = course_select.add_selection(credentials.name, credentials.semester, credentials.cid)
return Response(status_code=200) if not error else Response(error, status_code=500)
#
#
# @app.route('/api/user/course', methods=['DELETE'])
Expand Down
25 changes: 18 additions & 7 deletions src/api/tests/test_user_course.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .util import Client
from fastapi.testclient import TestClient
import pytest

TEST_USER = { 'email': 'test@email.com',
'password': '123456' }
Expand All @@ -9,10 +10,12 @@
}

'''
Test this api endpoint/file only with the following command line:
pytest -s tests/test_user_course.py
Test this api endpoint/file locally with the following command line:
src/api/tests/test.sh
'''
def test_user_course_post_success(post_user, client: Client):
@pytest.mark.testclient
@pytest.mark.incompletedependency
def test_user_course_post_success(post_user, client: TestClient):
'''
Test user course post by comparing it to user get course
'''
Expand All @@ -28,7 +31,9 @@ def test_user_course_post_success(post_user, client: Client):
d = client.delete("/api/session", json={"sessionID": sess.json()['content']['sessionID']})
assert d.status_code == 200

def test_user_course_post_failure(client: Client):
@pytest.mark.testclient
@pytest.mark.incompletedependency
def test_user_course_post_failure(post_user, client: TestClient):
'''
Test user course post with invalid parameter
'''
Expand All @@ -40,9 +45,15 @@ def test_user_course_post_failure(client: Client):
d = client.delete('/api/session', json={'sessionID': sessID})
assert d.status_code == 200

def test_course_post_not_authorized(client: Client):
@pytest.mark.testclient
#@pytest.mark.incompletedependency
def test_course_post_not_authorized(client: TestClient):
'''
Test user course post without user session/login
'''
r = client.post("/api/user/course", json=TEST_USER_COURSE)
assert r.status_code == 403
print(r.text)
assert r.status_code == 403 #422?
# data = r.json()
# assert data['content']['sessionID'] is not None