From 9ea00145f90267180a60a29a98db574fe48ac66d Mon Sep 17 00:00:00 2001 From: etyemyer Date: Sun, 14 Jun 2015 22:49:10 +0300 Subject: [PATCH] UserApi_Test - test getuserbytoken with valid,invalid and empty string CampusesApi_test - with valid,invalid string --- Testing/CampusAPI_Test.py | 26 ++++++++++++++++++++++++++ Testing/UserAPI_Test.py | 37 +++++++++++++++++++++++++++++++++++++ Testing/__init__.py | 1 + Testing/config.py | 14 ++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 Testing/CampusAPI_Test.py create mode 100644 Testing/UserAPI_Test.py create mode 100644 Testing/__init__.py create mode 100644 Testing/config.py diff --git a/Testing/CampusAPI_Test.py b/Testing/CampusAPI_Test.py new file mode 100644 index 0000000..6f0c6e4 --- /dev/null +++ b/Testing/CampusAPI_Test.py @@ -0,0 +1,26 @@ +__author__ = 'etye' +import unittest +import requests +from Testing.config import __CONFIG__ +class UserTestPlan(unittest.TestCase): + 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_Campuses_invalid(self): + r = requests.get(self.__class__.url_+'api/Campuses/invalidtoken') + self.assertEquals(r.status_code, 403) + def test_Campuses_valid(self): + r = requests.get(self.__class__.url_+'api/Campuses/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 200) + self.assertEquals(r.json()['username'], 'qa_student') + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/Testing/UserAPI_Test.py b/Testing/UserAPI_Test.py new file mode 100644 index 0000000..67b9cf6 --- /dev/null +++ b/Testing/UserAPI_Test.py @@ -0,0 +1,37 @@ +__author__ = 'etye' +import unittest +import requests +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): + r = requests.get(self.__class__.url_+'api/getUserByToken/invalidtoken') + self.assertEquals(r.status_code, 403) + + + def test_getUserByToken_valid(self): + r = requests.get(self.__class__.url_+'api/getUserByToken/'+__CONFIG__['TOKENS']['STUDENT']) + self.assertEquals(r.status_code, 200) + self.assertEquals(r.json()['username'], 'qa_student') + + + def test_getUserByToken_empty(self): + r = requests.get(self.__class__.url_+'api/getUserByToken/') + self.assertEquals(r.status_code, 400) + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/Testing/__init__.py b/Testing/__init__.py new file mode 100644 index 0000000..b8ecda6 --- /dev/null +++ b/Testing/__init__.py @@ -0,0 +1 @@ +__author__ = 'etye' diff --git a/Testing/config.py b/Testing/config.py new file mode 100644 index 0000000..9e6f48a --- /dev/null +++ b/Testing/config.py @@ -0,0 +1,14 @@ +__author__ = 'etye' + + +__CONFIG__ = { + 'DEBUG': True, + 'PATHS': { + 'DEBUG': 'http://localhost:8080/', + 'PRODUCTION': 'http://se-hub.appspot.com/' + }, + 'TOKENS':{ + 'STUDENT': '_QA_TOKEN_TEST_STUDENT', + 'LECTURER': '_QA_TOKEN_TEST_LECTURER' + } +} \ No newline at end of file