Merge pull request #94 from sagidayan/QA

Qa
This commit is contained in:
Sagi Dayan 2015-06-29 20:21:05 +03:00
commit 5e39cd1bb8
5 changed files with 520 additions and 63 deletions

View file

@ -21,13 +21,13 @@ class UserTestPlan(unittest.TestCase):
#url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER"
url=self.__class__.url_+'api/campuses/create/'+__CONFIG__['TOKENS']['LECTURER'] url=self.__class__.url_+'api/campuses/create/'+__CONFIG__['TOKENS']['LECTURER']
data = { data = {
'title': 'Campus name', 'title': 'QA Campus',
'email_ending': '@campus.ac.com', 'email_ending': '@campus.ac.com',
'avatar_url': 'http://location.domain.com/image.jpg' 'avatar_url': 'http://location.domain.com/image.jpg'
} }
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers) 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): def test_campusCreate_student(self):
#url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" #url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER"

View file

@ -2,9 +2,9 @@ __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 UserTestPlan(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
debug = __CONFIG__['DEBUG'] debug = __CONFIG__['DEBUG']
@ -17,81 +17,159 @@ class UserTestPlan(unittest.TestCase):
if 200 <= request.status_code <= 299: if 200 <= request.status_code <= 299:
print 'Initialized' print 'Initialized'
def test_courseCreate_lecturer(self): def test_coursesCreate_Lecturer(self):
#url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" print (datetime.datetime.now().time())
url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'] 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 = { 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', 'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg',
'projects': '@gay.lord.ultima.multi.omega', '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' : 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) 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']
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, 403)
def test_courseCreate_student(self): def test_coursesCreate_InvalidToken(self):
#url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" print (datetime.datetime.now().time())
url=self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'] print("***********************************************")
data = { print(self._testMethodName+"Has begun")
'courseName': 'matan', print("***********************************************")
'campusName': 'https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg', headers = {'content-type': 'application/json'}
'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' url = self.__class__.url_+'api/courses/create/invalidToken'
data = { data = {
'courseName': 'matan', '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',
'projects': '@gay.lord.ultima.multi.omega', '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' : 6,'day' : 6}
} }
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers) r = requests.post(url, data=json.dumps(data), headers=headers)
self.assertEquals(r.status_code, 403) self.assertEquals(r.status_code, 403)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_courseCreate_hebrewToken(self): def test_coursesCreate_Student(self):
#url = "http://localhost:8080/api/courses/create/_QA_TOKEN_TEST_LECTURER" print (datetime.datetime.now().time())
url=self.__class__.url_+'api/courses/create/????' 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 = { data = {
'courseName': 'matan', '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',
'projects': '@gay.lord.ultima.multi.omega', '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' : 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/<string:name> #r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload)
def test_getCourseByCampusName_EXSISTING_CAMPUS(self): r = requests.post(url, data=json.dumps(data), headers=headers)
url=self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['CAMPUS_NAME']['JCE'] self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message'])
r = requests.get(url) 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')
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()

112
Testing/ProjectAPI_Test.py Normal file
View file

@ -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/<string:token>
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/<string:token>/<string:projectid>
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()

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 UserTestPlan(unittest.TestCase): class UserTestPlan(unittest.TestCase):
@ -18,71 +19,167 @@ class UserTestPlan(unittest.TestCase):
print 'Initialized' print 'Initialized'
def test_getUserByToken_invalid(self): 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') r = requests.get(self.__class__.url_+'api/users/getUserByToken/invalidtoken')
self.assertEquals(r.status_code, 204) self.assertEquals(r.status_code, 204)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getUserByToken_valid(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertEquals(r.json()['username'], 'qa_student') self.assertEquals(r.json()['username'], 'qa_student')
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getUserByToken_empty(self): def test_getUserByToken_empty(self):
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
r = requests.get(self.__class__.url_+'api/users/getUserByToken/') r = requests.get(self.__class__.url_+'api/users/getUserByToken/')
self.assertEquals(r.status_code, 204) self.assertEquals(r.status_code, 204)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isStudent_Student(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertFalse(r.json()['isLecturer']) self.assertFalse(r.json()['isLecturer'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isLecturer_Lecturer(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertTrue(r.json()['isLecturer']) self.assertTrue(r.json()['isLecturer'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isFirstLogin_Student(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertTrue(r.json()['isFirstLogin']) self.assertTrue(r.json()['isFirstLogin'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isFirstLogin_Lecturer(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertTrue(r.json()['isFirstLogin']) self.assertTrue(r.json()['isFirstLogin'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isClassIdListEmpty_Student(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
self.assertEquals(r.status_code, 200) 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): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
self.assertEquals(r.status_code, 200) 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): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertFalse(r.json()['isLecturer']) self.assertFalse(r.json()['isLecturer'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_Lecturer_isLecturer(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertTrue(r.json()['isLecturer']) self.assertTrue(r.json()['isLecturer'])
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isClassIdListEmpty_Lecturer(self): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
self.assertEquals(r.status_code, 200) 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): 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']) r = requests.get(self.__class__.url_+'api/users/getUserByToken/'+__CONFIG__['TOKENS']['LECTURER'])
self.assertEquals(r.status_code, 200) self.assertEquals(r.status_code, 200)
self.assertEquals(r.json()['campuses_id_list'],[]) print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
#/api/users/updateUser/<string:token> #/api/users/updateUser/<string:token>
def test_updateUser_lecturer(self): 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'] url=self.__class__.url_+'api/users/updateUser/'+__CONFIG__['TOKENS']['LECTURER']
data = { data = {
'name': 'new name', 'name': 'new name',
@ -90,11 +187,18 @@ class UserTestPlan(unittest.TestCase):
'campusName': 'JCE' 'campusName': 'JCE'
} }
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} 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.status_code, 200)
self.assertEquals(r._content, '{"message": "User updated"}') self.assertEquals(r._content, '{"message": "User updated"}')
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_updateUser_student(self): 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'] url=self.__class__.url_+'api/users/updateUser/'+__CONFIG__['TOKENS']['STUDENT']
data = { data = {
'name': 'new name', 'name': 'new name',
@ -102,11 +206,18 @@ class UserTestPlan(unittest.TestCase):
'campusName': 'JCE' 'campusName': 'JCE'
} }
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} 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.status_code, 200)
self.assertEquals(r._content, '{"message": "User updated"}') self.assertEquals(r._content, '{"message": "User updated"}')
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_updateUser_INVALID_TOKEN(self): 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' url=self.__class__.url_+'api/users/updateUser/invalidToken'
data = { data = {
'name': 'new name', 'name': 'new name',
@ -114,11 +225,18 @@ class UserTestPlan(unittest.TestCase):
'campusName': 'JCE' 'campusName': 'JCE'
} }
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} 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.status_code, 400)
self.assertEquals(r._content, '{"message": "Not a user!"}') self.assertEquals(r._content, '{"message": "Not a user!"}')
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_updateUser_HEBREW_TOKEN(self): 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/?????' url=self.__class__.url_+'api/users/updateUser/?????'
data = { data = {
'name': 'new name', 'name': 'new name',
@ -126,8 +244,153 @@ class UserTestPlan(unittest.TestCase):
'campusName': 'JCE' 'campusName': 'JCE'
} }
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} 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) self.assertEquals(r.status_code, 404)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
#/api/users/addUserToCampus/<string:token>
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/<string:token>/<string:campusID
def test_getUserByCampus_student(self):
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
#url=self.__class__.url_+'api/users/getUsersByCampus/'+__CONFIG__['TOKENS']['STUDENT']+'/6736157987569664'#campus id
url='http://localhost:8080/api/users/getUsersByCampus/_QA_TOKEN_TEST_STUDENT/6736157987569664'
r = requests.get(url)
self.assertEquals(r.status_code, 200)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getUserByCampus_lecturer(self):
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
#url=self.__class__.url_+'api/users/getUsersByCampus/'+__CONFIG__['TOKENS']['LECTURER']+'/6736157987569664'#campus id
url = 'http://localhost:8080/api/users/getUsersByCampus/_QA_TOKEN_TEST_STUDENT/6736157987569664'
r = requests.get(url)
self.assertEquals(r.status_code, 200)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getUserByCampus_student_invalidCampusId(self):
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
url=self.__class__.url_+'api/users/getUsersByCampus/'+__CONFIG__['TOKENS']['STUDENT']+'/invalidId'#campus id
r = requests.get(url)
self.assertEquals(r.status_code, 400)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getUserByCampus_lecturer_invalidCampusId(self):
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
url=self.__class__.url_+'api/users/getUsersByCampus/'+__CONFIG__['TOKENS']['LECTURER']+'/invalidId'#campus id
r = requests.get(url)
self.assertEquals(r.status_code, 400)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
#http://localhost:8080/api/users/getUsersByCampus/_QA_TOKEN_TEST_STUDENT/6736157987569664
def test_getUserByCampus_invalidToken_validCampusId(self):
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
#url=self.__class__.url_+'api/users/getUsersByCampus/invalidToken/6736157987569664'#campus id
url='http://localhost:8080/api/users/getUsersByCampus/invalidToken/6736157987569664'
r = requests.get(url)
self.assertEquals(r.status_code, 400)
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() suite = unittest.TestLoader().loadTestsFromTestCase(UserTestPlan)
unittest.TextTestRunner(verbosity=2).run(suite)
#unittest.main()

View file

@ -13,5 +13,9 @@ __CONFIG__ = {
}, },
'CAMPUS_NAME':{ 'CAMPUS_NAME':{
'JCE':'JCE' 'JCE':'JCE'
},
'ID':{
'STUDENT_ID':4818609708728320,
'LECTURER_ID':6225984592281600
} }
} }