Skip to content

Commit

Permalink
Fast api course (#552)
Browse files Browse the repository at this point in the history
* user_course_get_success

* create a user course delete success function

* update the delete failure function and add code to log out the session in the success cases

* add failure cases for get and delete

* add failure cases for get and delete

* Update test_user_course_delete.py

Change ways of writing to examine whether the course is successfully delete or not

* delete trivial spaces and all the prints

Co-authored-by: Xies3 <[email protected]>
  • Loading branch information
lhain08 and Xies3 authored Mar 18, 2022
1 parent dba5d56 commit 4435ccf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/api/tests/test_user_course_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from .util import Client

TEST_USER = { 'email': '[email protected]',
'password': '123456' }

TEST_COURSE = {'name': 'ARCH-4770',
'cid': '-1',
'semester': 'SUMMER2020'}

TEST_COURSE_2 = {'name': 'ARCH-4770',
'cid': None,
'semester': 'SUMMER2020'}


def test_user_course_delete_success(post_user, client: Client):
r = client.post("/api/session", json=TEST_USER)
assert r.status_code == 200
course = client.post("/api/user/course", json=TEST_COURSE)
assert course.status_code == 200
d = client.get("/api/user/course", json=TEST_COURSE)
data = d.json()[1]
assert data['course_name'] == TEST_COURSE['name']
assert data['crn'] == TEST_COURSE['cid']
assert data['semester'] == TEST_COURSE['semester']
x = client.delete("/api/user/course", json = TEST_COURSE)
assert x.status_code == 200
d = client.get("/api/user/course", json=TEST_COURSE)
data = d.json()
for x in data:
assert x['course_name'] is not TEST_COURSE['name']
assert x['crn'] is not TEST_COURSE['cid']
client.delete("/api/session", json = {"sessionID": r.json()["content"]["sessionID"]})

def test_user_course_delete_failure(client: Client):
r = client.post("/api/user/course", json=TEST_USER)
assert r.status_code == 403
26 changes: 26 additions & 0 deletions src/api/tests/test_user_course_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .util import Client

TEST_USER = { 'email': '[email protected]',
'password': '123456' }

TEST_COURSE = {'name': 'ARCH-4770',
'cid': '-1',
'semester': 'SUMMER2020'}


def test_user_course_get_success(post_user, client: Client):
r = client.post("/api/session", json=TEST_USER)
assert r.status_code == 200
course = client.post("/api/user/course", json=TEST_COURSE)
assert course.status_code == 200
d = client.get("/api/user/course", json=TEST_COURSE)
data = d.json()[1]
assert data['course_name'] == TEST_COURSE['name']
assert data['crn'] == TEST_COURSE['cid']
assert data['semester'] == TEST_COURSE['semester']
client.delete("/api/session", json = {"sessionID": r.json()["content"]["sessionID"]})

def test_user_course_get_failure(client: Client):
r = client.post("/api/user/course", json = TEST_COURSE)
assert r.status_code == 403

0 comments on commit 4435ccf

Please sign in to comment.