From a943d370d122dea79ade28a246bc22b097ec3836 Mon Sep 17 00:00:00 2001 From: etyemyer Date: Mon, 15 Jun 2015 22:21:07 +0300 Subject: [PATCH 1/3] UserApi_Test - test getuserbytoken with valid,invalid and empty string CampusesApi_test - with valid,invalid string --- Testing/CampusAPI_Test.py | 2 +- Testing/CoursesAPI_Test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Testing/CoursesAPI_Test.py diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py index 09be45d..ee40022 100644 --- a/Testing/CampusAPI_Test.py +++ b/Testing/CampusAPI_Test.py @@ -2,7 +2,7 @@ __author__ = 'etye' import unittest import requests from Testing.config import __CONFIG__ -class UserTestPlan(unittest.TestCase): +class CampusTestPlan(unittest.TestCase): @classmethod def setUpClass(cls): debug = __CONFIG__['DEBUG'] diff --git a/Testing/CoursesAPI_Test.py b/Testing/CoursesAPI_Test.py new file mode 100644 index 0000000..1625cde --- /dev/null +++ b/Testing/CoursesAPI_Test.py @@ -0,0 +1,32 @@ +__author__ = 'etye' +import unittest +import requests +from Testing.config import __CONFIG__ +class CoursesTestPlan(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_coursesCreate_Lecturer(self): + r = requests.get(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER']) + self.assertEquals(r.status_code, 201) + + def test_coursesCreate_InvalidToken(self): + r = requests.get(self.__class__.url_+'api/courses/create/invalidToken') + self.assertEquals(r.status_code, 403) + + def test_coursesCreate_Student(self): + r = requests.get(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 403) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 081806037818f3a6f173fdc310538eddd951a9c5 Mon Sep 17 00:00:00 2001 From: etyemyer Date: Tue, 16 Jun 2015 19:17:49 +0300 Subject: [PATCH 2/3] UserApi_Test - test getuserbytoken with valid,invalid and empty string CampusesApi_test - with valid,invalid string --- Testing/CampusAPI_Test.py | 40 +++++++++++++++++++++++++------------- Testing/CoursesAPI_Test.py | 12 +++++++++--- Testing/UserAPI_Test.py | 12 ++++++++++++ Testing/config.py | 3 ++- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py index ee40022..aeeb525 100644 --- a/Testing/CampusAPI_Test.py +++ b/Testing/CampusAPI_Test.py @@ -5,27 +5,39 @@ from Testing.config import __CONFIG__ class CampusTestPlan(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' + 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_campusesGet_invalidToken(self): - r = requests.get(self.__class__.url_+'api/campuses/getAll/invalidtoken') - self.assertEquals(r.status_code, 403) + r = requests.get(self.__class__.url_+'api/campuses/getAll/invalidtoken') + self.assertEquals(r.status_code, 403) def test_campusesGet_validToken_testArraySize(self): - r = requests.get(self.__class__.url_+'api/campuses/getAll/'+__CONFIG__['TOKENS']['STUDENT']) - self.assertEquals(r.status_code, 200) - self.assertTrue(len(r.json())>= 1) + r = requests.get(self.__class__.url_+'api/campuses/getAll/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 200) + self.assertTrue(len(r.json())>= 1) + def test_campusCreate_Lecturer(self): + payload = {'title': 'Campus name', 'email_ending': '@campus.ac.com','avatar_url': 'http://location.domain.com/image.jpg'} + r = requests.post(self.__class__.url_+'api/campuses/create/'+__CONFIG__['TOKENS']['LECTURER'],data=payload) + self.assertEquals(r.status_code, 201) + def test_campusCreate_Student(self): + payload = {'title': 'Campus name', 'email_ending': '@campus.ac.com','avatar_url': 'http://location.domain.com/image.jpg'} + r = requests.post(self.__class__.url_+'api/campuses/create/'+__CONFIG__['TOKENS']['STUDENT'],data=payload) + self.assertEquals(r.status_code, 403) + def test_campusCreate_InvalidToken(self): + payload = {'title': 'Campus name', 'email_ending': '@campus.ac.com','avatar_url': 'http://location.domain.com/image.jpg'} + r = requests.post(self.__class__.url_+'api/campuses/create/invalidToken',data=payload) + self.assertEquals(r.status_code, 403) if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/Testing/CoursesAPI_Test.py b/Testing/CoursesAPI_Test.py index 1625cde..e4734ad 100644 --- a/Testing/CoursesAPI_Test.py +++ b/Testing/CoursesAPI_Test.py @@ -16,17 +16,23 @@ class CoursesTestPlan(unittest.TestCase): print 'Initialized' def test_coursesCreate_Lecturer(self): - r = requests.get(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['LECTURER']) + 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) def test_coursesCreate_InvalidToken(self): - r = requests.get(self.__class__.url_+'api/courses/create/invalidToken') + 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/invalidToken',data=payload) self.assertEquals(r.status_code, 403) def test_coursesCreate_Student(self): - r = requests.get(self.__class__.url_+'api/courses/create/'+__CONFIG__['TOKENS']['STUDENT']) + 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) + def test_getCourseByCampusName(self): + r = requests.get(self.__class__.url_+'api/courses/getCourseByCampusName/'+__CONFIG__['TOKENS']['CAMPUS_NAME']) + self.assertEquals(r.status_code, 200) if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py index 1af62c3..934a2a6 100644 --- a/Testing/UserAPI_Test.py +++ b/Testing/UserAPI_Test.py @@ -1,6 +1,7 @@ __author__ = 'etye' import unittest import requests +import json from Testing.config import __CONFIG__ class UserTestPlan(unittest.TestCase): @@ -79,6 +80,17 @@ class UserTestPlan(unittest.TestCase): self.assertEquals(r.status_code, 200) self.assertEquals(r.json()['campuses_id_list'],[]) + def test_userUpdate_Student(self): + 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 = {} + #data['name'] = 'New Name' + #data['isLecturer'] = 'false' + #json_data = json.dumps(data) + #r = requests.post(self.__class__.url_+'api/users/userUpdate/'+__CONFIG__['TOKENS']['STUDENT'],json_data) + #self.assertEquals(r.status_code, 200) + #self.assertEquals(r.json()['message'],'User updated') if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/Testing/config.py b/Testing/config.py index 9e6f48a..7897b71 100644 --- a/Testing/config.py +++ b/Testing/config.py @@ -9,6 +9,7 @@ __CONFIG__ = { }, 'TOKENS':{ 'STUDENT': '_QA_TOKEN_TEST_STUDENT', - 'LECTURER': '_QA_TOKEN_TEST_LECTURER' + 'LECTURER': '_QA_TOKEN_TEST_LECTURER', + 'CAMPUS_NAME':'JCE' } } \ No newline at end of file From faad6dae001a4acea4fbbb6ae87da8296df073de Mon Sep 17 00:00:00 2001 From: etyemyer Date: Wed, 17 Jun 2015 23:18:13 +0300 Subject: [PATCH 3/3] 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/'