se-hub/Testing/CoursesAPI_test.py

109 lines
5.2 KiB
Python
Raw Normal View History

2015-06-21 20:19:44 +00:00
__author__ = 'etye'
import unittest
import requests
import json
2015-06-24 09:42:55 +00:00
import datetime
2015-06-21 20:19:44 +00:00
from Testing.config import __CONFIG__
2015-06-24 09:42:55 +00:00
class CoursesTestPlan(unittest.TestCase):
2015-06-21 20:19:44 +00:00
@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'
2015-06-24 09:42:55 +00:00
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' }
2015-06-21 20:19:44 +00:00
data = {
2015-06-24 09:42:55 +00:00
'courseName': 'QA COURSE',
2015-06-21 20:19:44 +00:00
'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}
}
2015-06-24 09:42:55 +00:00
#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',
2015-06-21 20:19:44 +00:00
'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}
}
2015-06-24 09:42:55 +00:00
'''
# 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)
2015-06-21 20:19:44 +00:00
2015-06-23 16:55:58 +00:00
2015-06-24 09:42:55 +00:00
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'
2015-06-23 16:55:58 +00:00
data = {
2015-06-24 09:42:55 +00:00
'courseName': 'QA COURSE',
2015-06-21 20:19:44 +00:00
'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}
}
2015-06-23 16:55:58 +00:00
r = requests.post(url, data=json.dumps(data), headers=headers)
self.assertEquals(r.status_code, 403)
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
2015-06-23 16:55:58 +00:00
2015-06-24 09:42:55 +00:00
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' }
2015-06-21 20:19:44 +00:00
data = {
2015-06-24 09:42:55 +00:00
'courseName': 'QA COURSE',
2015-06-21 20:19:44 +00:00
'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}
}
2015-06-24 09:42:55 +00:00
#r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload)
2015-06-23 16:55:58 +00:00
r = requests.post(url, data=json.dumps(data), headers=headers)
2015-06-24 09:42:55 +00:00
self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
2015-06-21 20:19:44 +00:00
2015-06-24 09:42:55 +00:00
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')
2015-06-21 20:19:44 +00:00
self.assertEquals(r.status_code, 200)
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
2015-06-21 20:19:44 +00:00
if __name__ == '__main__':
unittest.main()