From aaa5ba223a42acd1cab40a0af823a8b8542e7261 Mon Sep 17 00:00:00 2001 From: etyemyer Date: Sun, 14 Jun 2015 23:45:09 +0300 Subject: [PATCH 1/6] UserApi_Test - test getuserbytoken with valid,invalid and empty string CampusesApi_test - with valid,invalid string --- Testing/CampusAPI_Test.py | 20 ++++++++++++-------- Testing/UserAPI_Test.py | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py index 6f0c6e4..d43f62f 100644 --- a/Testing/CampusAPI_Test.py +++ b/Testing/CampusAPI_Test.py @@ -3,7 +3,8 @@ import unittest import requests from Testing.config import __CONFIG__ class UserTestPlan(unittest.TestCase): - def setUpClass(cls): + @classmethod + def setUpClass(cls): debug = __CONFIG__['DEBUG'] if debug: url = __CONFIG__['PATHS']['DEBUG'] @@ -14,13 +15,16 @@ class UserTestPlan(unittest.TestCase): if 200 <= request.status_code <= 299: print 'Initialized' - def test_Campuses_invalid(self): - r = requests.get(self.__class__.url_+'api/Campuses/invalidtoken') - self.assertEquals(r.status_code, 403) - def test_Campuses_valid(self): - r = requests.get(self.__class__.url_+'api/Campuses/'+__CONFIG__['TOKENS']['STUDENT']) - self.assertEquals(r.status_code, 200) - self.assertEquals(r.json()['username'], 'qa_student') + def test_Campuses_invalidToken(self): + r = requests.get(self.__class__.url_+'api/Campuses/invalidtoken') + self.assertEquals(r.status_code, 403) + + def test_Campuses_validToken_testArraySize(self): + r = requests.get(self.__class__.url_+'api/Campuses/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 200) + self.assertTrue(len(r.json())>= 1) + + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index 67b9cf6..f1ba2d8 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -30,7 +30,7 @@ class UserTestPlan(unittest.TestCase): def test_getUserByToken_empty(self): r = requests.get(self.__class__.url_+'api/getUserByToken/') self.assertEquals(r.status_code, 400) - + if __name__ == '__main__': From 2671376db4592c8505498fd1ded93b9a715602d7 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 19:54:15 +0300 Subject: [PATCH 2/6] added updateUser function --- SE_API/UserRoutes.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index e487f2a..efad1bc 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -70,6 +70,57 @@ def getUserByToken(token): return bad_request("No User Found") +@user_routes.route('/api/users/updateUser/', methods=["GET"]) +@auto.doc() +def updateUser(token): + """ + >This Call will update user details +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - JSON Object, Example:
+ {
+ 'name': 'Campus name',
+ 'isLecturer': '@campus.ac.com',
+ }
+
+ Response +
+ 200 - User updated +
+ 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') def documentation(): return auto.html() \ No newline at end of file From 315e07aad250c3f43d5114abad2473627e21909e Mon Sep 17 00:00:00 2001 From: etyemyer Date: Mon, 15 Jun 2015 20:49:57 +0300 Subject: [PATCH 3/6] UserApi_Test - test getuserbytoken with valid,invalid and empty string CampusesApi_test - with valid,invalid string --- Testing/UserAPI_Test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index f1ba2d8..179979e 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -18,7 +18,7 @@ class UserTestPlan(unittest.TestCase): def test_getUserByToken_invalid(self): r = requests.get(self.__class__.url_+'api/getUserByToken/invalidtoken') - self.assertEquals(r.status_code, 403) + self.assertEquals(r.status_code, 204) def test_getUserByToken_valid(self): @@ -30,7 +30,7 @@ class UserTestPlan(unittest.TestCase): def test_getUserByToken_empty(self): r = requests.get(self.__class__.url_+'api/getUserByToken/') self.assertEquals(r.status_code, 400) - + if __name__ == '__main__': From f25e50862356153a74ada7cdb04172bbdf288653 Mon Sep 17 00:00:00 2001 From: etyemyer Date: Mon, 15 Jun 2015 22:11:46 +0300 Subject: [PATCH 4/6] UserApi_Test - test getuserbytoken with valid,invalid and empty string CampusesApi_test - with valid,invalid string --- Testing/CampusAPI_Test.py | 9 ++++---- Testing/UserAPI_Test.py | 44 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py index d43f62f..09be45d 100644 --- a/Testing/CampusAPI_Test.py +++ b/Testing/CampusAPI_Test.py @@ -15,16 +15,17 @@ class UserTestPlan(unittest.TestCase): if 200 <= request.status_code <= 299: print 'Initialized' - def test_Campuses_invalidToken(self): - r = requests.get(self.__class__.url_+'api/Campuses/invalidtoken') + def test_campusesGet_invalidToken(self): + r = requests.get(self.__class__.url_+'api/campuses/getAll/invalidtoken') self.assertEquals(r.status_code, 403) - def test_Campuses_validToken_testArraySize(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.assertTrue(len(r.json())>= 1) + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index e907400..7baa8cb 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -18,7 +18,7 @@ class UserTestPlan(unittest.TestCase): def test_getUserByToken_invalid(self): 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): 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): 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): 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.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.assertFalse(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__': unittest.main() \ No newline at end of file From 0a403286bf88e4f1b76ace6fda57be7f80d1a463 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 16 Jun 2015 09:35:41 +0300 Subject: [PATCH 5/6] API: Fixed Testing init route function --- SE_API/API.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SE_API/API.py b/SE_API/API.py index a1ad212..972c39e 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -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', 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', - 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) for u in query.run(): is_student_exist = True From bd541b59c4a0298d865ba666cd16d5a1aede4473 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 16 Jun 2015 09:37:25 +0300 Subject: [PATCH 6/6] QA: Fixed a small test in UserAPI --- Testing/UserAPI_Test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index 7baa8cb..1af62c3 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -67,7 +67,7 @@ class UserTestPlan(unittest.TestCase): def test_Lecturer_isLecturer(self): r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER']) self.assertEquals(r.status_code, 200) - self.assertFalse(r.json()['isLecturer']) + self.assertTrue(r.json()['isLecturer']) def test_isClassIdListEmpty_Lecturer(self): r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])