diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py index 0b72d61..2f6075f 100644 --- a/Testing/CampusAPI_Test.py +++ b/Testing/CampusAPI_Test.py @@ -2,6 +2,7 @@ __author__ = 'etye' import unittest import requests import json +import webbrowser from Testing.config import __CONFIG__ class UserTestPlan(unittest.TestCase): @classmethod @@ -69,8 +70,18 @@ class UserTestPlan(unittest.TestCase): self.assertEquals(r.status_code, 200) self.assertTrue(len(r.json())>= 1) + def test_campusesGet_validToken_hebrewToken(self): + r = requests.get(self.__class__.url_+'api/campuses/getAll/????') + self.assertEquals(r.status_code, 403) - + # connectUserToCampus = self.__class__.url_+'http://localhost:8080/api/help/validation/confirm/TOKEN|post.jce.ac.il' + # webbrowser.open('http://eample.com') + #/api/campuses/getCampusesByUser/ + def test_getCampusesByUser_lecturerToken(self): + connectUserToCampus = self.__class__.url_+'api/help/validation/confirm/'++__CONFIG__['TOKENS']['LECTURER']+'|post.jce.ac.il' + webbrowser.open('http://localhost:8080/api/help/validation/confirm/_QA_TOKEN_TEST_LECTURER|post.jce.ac.il') + r = requests.get(self.__class__.url_+'api/campuses/getCampusesByUser/'+__CONFIG__['TOKENS']['LECTURER']) + self.assertEquals(r.status_code, 200) if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/Testing/MessagesAPI_Tests.py b/Testing/MessagesAPI_Tests.py new file mode 100644 index 0000000..e7e1f01 --- /dev/null +++ b/Testing/MessagesAPI_Tests.py @@ -0,0 +1,191 @@ +__author__ = 'etye' +import unittest +import requests +import json +#import logging +import datetime + +from Testing.config import __CONFIG__ +class MessagesTestPlan(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/messages/create/ + POST OPTIONS + token user payload e msg + This call will create a new Message in the DB + ''' + def test_messageCreate_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/messages/create/_QA_TOKEN_TEST_STUDENT' + #params = {'seToken': 'seToken' } + data = { + 'groupId' : 123456789, + 'message' : 'Class is canceled', + 'isProject' : True + } + + #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_messageCreate_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/messages/create/_QA_TOKEN_TEST_LECTURER' + #params = {'seToken': 'seToken' } + data = { + 'groupId' : 123456789, + 'message' : 'Class is canceled', + 'isProject' : True + } + + #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_messageCreate_INVALIDTOKEN(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/messages/create/invlaidToken' + #params = {'seToken': 'seToken' } + data = { + 'groupId' : 123456789, + 'message' : 'Class is canceled', + 'isProject' : True + } + + #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("***********************************************") + + ''' + /api/messages/deleteMessage// + OPTIONS DELETE + token msgId user msg e + >This Call will delete a message by owner token + Route Parameters + - SeToken: token - msgId: 1234567890 + + Payload + - NONE + ''' + def test_deleteMessage_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + #create Message and get the id to call delete message API REST + r = requests.delete(self.__class__.url_+'api/messages/deleteMessage/_QA_TOKEN_TEST_STUDENT/ + HEAD OPTIONS GET + token user arr allMsgs projectMsgs m msgDic msgTime i + >This Call will return an array of all messages (sorted by date), + + Route Parameters + - SeToken: token + - groupId: 1234567890 + + Payload + - NONE + + ''' + def test_getAllUserMessages_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + #create Message and get the id to call delete message API REST + r = requests.get(self.__class__.url_+'api/messages/getAllUserMessages/_QA_TOKEN_TEST_LECTURER') + self.assertEquals(r.status_code, 200) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + + def test_getAllUserMessages_STUDENT(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + #create Message and get the id to call delete message API REST + r = requests.get(self.__class__.url_+'api/messages/getAllUserMessages/_QA_TOKEN_TEST_STUDENT') + self.assertEquals(r.status_code, 200) + print("***********************************************") + print(self._testMethodName+"Has finished Successfully") + print("***********************************************") + +''' +/api/messages/create/ +POST OPTIONS +token user payload e msg +This call will create a new Message in the DB +Route Parameters +- seToken: 'seToken' + +Payload +- JSON Object, Example: +{ +'groupId' : 123456789, +'message' : 'Class is canceled', +'isProject' : true +} +''' + diff --git a/Testing/MiscellaneousAPIMethod_Tests.py b/Testing/MiscellaneousAPIMethod_Tests.py new file mode 100644 index 0000000..b8ecda6 --- /dev/null +++ b/Testing/MiscellaneousAPIMethod_Tests.py @@ -0,0 +1 @@ +__author__ = 'etye' diff --git a/Testing/TasksAPI_Test.py b/Testing/TasksAPI_Test.py new file mode 100644 index 0000000..13eb6c1 --- /dev/null +++ b/Testing/TasksAPI_Test.py @@ -0,0 +1,396 @@ +__author__ = 'etye' +import unittest +import requests +import json +#import logging +import datetime + +from Testing.config import __CONFIG__ +class TaskTestPlan(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/tasks/create/ + POST OPTIONS + + + ''' + def test_tasks_create_LectureToken(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/tasks/create/_QA_TOKEN_TEST_LECTURER' + #params = {'seToken': 'seToken' } + + data = { + 'title':'task1', + 'courseId':1234567890, + 'description':'pls fddfsdfdsk', + 'dueDate':{'year':2010, + 'month':2, + 'day':4 + }, 'isPersonal':True, + 'components':[ + { + 'type' : 'should be type1', + 'label' : 'should be label1', + 'isMandatory' : True, + 'order' : 1 + }, + { + 'type' : 'should be type2', + 'label' : 'should be label2', + 'isMandatory' : True, + 'order' : 2 + }, + { + 'type' : 'should be type3', + 'label' : 'should be label3', + 'isMandatory' : False, + 'order' : 3 + } + ] + } + #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_tasks_create_Student_Token(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/tasks/create/_QA_TOKEN_TEST_STUDENT' + #params = {'seToken': 'seToken' } + + data = { + 'title':'task1', + 'courseId':1234567890, + 'description':'pls fddfsdfdsk', + 'dueDate':{'year':2010, + 'month':2, + 'day':4 + }, 'isPersonal':True, + 'components':[ + { + 'type' : 'should be type1', + 'label' : 'should be label1', + 'isMandatory' : True, + 'order' : 1 + }, + { + 'type' : 'should be type2', + 'label' : 'should be label2', + 'isMandatory' : True, + 'order' : 2 + }, + { + 'type' : 'should be type3', + 'label' : 'should be label3', + 'isMandatory' : False, + 'order' : 3 + } + ] + } + #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_tasks_create_Student_Token(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/tasks/create/INVALIDTOKEN' + #params = {'seToken': 'seToken' } + + data = { + 'title':'task1', + 'courseId':1234567890, + 'description':'pls fddfsdfdsk', + 'dueDate':{'year':2010, + 'month':2, + 'day':4 + }, 'isPersonal':True, + 'components':[ + { + 'type' : 'should be type1', + 'label' : 'should be label1', + 'isMandatory' : True, + 'order' : 1 + }, + { + 'type' : 'should be type2', + 'label' : 'should be label2', + 'isMandatory' : True, + 'order' : 2 + }, + { + 'type' : 'should be type3', + 'label' : 'should be label3', + 'isMandatory' : False, + 'order' : 3 + } + ] + } + #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("***********************************************") + + ''' + /api/tasks/submitGrade/// + ''' + + def test_submitGrade_Lecturer(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_ +'api/tasks/submitGrade/_QA_TOKEN_TEST_LECTURER/_QA__TEST_PROJECT/QA_TEST_PROJECT_NAME' + #params = {'seToken': 'seToken' } + data = { + 'title': 'task1', + 'courseId': 1234567890, + 'description': 'plsfddfsdfdsk', + 'dueDate': { + 'year': 2010, + 'month': 2, + 'day': 4 + }, + 'isPersonal': True, + 'components': [{ + 'type': 'shouldbetype1', + 'label': 'shouldbelabel1', + 'isMandatory': True, + 'order': 1 + }, + { + 'type': 'shouldbetype2', + 'label': 'shouldbelabel2', + 'isMandatory': True, + 'order': 2 + }, + { + 'type': 'shouldbetype3', + 'label': 'shouldbelabel3', + 'isMandatory': False, + 'order': 3 + }] + } + + + r = requests.post(url, data=json.dumps(data), headers=headers) + + 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, 'message: ' + r.json()['message']) + + def test_submitGrade_Student(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_ +'api/tasks/submitGrade/_QA_TOKEN_TEST_STUDENT/_QA__TEST_PROJECT/QA_TEST_PROJECT_NAME' + #params = {'seToken': 'seToken' } + data = { + 'title': 'task1', + 'courseId': 1234567890, + 'description': 'plsfddfsdfdsk', + 'dueDate': { + 'year': 2010, + 'month': 2, + 'day': 4 + }, + 'isPersonal': True, + 'components': [{ + 'type': 'shouldbetype1', + 'label': 'shouldbelabel1', + 'isMandatory': True, + 'order': 1 + }, + { + 'type': 'shouldbetype2', + 'label': 'shouldbelabel2', + 'isMandatory': True, + 'order': 2 + }, + { + 'type': 'shouldbetype3', + 'label': 'shouldbelabel3', + 'isMandatory': False, + 'order': 3 + }] + } + + + r = requests.post(url, data=json.dumps(data), headers=headers) + + print(r._content) + if(r.status_code!=201):print("_____"+self._testMethodName+" has Failed"+"_____" + r._content) + self.assertEquals(r.status_code, 404) + #self.assertEquals(r.status_code, 400, 'message: ' + r.json()['message']) + + def test_submitGrade_INVALIDTOKEN(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_ +'api/tasks/submitGrade/InvalidToken/invalidId/InvalidProject' + #params = {'seToken': 'seToken' } + data = { + 'title': 'task1', + 'courseId': 1234567890, + 'description': 'fun course', + 'dueDate': { + 'year': 2010, + 'month': 2, + 'day': 4 + }, + 'isPersonal': True, + 'components': [{ + 'type': 'shouldbetype1', + 'label': 'shouldbelabel1', + 'isMandatory': True, + 'order': 1 + }, + { + 'type': 'shouldbetype2', + 'label': 'shouldbelabel2', + 'isMandatory': True, + 'order': 2 + }, + { + 'type': 'shouldbetype3', + 'label': 'shouldbelabel3', + 'isMandatory': False, + 'order': 3 + }] + } + + + r = requests.post(url, data=json.dumps(data), headers=headers) + + print(r._content) + if(r.status_code!=201):print("_____"+self._testMethodName+" has Failed"+"_____" + r._content) + self.assertEquals(r.status_code, 404) + + ''' + /api/tasks/submitTask/// + ''' + def test_submitTask_LECTURER(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_ +'api/tasks/submitTask/_QA_TOKEN_TEST_LECTURER/_QA__TEST_PROJECT/QA_TEST_PROJECT_NAME' + #params = {'seToken': 'seToken' } + data = { + 'title': 'task1', + 'courseId': 1234567890, + 'description': 'plsfddfsdfdsk', + 'dueDate': { + 'year': 2010, + 'month': 2, + 'day': 4 + }, + 'isPersonal': True, + 'components': [{ + 'type': 'shouldbetype1', + 'label': 'shouldbelabel1', + 'isMandatory': True, + 'order': 1 + }, + { + 'type': 'shouldbetype2', + 'label': 'shouldbelabel2', + 'isMandatory': True, + 'order': 2 + }, + { + 'type': 'shouldbetype3', + 'label': 'shouldbelabel3', + 'isMandatory': False, + 'order': 3 + }] +} + + + r = requests.post(url, data=json.dumps(data), headers=headers) + + print(r._content) + if(r.status_code!=201):print("_____"+self._testMethodName+" has Failed"+"_____" + r._content) + self.assertEquals(r.status_code, 500) + + def test_submitTask_STUDENT(self): + print (datetime.datetime.now().time()) + print("***********************************************") + print(self._testMethodName+"Has begun") + print("***********************************************") + headers = {'content-type': 'application/json'} + url = self.__class__.url_ +'api/tasks/submitTask/_QA_TOKEN_TEST_STUDENT/_QA__TEST_PROJECT/QA_TEST_PROJECT_NAME' + #params = {'seToken': 'seToken' } + data = { + 'title': 'task1', + 'courseId': 1234567890, + 'description': 'plsfddfsdfdsk', + 'dueDate': { + 'year': 2010, + 'month': 2, + 'day': 4 + }, + 'isPersonal': True, + 'components': [{ + 'type': 'shouldbetype1', + 'label': 'shouldbelabel1', + 'isMandatory': True, + 'order': 1 + }, + { + 'type': 'shouldbetype2', + 'label': 'shouldbelabel2', + 'isMandatory': True, + 'order': 2 + }, + { + 'type': 'shouldbetype3', + 'label': 'shouldbelabel3', + 'isMandatory': False, + 'order': 3 + }] + } + + + r = requests.post(url, data=json.dumps(data), headers=headers) + + print(r._content) + if(r.status_code!=201):print("_____"+self._testMethodName+" has Failed"+"_____" + r._content) + self.assertEquals(r.status_code, 500) \ No newline at end of file diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index c76dea8..251ec99 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -271,7 +271,7 @@ class UserTestPlan(unittest.TestCase): } #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) + self.assertEquals(r.status_code, 404) def test_addUserToCampus_invalidToken(self): headers = {'content-type': 'application/json'} @@ -282,7 +282,7 @@ class UserTestPlan(unittest.TestCase): } #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) + self.assertEquals(r.status_code, 404) ''' def test_addUserToCourse_invalidToken(self): @@ -311,13 +311,13 @@ class UserTestPlan(unittest.TestCase): #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) + self.assertEquals(r.status_code, 204) 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) + self.assertEquals(r.status_code, 204) def test_getUserById_invalidToken(self): #url = self.__class__.url_+'api/users/getUserById/'+__CONFIG__['TOKENS']['STUDENT'] + '/'+__CONFIG__['ID']['STUDENT_ID'] diff --git a/Testing/ValidationAPI_Tests.py b/Testing/ValidationAPI_Tests.py new file mode 100644 index 0000000..b8ecda6 --- /dev/null +++ b/Testing/ValidationAPI_Tests.py @@ -0,0 +1 @@ +__author__ = 'etye' diff --git a/Testing/config.py b/Testing/config.py index 5373437..d82e9aa 100644 --- a/Testing/config.py +++ b/Testing/config.py @@ -2,7 +2,7 @@ __author__ = 'etye' __CONFIG__ = { - 'DEBUG': True, + 'DEBUG': False, 'PATHS': { 'DEBUG': 'http://localhost:8080/', 'PRODUCTION': 'http://se-hub.appspot.com/'