mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 16:31:13 +00:00
clean up test code
This commit is contained in:
@@ -1,24 +1,5 @@
|
||||
import os
|
||||
if os.getenv('CI_BASE_URL'):
|
||||
BASE_URL = os.getenv('CI_BASE_URL')
|
||||
else:
|
||||
BASE_URL = u'http://127.0.0.1:8000'
|
||||
|
||||
if os.getenv('CI_USERNAME'):
|
||||
USERNAME = os.getenv('CI_USERNAME')
|
||||
else:
|
||||
USERNAME = u'test@test.com'
|
||||
|
||||
if os.getenv('CI_PASSWORD'):
|
||||
PASSWORD = os.getenv('CI_PASSWORD')
|
||||
else:
|
||||
PASSWORD = u'testtest'
|
||||
|
||||
def getBaseUrl():
|
||||
return BASE_URL
|
||||
|
||||
def getUserName():
|
||||
return USERNAME
|
||||
|
||||
def getPassword():
|
||||
return PASSWORD
|
||||
BASE_URL = os.getenv('CI_BASE_URL', u'http://127.0.0.1:8000')
|
||||
USERNAME = os.getenv('CI_USERNAME', u'test@test.com')
|
||||
PASSWORD = os.getenv('CI_PASSWORD', u'testtest')
|
||||
|
@@ -11,18 +11,15 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from common import common
|
||||
from common.common import BASE_URL, USERNAME, PASSWORD
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
|
||||
LOGIN_URL = common.getBaseUrl() + u'/accounts/login/'
|
||||
HOME_URL = common.getBaseUrl() + u'/home/my/'
|
||||
LOGOUT_URL = common.getBaseUrl() + u'/accounts/logout/'
|
||||
LOGIN_URL = BASE_URL + u'/accounts/login/'
|
||||
HOME_URL = BASE_URL + u'/home/my/'
|
||||
LOGOUT_URL = BASE_URL + u'/accounts/logout/'
|
||||
|
||||
USERNAME = common.getUserName()
|
||||
PASSWORD = common.getPassword()
|
||||
|
||||
def getLoggedInstance():
|
||||
def get_logged_instance():
|
||||
browser = webdriver.PhantomJS()
|
||||
browser.get(LOGIN_URL)
|
||||
username_input = browser.find_element_by_name('username')
|
||||
|
@@ -1,22 +1,22 @@
|
||||
import integration as common
|
||||
from integration import HOME_URL, LOGOUT_URL, get_logged_instance
|
||||
import unittest
|
||||
|
||||
class LoginTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.browser = common.getLoggedInstance()
|
||||
self.browser = get_logged_instance()
|
||||
self.assertIsNotNone(self.browser)
|
||||
self.addCleanup(self.browser.quit)
|
||||
|
||||
def testLogin(self):
|
||||
self.assertRegexpMatches(self.browser.current_url, common.HOME_URL)
|
||||
self.assertRegexpMatches(self.browser.current_url, HOME_URL)
|
||||
|
||||
def testLogout(self):
|
||||
myinfo_bar = self.browser.find_element_by_css_selector('#my-info')
|
||||
logout_input = self.browser.find_element_by_css_selector('a#logout')
|
||||
myinfo_bar.click()
|
||||
logout_input.click()
|
||||
self.assertRegexpMatches(self.browser.current_url, common.LOGOUT_URL)
|
||||
self.assertRegexpMatches(self.browser.current_url, LOGOUT_URL)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
@@ -11,18 +11,16 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from common import common
|
||||
from common.common import BASE_URL, USERNAME, PASSWORD
|
||||
import requests, re
|
||||
|
||||
PING_URL = common.getBaseUrl() + u'/api2/ping/'
|
||||
TOKEN_URL = common.getBaseUrl() + u'/api2/auth-token/'
|
||||
AUTH_PING_URL = common.getBaseUrl() + u'/api2/auth/ping/'
|
||||
PING_URL = BASE_URL + u'/api2/ping/'
|
||||
TOKEN_URL = BASE_URL + u'/api2/auth-token/'
|
||||
AUTH_PING_URL = BASE_URL + u'/api2/auth/ping/'
|
||||
|
||||
USERNAME = common.getUserName()
|
||||
PASSWORD = common.getPassword()
|
||||
META_AUTH = {'username': USERNAME, 'password': PASSWORD}
|
||||
|
||||
def getAuthToken():
|
||||
def get_auth_token():
|
||||
res = requests.post(TOKEN_URL, data=META_AUTH)
|
||||
if (res.status_code != 200):
|
||||
return None
|
||||
@@ -31,8 +29,8 @@ def getAuthToken():
|
||||
return None
|
||||
return token
|
||||
|
||||
def getAuthedInstance():
|
||||
token = getAuthToken()
|
||||
def get_authed_instance():
|
||||
token = get_auth_token()
|
||||
if (token == None):
|
||||
return None
|
||||
s = requests.Session()
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import integration_api as common
|
||||
from integration_api import AUTH_PING_URL, get_authed_instance
|
||||
import unittest
|
||||
|
||||
class AuthPingApiTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.requests = common.getAuthedInstance()
|
||||
self.requests = get_authed_instance()
|
||||
self.assertIsNotNone(self.requests)
|
||||
|
||||
def testAuthPingApi(self):
|
||||
res = self.requests.get(common.AUTH_PING_URL)
|
||||
res = self.requests.get(AUTH_PING_URL)
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertRegexpMatches(res.text, u'"pong"')
|
||||
|
||||
|
@@ -1,11 +1,10 @@
|
||||
import integration_api as common
|
||||
import requests
|
||||
import unittest
|
||||
from integration_api import PING_URL
|
||||
import requests, unittest
|
||||
|
||||
class PingApiTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.res = requests.get(common.PING_URL)
|
||||
self.res = requests.get(PING_URL)
|
||||
|
||||
def testPingApi(self):
|
||||
self.assertEqual(self.res.status_code, 200)
|
||||
|
Reference in New Issue
Block a user