From 1f74a88db139eb40ef070642d5adad258cbc8ebc Mon Sep 17 00:00:00 2001 From: etyemyer Date: Wed, 24 Jun 2015 12:42:55 +0300 Subject: [PATCH 1/5] Updated tests and added deleted tests --- Testing/CampusAPI_Test.py | 4 +- Testing/CoursesAPI_test.py | 112 +++++++++++++++++--------------- Testing/ProjectAPI_Test.py | 112 ++++++++++++++++++++++++++++++++ Testing/UserAPI_Test.py | 128 ++++++++++++++++++++++++++++++++++++- 4 files changed, 301 insertions(+), 55 deletions(-) create mode 100644 Testing/ProjectAPI_Test.py 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..70c5819 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,93 @@ 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 = 'http://se-hub.appspot.com/api/courses/create/_QA_TOKEN_TEST_LECTURER' + 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) + + #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + r = requests.post(url, params=params, 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} + } + ''' + # 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"+"_________") 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("***********************************************") 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..6b202a9 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,166 @@ 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'],[]) + 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'],[]) + 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'],[]) + 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', @@ -93,8 +189,15 @@ class UserTestPlan(unittest.TestCase): r = requests.post(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', @@ -105,8 +208,15 @@ class UserTestPlan(unittest.TestCase): r = requests.post(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', @@ -117,8 +227,15 @@ class UserTestPlan(unittest.TestCase): r = requests.post(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', @@ -128,6 +245,11 @@ class UserTestPlan(unittest.TestCase): headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.post(url, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 404) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") if __name__ == '__main__': - unittest.main() \ No newline at end of file + suite = unittest.TestLoader().loadTestsFromTestCase(UserTestPlan) + unittest.TextTestRunner(verbosity=2).run(suite) + #unittest.main() \ No newline at end of file From 66197ad81602fdb9532e82757b760db209c18454 Mon Sep 17 00:00:00 2001 From: etyemyer Date: Mon, 29 Jun 2015 17:14:36 +0300 Subject: [PATCH 2/5] added tests --- Testing/CoursesAPI_test.py | 82 ++++++++++++++++++++++++++++++++++---- Testing/UserAPI_Test.py | 14 +++---- 2 files changed, 81 insertions(+), 15 deletions(-) diff --git a/Testing/CoursesAPI_test.py b/Testing/CoursesAPI_test.py index 70c5819..c9a1fbe 100644 --- a/Testing/CoursesAPI_test.py +++ b/Testing/CoursesAPI_test.py @@ -23,18 +23,17 @@ class CoursesTestPlan(unittest.TestCase): print(self._testMethodName+"Has begun") print("***********************************************") headers = {'content-type': 'application/json'} - url = 'http://se-hub.appspot.com/api/courses/create/_QA_TOKEN_TEST_LECTURER' - params = {'seToken': 'seToken' } + url = self.__class__.url_ +'api/courses/create/_QA_TOKEN_TEST_LECTURER' + #params = {'seToken': 'seToken' } data = { - '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', + 'courseName': 'Advance Math', + 'campusName': 'JCE', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, - 'endDate': {'year': 2016,'month' : 6,'day' : 6} + '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, params=params, data=json.dumps(data), headers=headers) + r = requests.post(url, data=json.dumps(data), headers=headers) ''' payload = { 'courseName': 'QA COURSE', @@ -47,7 +46,7 @@ class CoursesTestPlan(unittest.TestCase): # 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"+"_________") + if(r.status_code!=201):print("_____"+self._testMethodName+" has Failed"+"_____" + r._content) self.assertEquals(r.status_code, 201) @@ -105,5 +104,72 @@ class CoursesTestPlan(unittest.TestCase): 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/UserAPI_Test.py b/Testing/UserAPI_Test.py index 6b202a9..ec13e09 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -107,7 +107,7 @@ class UserTestPlan(unittest.TestCase): 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("***********************************************") @@ -119,7 +119,7 @@ class UserTestPlan(unittest.TestCase): 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("***********************************************") @@ -155,7 +155,7 @@ class UserTestPlan(unittest.TestCase): 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("***********************************************") @@ -186,7 +186,7 @@ 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("***********************************************") @@ -205,7 +205,7 @@ 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("***********************************************") @@ -224,7 +224,7 @@ 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("***********************************************") @@ -243,7 +243,7 @@ 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") From ad0451e721322b0a2c1e069cc4e8000275f214bc Mon Sep 17 00:00:00 2001 From: etyemyer Date: Mon, 29 Jun 2015 17:44:46 +0300 Subject: [PATCH 3/5] Courses API changes added --- Testing/CoursesAPI_test.py | 132 +++++++------------------------------ 1 file changed, 24 insertions(+), 108 deletions(-) diff --git a/Testing/CoursesAPI_test.py b/Testing/CoursesAPI_test.py index c9a1fbe..f4c37d5 100644 --- a/Testing/CoursesAPI_test.py +++ b/Testing/CoursesAPI_test.py @@ -2,7 +2,6 @@ __author__ = 'etye' import unittest import requests import json -import datetime from Testing.config import __CONFIG__ class CoursesTestPlan(unittest.TestCase): @classmethod @@ -18,22 +17,19 @@ class CoursesTestPlan(unittest.TestCase): print 'Initialized' 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' } + url = 'http://se-hub.appspot.com/api/courses/create/_QA_TOKEN_TEST_LECTURER' + params = {'seToken': 'seToken' } data = { - 'courseName': 'Advance Math', - 'campusName': 'JCE', + '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' : 5, 'day' : 14} + 'endDate': {'year': 2016,'month' : 6,'day' : 6} } #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) - r = requests.post(url, data=json.dumps(data), headers=headers) + r = requests.post(url, params=params, data=json.dumps(data), headers=headers) ''' payload = { 'courseName': 'QA COURSE', @@ -45,16 +41,9 @@ class CoursesTestPlan(unittest.TestCase): ''' # 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) - + #self.assertEquals(r.status_code, 201) 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 = { @@ -64,20 +53,24 @@ class CoursesTestPlan(unittest.TestCase): 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - r = requests.post(url, data=json.dumps(data), headers=headers) + params = {'seToken': 'seToken' } + r = requests.post(url, params=params, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 403) - print("***********************************************") - print(self._testMethodName+"Has finished Successfully") - print("***********************************************") - + ''' + payload = {'courseName': 'Advance Math', 'campusName': 'JCE', 'startDate':'2015-14-3','endDate': '2015-29-6','taskFlag': 'False'} + 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} + } + r = requests.post(self.__class__.url_+'api/courses/create/invalidToken',data=payload) + ''' 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' } + params = {'seToken': 'seToken' } data = { 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', @@ -87,89 +80,12 @@ class CoursesTestPlan(unittest.TestCase): } #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) - r = requests.post(url, data=json.dumps(data), headers=headers) + r = requests.post(url, params=params, 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_getCourseByCampusName(self): - print (datetime.datetime.now().time()) - print("***********************************************") - print(self._testMethodName+"Has begun") - print("***********************************************") - r = requests.get(self.__class__.url_+'api/courses/getCourseByCampusName/JCE') + r = requests.get(self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['TOKENS']['CAMPUS_NAME']) 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 From d0d6ed3851dac85aec7b389c165c3ad9cabccf54 Mon Sep 17 00:00:00 2001 From: etyemyer Date: Mon, 29 Jun 2015 17:45:02 +0300 Subject: [PATCH 4/5] Courses API changes added --- Testing/CoursesAPI_test.py | 132 ++++++++++++++++++++++++++++++------- 1 file changed, 108 insertions(+), 24 deletions(-) diff --git a/Testing/CoursesAPI_test.py b/Testing/CoursesAPI_test.py index f4c37d5..c9a1fbe 100644 --- a/Testing/CoursesAPI_test.py +++ b/Testing/CoursesAPI_test.py @@ -2,6 +2,7 @@ __author__ = 'etye' import unittest import requests import json +import datetime from Testing.config import __CONFIG__ class CoursesTestPlan(unittest.TestCase): @classmethod @@ -17,19 +18,22 @@ class CoursesTestPlan(unittest.TestCase): print 'Initialized' def test_coursesCreate_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") headers = {'content-type': 'application/json'} - url = 'http://se-hub.appspot.com/api/courses/create/_QA_TOKEN_TEST_LECTURER' - params = {'seToken': 'seToken' } + url = self.__class__.url_ +'api/courses/create/_QA_TOKEN_TEST_LECTURER' + #params = {'seToken': 'seToken' } data = { - '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', + 'courseName': 'Advance Math', + 'campusName': 'JCE', 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, - 'endDate': {'year': 2016,'month' : 6,'day' : 6} + '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, params=params, data=json.dumps(data), headers=headers) + r = requests.post(url, data=json.dumps(data), headers=headers) ''' payload = { 'courseName': 'QA COURSE', @@ -41,9 +45,16 @@ class CoursesTestPlan(unittest.TestCase): ''' # 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) - #self.assertEquals(r.status_code, 201) + print(r._content) + if(r.status_code!=201):print("_____"+self._testMethodName+" has Failed"+"_____" + r._content) + self.assertEquals(r.status_code, 201) + 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 = { @@ -53,24 +64,20 @@ class CoursesTestPlan(unittest.TestCase): 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'endDate': {'year': 2016,'month' : 6,'day' : 6} } - params = {'seToken': 'seToken' } - r = requests.post(url, params=params, data=json.dumps(data), headers=headers) + r = requests.post(url, data=json.dumps(data), headers=headers) self.assertEquals(r.status_code, 403) - ''' - payload = {'courseName': 'Advance Math', 'campusName': 'JCE', 'startDate':'2015-14-3','endDate': '2015-29-6','taskFlag': 'False'} - 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} - } - r = requests.post(self.__class__.url_+'api/courses/create/invalidToken',data=payload) - ''' + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + 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' } + #params = {'seToken': 'seToken' } data = { 'courseName': 'QA COURSE', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', @@ -80,12 +87,89 @@ class CoursesTestPlan(unittest.TestCase): } #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) - r = requests.post(url, params=params, data=json.dumps(data), headers=headers) + 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_getCourseByCampusName(self): - r = requests.get(self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['TOKENS']['CAMPUS_NAME']) + 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 From a6c162fc92482f908663cb985af3b51dcc1e3ecf Mon Sep 17 00:00:00 2001 From: etyemyer Date: Mon, 29 Jun 2015 19:24:41 +0300 Subject: [PATCH 5/5] Updated User Tests. --- Testing/UserAPI_Test.py | 143 +++++++++++++++++++++++++++++++++++++++- Testing/config.py | 4 ++ 2 files changed, 146 insertions(+), 1 deletion(-) diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index ec13e09..c76dea8 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -29,6 +29,8 @@ class UserTestPlan(unittest.TestCase): print(self._testMethodName+"Has finished Successfully") print("***********************************************") + + def test_getUserByToken_valid(self): print (datetime.datetime.now().time()) print("***********************************************") @@ -167,7 +169,6 @@ class UserTestPlan(unittest.TestCase): 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("***********************************************") @@ -249,6 +250,146 @@ class UserTestPlan(unittest.TestCase): 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//