better test_web.py, thanks Niphlod
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.5-stable+timestamp.2013.03.21.11.29.00
|
Version 2.4.5-stable+timestamp.2013.03.21.12.03.58
|
||||||
|
|||||||
+52
-6
@@ -11,11 +11,58 @@ else:
|
|||||||
sys.path.append(os.path.realpath('../'))
|
sys.path.append(os.path.realpath('../'))
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
import signal
|
||||||
from contrib.webclient import WebClient
|
from contrib.webclient import WebClient
|
||||||
|
|
||||||
|
webserverprocess = None
|
||||||
|
|
||||||
class TestWeb(unittest.TestCase):
|
def startwebserver():
|
||||||
def testWebClient(self):
|
global webserverprocess
|
||||||
|
webserverprocess = subprocess.Popen([sys.executable, 'web2py.py', '-a', 'testpass'])
|
||||||
|
print 'Sleeping before web2py starts...'
|
||||||
|
for a in range(1,11):
|
||||||
|
time.sleep(1)
|
||||||
|
print a, '...'
|
||||||
|
print ''
|
||||||
|
|
||||||
|
def terminate_process(pid):
|
||||||
|
#Taken from http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kill-a-subprocess
|
||||||
|
# all this shit is because we are stuck with Python 2.5 and \
|
||||||
|
#we cannot use Popen.terminate()
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
import ctypes
|
||||||
|
PROCESS_TERMINATE = 1
|
||||||
|
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, pid)
|
||||||
|
ctypes.windll.kernel32.TerminateProcess(handle, -1)
|
||||||
|
ctypes.windll.kernel32.CloseHandle(handle)
|
||||||
|
else:
|
||||||
|
os.kill(pid, signal.SIGKILL)
|
||||||
|
|
||||||
|
def stopwebserver():
|
||||||
|
global webserverprocess
|
||||||
|
print 'Killing webserver'
|
||||||
|
if sys.version_info < (2,6):
|
||||||
|
terminate_process(webserverprocess.pid)
|
||||||
|
else:
|
||||||
|
webserverprocess.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
class LiveTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
startwebserver()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
stopwebserver()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TestWeb(LiveTest):
|
||||||
|
def testRegisterAndLogin(self):
|
||||||
client = WebClient('http://127.0.0.1:8000/welcome/default/')
|
client = WebClient('http://127.0.0.1:8000/welcome/default/')
|
||||||
|
|
||||||
client.get('index')
|
client.get('index')
|
||||||
@@ -40,7 +87,7 @@ class TestWeb(unittest.TestCase):
|
|||||||
|
|
||||||
# check registration and login were successful
|
# check registration and login were successful
|
||||||
client.get('index')
|
client.get('index')
|
||||||
print client.text
|
|
||||||
self.assertTrue('Welcome Homer' in client.text)
|
self.assertTrue('Welcome Homer' in client.text)
|
||||||
|
|
||||||
client = WebClient('http://127.0.0.1:8000/admin/default/')
|
client = WebClient('http://127.0.0.1:8000/admin/default/')
|
||||||
@@ -48,9 +95,7 @@ class TestWeb(unittest.TestCase):
|
|||||||
client.get('site')
|
client.get('site')
|
||||||
client.get('design/welcome')
|
client.get('design/welcome')
|
||||||
|
|
||||||
|
def testStaticCache(self):
|
||||||
class TestStaticCacheControl(unittest.TestCase):
|
|
||||||
def testWebClient(self):
|
|
||||||
s = WebClient('http://127.0.0.1:8000/welcome/')
|
s = WebClient('http://127.0.0.1:8000/welcome/')
|
||||||
s.get('static/js/web2py.js')
|
s.get('static/js/web2py.js')
|
||||||
assert('expires' not in s.headers)
|
assert('expires' not in s.headers)
|
||||||
@@ -61,5 +106,6 @@ class TestStaticCacheControl(unittest.TestCase):
|
|||||||
assert('expires' in s.headers)
|
assert('expires' in s.headers)
|
||||||
assert(s.headers['cache-control'].startswith('max-age'))
|
assert(s.headers['cache-control'].startswith('max-age'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user