fixed a few more typos and better testing, thanks Paolo
This commit is contained in:
+1
-1
@@ -525,7 +525,7 @@ def load_config(config_file, opt_map):
|
|||||||
|
|
||||||
Notice that the configuring Python script is never executed/imported,
|
Notice that the configuring Python script is never executed/imported,
|
||||||
instead the ast library is used to evaluate each option assignment,
|
instead the ast library is used to evaluate each option assignment,
|
||||||
provided that it is writen on a single line.
|
provided that it is written on a single line.
|
||||||
|
|
||||||
Returns an OrderedDict with sourced options.
|
Returns an OrderedDict with sourced options.
|
||||||
"""
|
"""
|
||||||
|
|||||||
+32
-23
@@ -1,23 +1,25 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Unit tests for running web2py
|
Unit tests for running web2py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
from gluon.contrib.webclient import WebClient
|
from gluon.contrib.webclient import WebClient
|
||||||
from gluon._compat import urllib2, PY2
|
from gluon._compat import urllib2, PY2
|
||||||
|
from gluon.fileutils import create_app
|
||||||
|
|
||||||
|
test_app_name = '_test_web'
|
||||||
|
|
||||||
webserverprocess = None
|
webserverprocess = None
|
||||||
|
|
||||||
|
|
||||||
def startwebserver():
|
def startwebserver():
|
||||||
global webserverprocess
|
global webserverprocess
|
||||||
path = path = os.path.dirname(os.path.abspath(__file__))
|
path = path = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -33,9 +35,9 @@ def startwebserver():
|
|||||||
print('Sleeping before web2py starts...')
|
print('Sleeping before web2py starts...')
|
||||||
for a in range(1, 11):
|
for a in range(1, 11):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print(a, '...')
|
print("%d..." % a)
|
||||||
try:
|
try:
|
||||||
c = WebClient('http://127.0.0.1:8000')
|
c = WebClient('http://127.0.0.1:8000/' + test_app_name)
|
||||||
c.get('/')
|
c.get('/')
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
@@ -71,17 +73,24 @@ class LiveTest(unittest.TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
appdir = os.path.join('applications', test_app_name)
|
||||||
|
if not os.path.exists(appdir):
|
||||||
|
os.mkdir(appdir)
|
||||||
|
create_app(appdir)
|
||||||
startwebserver()
|
startwebserver()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
stopwebserver()
|
stopwebserver()
|
||||||
|
appdir = os.path.join('applications', test_app_name)
|
||||||
|
if os.path.exists(appdir):
|
||||||
|
shutil.rmtree(appdir)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf("datastore" in os.getenv("DB", ""), "TODO: setup web test for app engine")
|
@unittest.skipIf("datastore" in os.getenv("DB", ""), "TODO: setup web test for app engine")
|
||||||
class TestWeb(LiveTest):
|
class TestWeb(LiveTest):
|
||||||
def testRegisterAndLogin(self):
|
def testRegisterAndLogin(self):
|
||||||
client = WebClient('http://127.0.0.1:8000/welcome/default/')
|
client = WebClient("http://127.0.0.1:8000/%s/default/" % test_app_name)
|
||||||
|
|
||||||
client.get('index')
|
client.get('index')
|
||||||
|
|
||||||
@@ -102,28 +111,28 @@ class TestWeb(LiveTest):
|
|||||||
password='test',
|
password='test',
|
||||||
_formname='login')
|
_formname='login')
|
||||||
client.post('user/login', data=data)
|
client.post('user/login', data=data)
|
||||||
self.assertTrue('Homer' in client.text)
|
self.assertIn('Homer', client.text)
|
||||||
|
|
||||||
# check registration and login were successful
|
# check registration and login were successful
|
||||||
client.get('index')
|
client.get('index')
|
||||||
|
|
||||||
self.assertTrue('Homer' in client.text)
|
self.assertIn('Homer', client.text)
|
||||||
|
|
||||||
client = WebClient('http://127.0.0.1:8000/admin/default/')
|
client = WebClient('http://127.0.0.1:8000/admin/default/')
|
||||||
client.post('index', data=dict(password='testpass'))
|
client.post('index', data=dict(password='testpass'))
|
||||||
client.get('site')
|
client.get('site')
|
||||||
client.get('design/welcome')
|
client.get('design/' + test_app_name)
|
||||||
|
|
||||||
def testStaticCache(self):
|
def testStaticCache(self):
|
||||||
s = WebClient('http://127.0.0.1:8000/welcome/')
|
s = WebClient("http://127.0.0.1:8000/%s/" % test_app_name)
|
||||||
s.get('static/js/web2py.js')
|
s.get('static/js/web2py.js')
|
||||||
assert('expires' not in s.headers)
|
self.assertNotIn('expires', s.headers)
|
||||||
assert(not s.headers['cache-control'].startswith('max-age'))
|
self.assertFalse(s.headers['cache-control'].startswith('max-age'))
|
||||||
text = s.text
|
text = s.text
|
||||||
s.get('static/_1.2.3/js/web2py.js')
|
s.get('static/_1.2.3/js/web2py.js')
|
||||||
assert(text == s.text)
|
self.assertEqual(text, s.text)
|
||||||
assert('expires' in s.headers)
|
self.assertIn('expires', s.headers)
|
||||||
assert(s.headers['cache-control'].startswith('max-age'))
|
self.assertTrue(s.headers['cache-control'].startswith('max-age'))
|
||||||
|
|
||||||
@unittest.skipIf(not(PY2), 'skip PY3 testSoap')
|
@unittest.skipIf(not(PY2), 'skip PY3 testSoap')
|
||||||
def testSoap(self):
|
def testSoap(self):
|
||||||
@@ -133,15 +142,15 @@ class TestWeb(LiveTest):
|
|||||||
client = SoapClient(wsdl=url)
|
client = SoapClient(wsdl=url)
|
||||||
ret = client.SubIntegers(a=3, b=2)
|
ret = client.SubIntegers(a=3, b=2)
|
||||||
# check that the value returned is ok
|
# check that the value returned is ok
|
||||||
assert('SubResult' in ret)
|
self.assertIn('SubResult', ret)
|
||||||
assert(ret['SubResult'] == 1)
|
self.assertEqual(ret['SubResult'], 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = client.Division(a=3, b=0)
|
ret = client.Division(a=3, b=0)
|
||||||
except SoapFault as sf:
|
except SoapFault as sf:
|
||||||
# verify the exception value is ok
|
# verify the exception value is ok
|
||||||
# assert(sf.faultstring == "float division by zero") # true only in 2.7
|
# self.assertEqual(sf.faultstring, "float division by zero") # true only in 2.7
|
||||||
assert(sf.faultcode == "Server.ZeroDivisionError")
|
self.assertEqual(sf.faultcode, "Server.ZeroDivisionError")
|
||||||
|
|
||||||
# store sent and received xml for low level test
|
# store sent and received xml for low level test
|
||||||
xml_request = client.xml_request
|
xml_request = client.xml_request
|
||||||
@@ -152,7 +161,7 @@ class TestWeb(LiveTest):
|
|||||||
try:
|
try:
|
||||||
s.post('examples/soap_examples/call/soap', data=xml_request, method="POST")
|
s.post('examples/soap_examples/call/soap', data=xml_request, method="POST")
|
||||||
except urllib2.HTTPError as e:
|
except urllib2.HTTPError as e:
|
||||||
assert(e.msg == 'INTERNAL SERVER ERROR')
|
self.assertEqual(e.msg, 'INTERNAL SERVER ERROR')
|
||||||
# check internal server error returned (issue 153)
|
# check internal server error returned (issue 153)
|
||||||
assert(s.status == 500)
|
self.assertEqual(s.status, 500)
|
||||||
assert(s.text == xml_response)
|
self.assertEqual(s.text, xml_response)
|
||||||
|
|||||||
Reference in New Issue
Block a user