diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py index 8f8775e..0b72d61 100644 --- a/Testing/CampusAPI_Test.py +++ b/Testing/CampusAPI_Test.py @@ -21,13 +21,13 @@ class UserTestPlan(unittest.TestCase): #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" url=self.__class__.url_+'api/campuses/create/'+__CONFIG__['TOKENS']['LECTURER'] data = { - 'title': 'Campus name', + 'title': 'QA Campus', 'email_ending': '@campus.ac.com', 'avatar_url': 'http://location.domain.com/image.jpg' } headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 201) + self.assertEquals(r.status_code, 200) def test_campusCreate_student(self): #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" diff --git a/Testing/CoursesAPI_test.py b/Testing/CoursesAPI_test.py index dcc9a84..c9a1fbe 100644 --- a/Testing/CoursesAPI_test.py +++ b/Testing/CoursesAPI_test.py @@ -2,9 +2,9 @@ __author__ = 'etye' import unittest import requests import json +import datetime from Testing.config import __CONFIG__ - -class UserTestPlan(unittest.TestCase): +class CoursesTestPlan(unittest.TestCase): @classmethod def setUpClass(cls): debug = __CONFIG__['DEBUG'] @@ -17,81 +17,159 @@ class UserTestPlan(unittest.TestCase): if 200 <= request.status_code <= 299: print 'Initialized' - def test_courseCreate_lecturer(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'] + def test_coursesCreate_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_ +'api/courses/create/_QA_TOKEN_TEST_LECTURER' + #params = {'seToken': 'seToken' } data = { - 'courseName': 'matan', + 'courseName': 'Advance Math', + 'campusName': 'JCE', + 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, + 'endDate': {'year': 2016, 'month' : 5, 'day' : 14} + } + + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.post(url, data=json.dumps(data), headers=headers) + ''' + payload = { + 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'projects': '@gay.lord.ultima.multi.omega', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) + ''' + # r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'],data=payload) + #r = requests.post('http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER',data=payload) + print(r._content) + if(r.status_code!=201):print("_____"+self._testMethodName+" has Failed"+"_____" + r._content) self.assertEquals(r.status_code, 201) - def test_courseCreate_lecturerExsistingCourse(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'] + + def test_coursesCreate_InvalidToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/create/invalidToken' data = { - 'courseName': 'matan', + 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'projects': '@gay.lord.ultima.multi.omega', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.post(url, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 403) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") - def test_courseCreate_student(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'] + def test_coursesCreate_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/create/_QA_TOKEN_TEST_STUDENT' + #params = {'seToken': 'seToken' } data = { - 'courseName': 'matan', + 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'projects': '@gay.lord.ultima.multi.omega', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 403) - def test_courseCreate_invalidToken(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/invalidToken' - data = { - 'courseName': 'matan', - 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', - 'projects': '@gay.lord.ultima.multi.omega', - 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, - 'endDate': {'year': 2016,'month' : 6,'day' : 6} - } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 403) + self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") - def test_courseCreate_hebrewToken(self): - #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" - url=self.__class__.url_+'api/courses/create/????' - data = { - 'courseName': 'matan', - 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', - 'projects': '@gay.lord.ultima.multi.omega', - 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, - 'endDate': {'year': 2016,'month' : 6,'day' : 6} - } - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) - self.assertEquals(r.status_code, 404) - - #/api/courses/getCourseByCampusName/ - def test_getCourseByCampusName_EXSISTING_CAMPUS(self): - url=self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['CAMPUS_NAME']['JCE'] - r = requests.get(url) + def test_getCourseByCampusName(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + r = requests.get(self.__class__.url_+'api/courses/getCourseByCampusName/JCE') self.assertEquals(r.status_code, 200) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + + #/api/courses/createMessage/ + ''' + Payload + - JSON Object, Example: + { + 'courseName': 'Advance Math', + 'message': 'The lecture today is canceled' + } + ''' + def test_createMessage_lecturerToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/createMessage/_QA_TOKEN_TEST_LECTURER' + #params = {'seToken': 'seToken' } + data = { + 'courseName': 'Advance Math', + 'message': 'The lecture today is canceled' + } + + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.post(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 201, 'message: ' + r.json()['message']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + + def test_createMessage_studentToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/createMessage/_QA_TOKEN_TEST_STUDENT' + #params = {'seToken': 'seToken' } + data = { + 'courseName': 'Advance Math', + 'message': 'The lecture today is canceled' + } + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.post(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + + def test_createMessage_invalidToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/createMessage/invalidToken' + #params = {'seToken': 'seToken' } + data = { + 'courseName': 'Advance Math', + 'message': 'The lecture today is canceled' + } + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.post(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/Testing/ProjectAPI_Test.py b/Testing/ProjectAPI_Test.py new file mode 100644 index 0000000..a2746e8 --- /dev/null +++ b/Testing/ProjectAPI_Test.py @@ -0,0 +1,112 @@ +__author__ = 'etye' +import unittest +import requests +import json +#import logging +import datetime + +from Testing.config import __CONFIG__ +class ProjectTestPlan(unittest.TestCase): + @classmethod + def setUpClass(cls): + debug = __CONFIG__['DEBUG'] + if debug: + url = __CONFIG__['PATHS']['DEBUG'] + else: + url = __CONFIG__['PATHS']['PRODUCTION'] + cls.url_ = url + request = requests.get(url+'api/qa/init') + if 200 <= request.status_code <= 299: + print 'Initialized' + + #/api/projects/create/ + def test_projectCreate_lecturerToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/projects/create/'+__CONFIG__['TOKENS']['LECTURER'] + data = { + 'projectName': 'Advance Math', + 'courseName': 'JCE', + 'logo_url': 'http://location.domain.com/image.jpg', + 'gitRepository': 'http://location.git.com/somthing' + } + + r = requests.post(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 201) + print("***********************************************") + print(self._testMethodName+"Has finished") + #print("Test Project Create w/ Lecturer token has finished") + print("***********************************************") + + + def test_projectCreate_studentToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/projects/create/'+__CONFIG__['TOKENS']['STUDENT'] + data = { + 'projectName': 'Advance Math', + 'courseName': 'JCE', + 'logo_url': 'http://location.domain.com/image.jpg', + 'gitRepository': 'http://location.git.com/somthing' + } + r = requests.post(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 403) + print("***********************************************") + print(self._testMethodName+"Has finished") + #print("Test Project Create w/ Lecturer token has finished") + print("***********************************************") + + #/api/projects/deleteProject// + def test_projectDelete_studentToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/projects/create/'+__CONFIG__['TOKENS']['STUDENT'] + r = requests.delete(url) + self.assertEquals(r.status_code, 403) + print("***********************************************") + print(self._testMethodName+"Has finished") + #print("Test Project Create w/ Lecturer token has finished") + print("***********************************************") + + def test_projectDelete_lecturerToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/projects/create/'+__CONFIG__['TOKENS']['STUDENT'] + r = requests.delete(url) + self.assertEquals(r.status_code, 403) + print("***********************************************") + print(self._testMethodName+"Has finished") + #print("Test Project Create w/ Lecturer token has finished") + print("***********************************************") + + def test_projectDelete_invalidToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/projects/create/'+__CONFIG__['TOKENS']['STUDENT'] + r = requests.delete(url) + self.assertEquals(r.status_code, 403) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + #print("Test Project Create w/ Lecturer token has finished") + print("***********************************************") + +if __name__ == '__main__': + suite = unittest.TestLoader().loadTestsFromTestCase(ProjectTestPlan) + unittest.TextTestRunner(verbosity=2).run(suite) + #unittest.main() diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index aa6bb33..c76dea8 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -2,6 +2,7 @@ __author__ = 'etye' import unittest import requests import json +import datetime from Testing.config import __CONFIG__ class UserTestPlan(unittest.TestCase): @@ -18,71 +19,167 @@ class UserTestPlan(unittest.TestCase): print 'Initialized' def test_getUserByToken_invalid(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/invalidtoken') self.assertEquals(r.status_code, 204) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + + def test_getUserByToken_valid(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) self.assertEquals(r.status_code, 200) self.assertEquals(r.json()['username'], 'qa_student') + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_getUserByToken_empty(self): - r = requests.get(self.__class__.url_+'api/users/getUserByToken/') - self.assertEquals(r.status_code, 204) + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + r = requests.get(self.__class__.url_+'api/users/getUserByToken/') + self.assertEquals(r.status_code, 204) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_isStudent_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) self.assertEquals(r.status_code, 200) self.assertFalse(r.json()['isLecturer']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_isLecturer_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER']) self.assertEquals(r.status_code, 200) self.assertTrue(r.json()['isLecturer']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_isFirstLogin_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) self.assertEquals(r.status_code, 200) self.assertTrue(r.json()['isFirstLogin']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_isFirstLogin_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER']) self.assertEquals(r.status_code, 200) self.assertTrue(r.json()['isFirstLogin']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_isClassIdListEmpty_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") 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'],[]) + #self.assertEquals(r.json()['classes_id_list'],[]) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_campuses_id_list_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") 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'],[]) + #self.assertEquals(r.json()['campuses_id_list'],[]) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_Student_isLecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) self.assertEquals(r.status_code, 200) self.assertFalse(r.json()['isLecturer']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_Lecturer_isLecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER']) self.assertEquals(r.status_code, 200) self.assertTrue(r.json()['isLecturer']) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_isClassIdListEmpty_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") 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'],[]) + #self.assertEquals(r.json()['classes_id_list'],[]) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_campuses_id_list_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") 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'],[]) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") #/api/users/updateUser/ def test_updateUser_lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") url=self.__class__.url_+'api/users/updateUser/'+__CONFIG__['TOKENS']['LECTURER'] data = { 'name': 'new name', @@ -90,11 +187,18 @@ class UserTestPlan(unittest.TestCase): 'campusName': 'JCE' } headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) + r = requests.put(url, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 200) self.assertEquals(r._content, '{"message": "User updated"}') + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_updateUser_student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") url=self.__class__.url_+'api/users/updateUser/'+__CONFIG__['TOKENS']['STUDENT'] data = { 'name': 'new name', @@ -102,11 +206,18 @@ class UserTestPlan(unittest.TestCase): 'campusName': 'JCE' } headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) + r = requests.put(url, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 200) self.assertEquals(r._content, '{"message": "User updated"}') + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_updateUser_INVALID_TOKEN(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") url=self.__class__.url_+'api/users/updateUser/invalidToken' data = { 'name': 'new name', @@ -114,11 +225,18 @@ class UserTestPlan(unittest.TestCase): 'campusName': 'JCE' } headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) + r = requests.put(url, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 400) self.assertEquals(r._content, '{"message": "Not a user!"}') + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") def test_updateUser_HEBREW_TOKEN(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") url=self.__class__.url_+'api/users/updateUser/?????' data = { 'name': 'new name', @@ -126,8 +244,153 @@ class UserTestPlan(unittest.TestCase): 'campusName': 'JCE' } headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - r = requests.post(url, data=json.dumps(data), headers=headers) + r = requests.put(url, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 404) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + + #/api/users/addUserToCampus/ + def test_addUserToCampus_lecturer(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/users/addUserToCampus/'+__CONFIG__['TOKENS']['LECTURER'] + #params = {'seToken': 'seToken' } + data = { + "campusId": 6736157987569664 + } + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.put(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 200) + + def test_addUserToCampus_student(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/users/addUserToCampus/'+__CONFIG__['TOKENS']['STUDENT'] + #params = {'seToken': 'seToken' } + data = { + "campusId": 6736157987569664 + } + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.put(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 400) + + def test_addUserToCampus_invalidToken(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/users/addUserToCampus/invalidToken' + #params = {'seToken': 'seToken' } + data = { + "campusId": 6736157987569664 + } + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.put(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 400) + + ''' + def test_addUserToCourse_invalidToken(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/users/addUserToCourse/invalidToken' + #params = {'seToken': 'seToken' } + data = { + "campusId": 5522297150504960 + } + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.put(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 400) + + def test_addUserToCourse_lecturer(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/users/addUserToCampus/'+__CONFIG__['TOKENS']['LECTURER'] + #params = {'seToken': 'seToken' } + data = { + "courseId": 5522297150504960 + } + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.put(url, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, ) +''' + def test_getUserById_student(self): + #url = self.__class__.url_+'api/users/getUserById/'+__CONFIG__['TOKENS']['STUDENT'] + '/'+__CONFIG__['ID']['STUDENT_ID'] + url = 'http://localhost:8080/api/users/getUserById/_QA_TOKEN_TEST_STUDENT/6225984592281600' + r = requests.get(url) + self.assertEquals(r.status_code, 200) + + def test_getUserById_lecturer(self): + #url = self.__class__.url_+'api/users/getUserById/'+__CONFIG__['TOKENS']['STUDENT'] + '/'+__CONFIG__['ID']['STUDENT_ID'] + url = 'http://localhost:8080/api/users/getUserById/_QA_TOKEN_TEST_LECTURER/6225984592281600' + r = requests.get(url) + self.assertEquals(r.status_code, 200) + + def test_getUserById_invalidToken(self): + #url = self.__class__.url_+'api/users/getUserById/'+__CONFIG__['TOKENS']['STUDENT'] + '/'+__CONFIG__['ID']['STUDENT_ID'] + url = 'http://localhost:8080/api/users/getUserById/invalidToken/InvalidId' + r = requests.get(url) + self.assertEquals(r.status_code, 403) + + #/api/users/getUsersByCampus//