python – 如何使用GAE和Nosetest模拟用户?
作者:互联网
当鼻子实例化自己的测试平台时,如何调用setup_env()?
我正在尝试使用TDD开发App Engine应用程序,我需要弄清楚如何模拟用户.
我开始测试:
nosetests -v –with-gae
我有几个人建议使用nosetests,因为它会让事情变得更容易.
但是,有关如何模拟事物的所有示例似乎都明确使用了testbed.setup_env()
https://cloud.google.com/appengine/docs/python/tools/localunittesting
How do you mock the User service in App Engine?
我不明白如何使用nosetests设置环境值.
这就是我现在拥有的:
import sys, os, subprocess, time, unittest, shlex
sys.path.append("/usr/local/google_appengine")
sys.path.append('/usr/local/google_appengine/lib/')
sys.path.append("/usr/local/google_appengine/lib/yaml/lib")
sys.path.append("/usr/local/google_appengine/lib/webapp2-2.5.2")
sys.path.append("/usr/local/google_appengine/lib/django-1.5")
sys.path.append("/usr/local/google_appengine/lib/cherrypy")
sys.path.append("/usr/local/google_appengine/lib/concurrent")
sys.path.append("/usr/local/google_appengine/lib/docker")
sys.path.append("/usr/local/google_appengine/lib/requests")
sys.path.append("/usr/local/google_appengine/lib/websocket")
sys.path.append("/usr/local/google_appengine/lib/fancy_urllib")
sys.path.append("/usr/local/google_appengine/lib/antlr3")
os.environ['APPLICATION_ID'] = 'workout'
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from google.appengine.api import memcache, apiproxy_stub, apiproxy_stub_map
from google.appengine.ext import db
from google.appengine.ext import testbed
from google.appengine.datastore import datastore_stub_util
from google.appengine.tools.devappserver2 import devappserver2
class NewVisitorTest(unittest.TestCase):
# enable the datastore stub
nosegae_datastore_v3 = True
nosegae_datastore_v3_kwargs = {
'datastore_file': '/tmp/nosegae.sqlite3',
'use_sqlite': True
}
def setUp(self):
# Start the dev server
cmd = "/usr/local/bin/dev_appserver.py /Users/Bryan/work/GoogleAppEngine/workout_log/app.yaml --port 8080 --storage_path /tmp/datastore --clear_datastore --skip_sdk_update_check"
self.dev_appserver = subprocess.Popen(shlex.split(cmd),
stdout=subprocess.PIPE)
time.sleep(2) # Important, let dev_appserver start up
self.datastore_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3')
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
self.dev_appserver.terminate()
解决方法:
我想我自己想出来了.
我将下面的语句添加到测试setUp()中:
testself.testbed.setup_env(user_is_admin='1')
标签:python,google-app-engine,nosetests,nose-gae 来源: https://codeday.me/bug/20190623/1272350.html