-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fast api user post and delete (#541)
* Create user.py * Delete user.py * Create flasktest.py * passed user post test * test case for delete * all test cases * change based on comments * Update .gitignore * Delete yacs.n.iml * Delete workspace.xml * Delete modules.xml * Delete vcs.xml * Delete runConfigurations.xml * removed .idea/.gitignore Co-authored-by: Liam Haining <[email protected]>
- Loading branch information
1 parent
d524b7f
commit dba5d56
Showing
2 changed files
with
72 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 |
---|---|---|
|
@@ -9,4 +9,4 @@ node_modules/ | |
.python-version | ||
*.ipynb* | ||
courses20.xml | ||
.coverage | ||
.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from .util import Client | ||
TEST_USER = { 'email': '[email protected]', | ||
'password': '123456' } | ||
|
||
TEST_USER_SIGNUP = { 'email': '[email protected]', | ||
'name': 'TestName', | ||
'phone': '', | ||
'password': '123456', | ||
'degree': 'Undergraduate', | ||
'major': 'CSCI' } | ||
|
||
# pytest -s tests/test_user.py | ||
def test_user_post_success(post_user, client: Client): | ||
''' | ||
add a valid new user into the session | ||
''' | ||
r = client.post("/api/user", json= {"name": "test2", "email":"[email protected]","phone": "", "password":"test123", "major":"", "degree":""} ) | ||
data = r.json() | ||
assert r.status_code == 200 | ||
assert data['content'] is not None | ||
assert data['content']['msg'] == "User added successfully." | ||
r = client.post('/api/session', json={"email":"[email protected]", "password":"test123"}) | ||
assert r.status_code == 200 | ||
client.delete("/api/user", json={"sessionID":r.json()['content']['sessionID'], 'password':'test123'}) | ||
|
||
def test_user_post_failure(post_user, client: Client): | ||
''' | ||
add a invalid new user into the session | ||
''' | ||
r = client.post("/api/user", json= {"name": "test1", "email":"test1","phone": "", "password":"123", "major":"", "degree":""}) | ||
data = r.json() | ||
assert data['content'] is None | ||
assert r.status_code == 200 | ||
|
||
def test_user_delete_success(post_user, client: Client): | ||
''' | ||
delete a valid user in the session | ||
''' | ||
r1 = client.post("/api/session", json=TEST_USER) # {'email':'[email protected]', 'password': 'test123'}) | ||
data = r1.json() | ||
sessionid = data['content']['sessionID'] | ||
r2 = client.delete("/api/user", json= {"sessionID": sessionid, "password": "123456"}) | ||
assert r2.status_code == 200 | ||
r=client.post('/api/user', json=TEST_USER_SIGNUP) | ||
assert r.status_code == 200 | ||
data = r.json() | ||
# assert data['content'] is not None | ||
# assert data['content']['msg'] == "User added successfully." | ||
|
||
def test_user_delete_failure(post_user, client: Client): | ||
''' | ||
delete a not exist user in the session | ||
''' | ||
r1 = client.post("/api/session", json=TEST_USER) # {'email':'[email protected]', 'password': 'test123'}) | ||
data = r1.json() | ||
sessionid = data['content']['sessionID'] | ||
r2 = client.delete("/api/user", json= {"sessionID": sessionid, "password": "12345"}) | ||
assert r2.status_code == 200 | ||
data2 = r2.json() | ||
assert data2['errMsg'] == "Wrong password." | ||
|
||
def test_user_delete_failure2(post_user, client: Client): | ||
''' | ||
delete the session, then try to delete user | ||
''' | ||
sess = client.post("/api/session", json=TEST_USER).json() | ||
sessID = sess['content']['sessionID'] | ||
r = client.delete('/api/session', json={'sessionID': sessID}) | ||
assert r.status_code == 200 | ||
r1 = client.delete("/api/user", json= {"sessionID": sessID, "password": "12345"}) | ||
assert r1.status_code == 403 |