Updated tests and added deleted tests

This commit is contained in:
etyemyer 2015-06-24 12:42:55 +03:00
parent 89c16b8ecc
commit 1f74a88db1
4 changed files with 301 additions and 55 deletions

View file

@ -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"

View file

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

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 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):
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/<string:token>
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()
suite = unittest.TestLoader().loadTestsFromTestCase(UserTestPlan)
unittest.TextTestRunner(verbosity=2).run(suite)
#unittest.main()