From faad6dae001a4acea4fbbb6ae87da8296df073de Mon Sep 17 00:00:00 2001 From: etyemyer Date: Wed, 17 Jun 2015 23:18:13 +0300 Subject: [PATCH] Added Tests CoursesApi - course create UserApi - Fixed tests --- Testing/CoursesAPI_Test.py | 69 +++++++++++++++++++++++++++++++++----- Testing/UserAPI_Test.py | 2 +- Testing/config.py | 2 +- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/Testing/CoursesAPI_Test.py b/Testing/CoursesAPI_Test.py index e4734ad..f4c37d5 100644 --- a/Testing/CoursesAPI_Test.py +++ b/Testing/CoursesAPI_Test.py @@ -1,6 +1,7 @@ __author__ = 'etye' import unittest import requests +import json from Testing.config import __CONFIG__ class CoursesTestPlan(unittest.TestCase): @classmethod @@ -16,19 +17,71 @@ class CoursesTestPlan(unittest.TestCase): print 'Initialized' def test_coursesCreate_Lecturer(self): - payload = {'courseName': 'Advance Math', 'campusName': 'JCE', 'startDate':'2015-14-3','endDate': '2015-29-6','taskFlag': 'False'} - r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER'],data=payload) - self.assertEquals(r.status_code, 201) + headers = {'content-type': 'application/json'} + url = 'http://se-hub.appspot.com/api/courses/create/_QA_TOKEN_TEST_LECTURER' + params = {'seToken': 'seToken' } + data = { + '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']['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) + #self.assertEquals(r.status_code, 201) def test_coursesCreate_InvalidToken(self): + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/create/invalidToken' + data = { + '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} + } + params = {'seToken': 'seToken' } + r = requests.post(url, params=params, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 403) + ''' payload = {'courseName': 'Advance Math', 'campusName': 'JCE', 'startDate':'2015-14-3','endDate': '2015-29-6','taskFlag': 'False'} + 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/invalidToken',data=payload) - self.assertEquals(r.status_code, 403) - + ''' def test_coursesCreate_Student(self): - payload = {'courseName': 'Advance Math', 'campusName': 'JCE', 'startDate':'2015-14-3','endDate': '2015-29-6','taskFlag': 'False'} - r = requests.post(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) - self.assertEquals(r.status_code, 403) + headers = {'content-type': 'application/json'} + url = self.__class__.url_+'api/courses/create/_QA_TOKEN_TEST_STUDENT' + params = {'seToken': 'seToken' } + data = { + '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']['STUDENT'],data=payload) + r = requests.post(url, params=params, data=json.dumps(data), headers=headers) + self.assertEquals(r.status_code, 403, 'message: ' + r.json()['message']) def test_getCourseByCampusName(self): r = requests.get(self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['TOKENS']['CAMPUS_NAME']) diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index 934a2a6..6594707 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -81,7 +81,7 @@ class UserTestPlan(unittest.TestCase): self.assertEquals(r.json()['campuses_id_list'],[]) def test_userUpdate_Student(self): - payload = {'name': 'New Name', 'isLecturer': 'false'} + payload = {'name': 'New Name', 'isLecturer': False} r = requests.post(self.__class__.url_+'api/users/userUpdate/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) self.assertEquals(r.status_code, 200) #data = {} diff --git a/Testing/config.py b/Testing/config.py index 7897b71..1fb14cd 100644 --- a/Testing/config.py +++ b/Testing/config.py @@ -2,7 +2,7 @@ __author__ = 'etye' __CONFIG__ = { - 'DEBUG': True, + 'DEBUG': False, 'PATHS': { 'DEBUG': 'http://localhost:8080/', 'PRODUCTION': 'http://se-hub.appspot.com/'