Merge branch 'master' of https://github.com/sagidayan/SE-Hub into UI
This commit is contained in:
commit
79a69225a1
4 changed files with 107 additions and 11 deletions
|
@ -214,7 +214,7 @@ def init_QA():
|
||||||
qa_student = User(username='qa_student', name='Student QA', avatar_url='http://ava.com', email='just@mail.com',
|
qa_student = User(username='qa_student', name='Student QA', avatar_url='http://ava.com', email='just@mail.com',
|
||||||
isLecturer=False, accessToken='student_token_', seToken='_QA_TOKEN_TEST_STUDENT')
|
isLecturer=False, accessToken='student_token_', seToken='_QA_TOKEN_TEST_STUDENT')
|
||||||
qa_lecturer = User(username='qa_lecturer', name='Student QA', avatar_url='http://ava.com', email='just@mail.com',
|
qa_lecturer = User(username='qa_lecturer', name='Student QA', avatar_url='http://ava.com', email='just@mail.com',
|
||||||
isLecturer=False, accessToken='student_token_', seToken='_QA_TOKEN_TEST_LECTURER')
|
isLecturer=True, accessToken='student_token_', seToken='_QA_TOKEN_TEST_LECTURER')
|
||||||
query = User.all().filter('username =', qa_student.username)
|
query = User.all().filter('username =', qa_student.username)
|
||||||
for u in query.run():
|
for u in query.run():
|
||||||
is_student_exist = True
|
is_student_exist = True
|
||||||
|
|
|
@ -70,6 +70,57 @@ def getUserByToken(token):
|
||||||
return bad_request("No User Found")
|
return bad_request("No User Found")
|
||||||
|
|
||||||
|
|
||||||
|
@user_routes.route('/api/users/updateUser/<string:token>', methods=["GET"])
|
||||||
|
@auto.doc()
|
||||||
|
def updateUser(token):
|
||||||
|
"""
|
||||||
|
<span class="card-title">>This Call will update user details</span>
|
||||||
|
<br>
|
||||||
|
<b>Route Parameters</b><br>
|
||||||
|
- seToken: 'seToken'
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Payload</b><br>
|
||||||
|
- JSON Object, Example: <br>
|
||||||
|
{<br>
|
||||||
|
'name': 'Campus name',<br>
|
||||||
|
'isLecturer': '@campus.ac.com',<br>
|
||||||
|
}<br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
200 - User updated
|
||||||
|
<br>
|
||||||
|
400 - Bad Request
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not request.data:
|
||||||
|
return bad_request()
|
||||||
|
|
||||||
|
try:
|
||||||
|
payload = json.loads(request.data)
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request(e)
|
||||||
|
|
||||||
|
user = get_user_by_token(token)
|
||||||
|
if user is None:
|
||||||
|
return bad_request("Not a user!")
|
||||||
|
|
||||||
|
try:
|
||||||
|
user.name = payload['user']
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
user.isLecturer = payload['isLecturer']
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
return ok("User updated")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@user_routes.route('/api/users/help')
|
@user_routes.route('/api/users/help')
|
||||||
def documentation():
|
def documentation():
|
||||||
return auto.html()
|
return auto.html()
|
|
@ -3,6 +3,7 @@ import unittest
|
||||||
import requests
|
import requests
|
||||||
from Testing.config import __CONFIG__
|
from Testing.config import __CONFIG__
|
||||||
class UserTestPlan(unittest.TestCase):
|
class UserTestPlan(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
debug = __CONFIG__['DEBUG']
|
debug = __CONFIG__['DEBUG']
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -14,13 +15,17 @@ class UserTestPlan(unittest.TestCase):
|
||||||
if 200 <= request.status_code <= 299:
|
if 200 <= request.status_code <= 299:
|
||||||
print 'Initialized'
|
print 'Initialized'
|
||||||
|
|
||||||
def test_Campuses_invalid(self):
|
def test_campusesGet_invalidToken(self):
|
||||||
r = requests.get(self.__class__.url_+'api/Campuses/invalidtoken')
|
r = requests.get(self.__class__.url_+'api/campuses/getAll/invalidtoken')
|
||||||
self.assertEquals(r.status_code, 403)
|
self.assertEquals(r.status_code, 403)
|
||||||
def test_Campuses_valid(self):
|
|
||||||
r = requests.get(self.__class__.url_+'api/Campuses/'+__CONFIG__['TOKENS']['STUDENT'])
|
def test_campusesGet_validToken_testArraySize(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/campuses/getAll/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||||
self.assertEquals(r.status_code, 200)
|
self.assertEquals(r.status_code, 200)
|
||||||
self.assertEquals(r.json()['username'], 'qa_student')
|
self.assertTrue(len(r.json())>= 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
|
@ -18,7 +18,7 @@ class UserTestPlan(unittest.TestCase):
|
||||||
|
|
||||||
def test_getUserByToken_invalid(self):
|
def test_getUserByToken_invalid(self):
|
||||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/invalidtoken')
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/invalidtoken')
|
||||||
self.assertEquals(r.status_code, 403)
|
self.assertEquals(r.status_code, 204)
|
||||||
|
|
||||||
def test_getUserByToken_valid(self):
|
def test_getUserByToken_valid(self):
|
||||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||||
|
@ -27,7 +27,7 @@ class UserTestPlan(unittest.TestCase):
|
||||||
|
|
||||||
def test_getUserByToken_empty(self):
|
def test_getUserByToken_empty(self):
|
||||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/')
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/')
|
||||||
self.assertEquals(r.status_code, 400)
|
self.assertEquals(r.status_code, 204)
|
||||||
|
|
||||||
def test_isStudent_Student(self):
|
def test_isStudent_Student(self):
|
||||||
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||||
|
@ -39,6 +39,46 @@ class UserTestPlan(unittest.TestCase):
|
||||||
self.assertEquals(r.status_code, 200)
|
self.assertEquals(r.status_code, 200)
|
||||||
self.assertTrue(r.json()['isLecturer'])
|
self.assertTrue(r.json()['isLecturer'])
|
||||||
|
|
||||||
|
def test_isFirstLogin_Student(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertTrue(r.json()['isFirstLogin'])
|
||||||
|
|
||||||
|
def test_isFirstLogin_Lecturer(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertTrue(r.json()['isFirstLogin'])
|
||||||
|
|
||||||
|
def test_isClassIdListEmpty_Student(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertEquals(r.json()['classes_id_list'],[])
|
||||||
|
|
||||||
|
def test_campuses_id_list_Student(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertEquals(r.json()['campuses_id_list'],[])
|
||||||
|
|
||||||
|
def test_Student_isLecturer(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertFalse(r.json()['isLecturer'])
|
||||||
|
|
||||||
|
def test_Lecturer_isLecturer(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertTrue(r.json()['isLecturer'])
|
||||||
|
|
||||||
|
def test_isClassIdListEmpty_Lecturer(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertEquals(r.json()['classes_id_list'],[])
|
||||||
|
|
||||||
|
def test_campuses_id_list_Lecturer(self):
|
||||||
|
r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
|
||||||
|
self.assertEquals(r.status_code, 200)
|
||||||
|
self.assertEquals(r.json()['campuses_id_list'],[])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
Loading…
Reference in a new issue