Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion components/core/UserManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def remove_user(username):
cursor = db.cursor()
sql = "DELETE from user WHERE user_name=%s;"
try:
cursor.execute(sql, (username))
cursor.execute(sql, (username,))
db.commit()
except MySQLdb.Error as e:
db.rollback()
Expand Down
60 changes: 60 additions & 0 deletions components/core/tests/tests_User_endpoint_tests.py
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
Comment on lines +3 to +4

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.


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 = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need to load these passwords/user_names from a config?

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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()