Courses API changes added

This commit is contained in:
etyemyer 2015-06-29 17:45:02 +03:00
parent ad0451e721
commit d0d6ed3851

View file

@ -2,6 +2,7 @@ __author__ = 'etye'
import unittest import unittest
import requests import requests
import json import json
import datetime
from Testing.config import __CONFIG__ from Testing.config import __CONFIG__
class CoursesTestPlan(unittest.TestCase): class CoursesTestPlan(unittest.TestCase):
@classmethod @classmethod
@ -17,19 +18,22 @@ class CoursesTestPlan(unittest.TestCase):
print 'Initialized' print 'Initialized'
def test_coursesCreate_Lecturer(self): def test_coursesCreate_Lecturer(self):
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
url = 'http://se-hub.appspot.com/api/courses/create/_QA_TOKEN_TEST_LECTURER' url = self.__class__.url_ +'api/courses/create/_QA_TOKEN_TEST_LECTURER'
params = {'seToken': 'seToken' } #params = {'seToken': 'seToken' }
data = { data = {
'courseName': 'QA COURSE', 'courseName': 'Advance Math',
'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', 'campusName': 'JCE',
'projects': '@gay.lord.ultima.multi.omega',
'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, '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(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 = { payload = {
'courseName': 'QA COURSE', '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(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) #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): def test_coursesCreate_InvalidToken(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/courses/create/invalidToken' url = self.__class__.url_+'api/courses/create/invalidToken'
data = { data = {
@ -53,24 +64,20 @@ class CoursesTestPlan(unittest.TestCase):
'startDate': {'year': 2015, 'month' : 4, 'day' : 3}, 'startDate': {'year': 2015, 'month' : 4, 'day' : 3},
'endDate': {'year': 2016,'month' : 6,'day' : 6} 'endDate': {'year': 2016,'month' : 6,'day' : 6}
} }
params = {'seToken': 'seToken' } 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) self.assertEquals(r.status_code, 403)
''' print("***********************************************")
payload = {'courseName': 'Advance Math', 'campusName': 'JCE', 'startDate':'2015-14-3','endDate': '2015-29-6','taskFlag': 'False'} print(self._testMethodName+"Has finished Successfully")
payload = { print("***********************************************")
'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): def test_coursesCreate_Student(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/courses/create/_QA_TOKEN_TEST_STUDENT' url = self.__class__.url_+'api/courses/create/_QA_TOKEN_TEST_STUDENT'
params = {'seToken': 'seToken' } #params = {'seToken': 'seToken' }
data = { data = {
'courseName': 'QA COURSE', 'courseName': 'QA COURSE',
'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', '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(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']) self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getCourseByCampusName(self): 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) self.assertEquals(r.status_code, 200)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
#/api/courses/createMessage/<string:token>
'''
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__': if __name__ == '__main__':
unittest.main() unittest.main()