-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
User endpoint tests #888
base: develop
Are you sure you want to change the base?
User endpoint tests #888
Changes from all commits
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,60 @@ | ||
import unittest | ||
import requests | ||
import logging as logger | ||
from flask import g | ||
|
||
headers = { | ||
'Host': 'localhost:5000', | ||
'Accept': 'application/json, text/plain, */*', | ||
'Accept-Language': 'en-US,en;q=0.5', | ||
'Accept-Encoding': 'gzip, deflate', | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Origin': 'http://localhost:3000', | ||
} | ||
user_data = { | ||
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. Will we need to load these 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. Right now these are just present in this file itself in future I will create a config to store this data. 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. OK. 😀 |
||
"user_name": "user", | ||
"password": "password", | ||
"email": "[email protected]", | ||
"auth": "0" | ||
} | ||
|
||
regular_user_data = { | ||
"user_name": "reg_user", | ||
"password": "password", | ||
"email": "[email protected]", | ||
} | ||
|
||
correctlogin = "user_name=rand&password=pass" | ||
|
||
url = "http://localhost:5000/api" | ||
|
||
class TestFlaskAPIUsingRequests(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(TestFlaskAPIUsingRequests, cls).setUpClass() | ||
resp = requests.post(url + '/login', correctlogin, headers=headers) | ||
cls.token = resp.headers['token'] | ||
|
||
def test_api_user_login(self): | ||
resp = requests.post(url + '/user', json=user_data, | ||
headers={'Content-Type': 'application/json', 'token': self.token, | ||
'Access-Control-Expose-Headers': 'token', | ||
'Access-Control-Allow-Origin': 'http://localhost:3000'}) | ||
self.assertEqual(resp.status_code, 200) | ||
|
||
def test_api_regular_user_login(self): | ||
resp = requests.post(url + '/regularuser', json=regular_user_data, | ||
headers={'Content-Type': 'application/json'}) | ||
self.assertEqual(resp.status_code, 200) | ||
|
||
def test_api_remove_user_request(self): | ||
resp = requests.delete(url + '/user/user', | ||
headers={'token': self.token, 'Access-Control-Expose-Headers': 'token', | ||
'Access-Control-Allow-Origin': 'http://localhost:3000'}) | ||
self.assertEqual(resp.status_code, 200) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
|
||
|
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.
Are these imports used? If not let's remove these.