se-hub/Testing/UserAPI_Test.py

255 lines
13 KiB
Python
Raw Normal View History

__author__ = 'etye'
import unittest
import requests
2015-06-21 20:19:44 +00:00
import json
2015-06-24 09:42:55 +00:00
import datetime
from Testing.config import __CONFIG__
class UserTestPlan(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'
def test_getUserByToken_invalid(self):
2015-06-24 09:42:55 +00:00
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)
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getUserByToken_valid(self):
2015-06-24 09:42:55 +00:00
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')
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_getUserByToken_empty(self):
2015-06-24 09:42:55 +00:00
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):
2015-06-24 09:42:55 +00:00
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'])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isLecturer_Lecturer(self):
2015-06-24 09:42:55 +00:00
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'])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isFirstLogin_Student(self):
2015-06-24 09:42:55 +00:00
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'])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isFirstLogin_Lecturer(self):
2015-06-24 09:42:55 +00:00
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'])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isClassIdListEmpty_Student(self):
2015-06-24 09:42:55 +00:00
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)
2015-06-29 14:14:36 +00:00
#self.assertEquals(r.json()['classes_id_list'],[])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_campuses_id_list_Student(self):
2015-06-24 09:42:55 +00:00
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)
2015-06-29 14:14:36 +00:00
#self.assertEquals(r.json()['campuses_id_list'],[])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_Student_isLecturer(self):
2015-06-24 09:42:55 +00:00
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'])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_Lecturer_isLecturer(self):
2015-06-24 09:42:55 +00:00
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)
2015-06-16 06:37:25 +00:00
self.assertTrue(r.json()['isLecturer'])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_isClassIdListEmpty_Lecturer(self):
2015-06-24 09:42:55 +00:00
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)
2015-06-29 14:14:36 +00:00
#self.assertEquals(r.json()['classes_id_list'],[])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
def test_campuses_id_list_Lecturer(self):
2015-06-24 09:42:55 +00:00
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'],[])
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
2015-06-21 20:19:44 +00:00
#/api/users/updateUser/<string:token>
def test_updateUser_lecturer(self):
2015-06-24 09:42:55 +00:00
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
2015-06-21 20:19:44 +00:00
url=self.__class__.url_+'api/users/updateUser/'+__CONFIG__['TOKENS']['LECTURER']
data = {
'name': 'new name',
'isLecturer': True,
'campusName': 'JCE'
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
2015-06-29 14:14:36 +00:00
r = requests.put(url, data=json.dumps(data), headers=headers)
2015-06-21 20:19:44 +00:00
self.assertEquals(r.status_code, 200)
self.assertEquals(r._content, '{"message": "User updated"}')
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
2015-06-21 20:19:44 +00:00
def test_updateUser_student(self):
2015-06-24 09:42:55 +00:00
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
2015-06-21 20:19:44 +00:00
url=self.__class__.url_+'api/users/updateUser/'+__CONFIG__['TOKENS']['STUDENT']
data = {
'name': 'new name',
'isLecturer': True,
'campusName': 'JCE'
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
2015-06-29 14:14:36 +00:00
r = requests.put(url, data=json.dumps(data), headers=headers)
2015-06-21 20:19:44 +00:00
self.assertEquals(r.status_code, 200)
self.assertEquals(r._content, '{"message": "User updated"}')
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
2015-06-21 20:19:44 +00:00
def test_updateUser_INVALID_TOKEN(self):
2015-06-24 09:42:55 +00:00
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
2015-06-21 20:19:44 +00:00
url=self.__class__.url_+'api/users/updateUser/invalidToken'
data = {
'name': 'new name',
'isLecturer': True,
'campusName': 'JCE'
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
2015-06-29 14:14:36 +00:00
r = requests.put(url, data=json.dumps(data), headers=headers)
2015-06-21 20:19:44 +00:00
self.assertEquals(r.status_code, 400)
self.assertEquals(r._content, '{"message": "Not a user!"}')
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
2015-06-21 20:19:44 +00:00
def test_updateUser_HEBREW_TOKEN(self):
2015-06-24 09:42:55 +00:00
print (datetime.datetime.now().time())
print("***********************************************")
print(self._testMethodName+"Has begun")
print("***********************************************")
2015-06-21 20:19:44 +00:00
url=self.__class__.url_+'api/users/updateUser/?????'
data = {
'name': 'new name',
'isLecturer': True,
'campusName': 'JCE'
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
2015-06-29 14:14:36 +00:00
r = requests.put(url, data=json.dumps(data), headers=headers)
2015-06-21 20:19:44 +00:00
self.assertEquals(r.status_code, 404)
2015-06-24 09:42:55 +00:00
print("***********************************************")
print(self._testMethodName+"Has finished Successfully")
print("***********************************************")
if __name__ == '__main__':
2015-06-24 09:42:55 +00:00
suite = unittest.TestLoader().loadTestsFromTestCase(UserTestPlan)
unittest.TextTestRunner(verbosity=2).run(suite)
#unittest.main()