我正在尝试使用TDD构建一个简单的Google App Engine应用程序。
$ python functional_tests.py
WARNING:root:initial generator _run_to_list(query.py:952) raised BadArgumentError(app must not be empty.)
WARNING:root:suspended generator _get_async(query.py:1231) raised BadArgumentError(app must not be empty.)
Traceback (most recent call last):
File "functional_tests.py", line 23, in <module>
from main import Customer
File "/Users/Bryan/work/GoogleAppEngine/dermalfillersecrets/main.py", line 39, in <module>
if not ( Client.query( Client.name == "Bryan Wheelock").get()):
File "/usr/local/google_appengine/google/appengine/ext/ndb/query.py", line 1218, in get
return self.get_async(**q_options).get_result()
File "/usr/local/google_appengine/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
self.check_success()
File "/usr/local/google_appengine/google/appengine/ext/ndb/tasklets.py", line 368, in _help_tasklet_along
value = gen.throw(exc.__class__, exc, tb)
File "/usr/local/google_appengine/google/appengine/ext/ndb/query.py", line 1231, in _get_async
res = yield self.fetch_async(1, **q_options)
File "/usr/local/google_appengine/google/appengine/ext/ndb/tasklets.py", line 371, in _help_tasklet_along
value = gen.send(val)
File "/usr/local/google_appengine/google/appengine/ext/ndb/query.py", line 957, in _run_to_list
dsquery = self._get_query(conn)
File "/usr/local/google_appengine/google/appengine/ext/ndb/query.py", line 918, in _get_query
group_by=group_by)
File "/usr/local/google_appengine/google/appengine/datastore/datastore_rpc.py", line 104, in positional_wrapper
return wrapped(*args, **kwds)
File "/usr/local/google_appengine/google/appengine/datastore/datastore_query.py", line 1906, in __init__
ancestor=ancestor)
File "/usr/local/google_appengine/google/appengine/datastore/datastore_rpc.py", line 104, in positional_wrapper
return wrapped(*args, **kwds)
File "/usr/local/google_appengine/google/appengine/datastore/datastore_query.py", line 1745, in __init__
self.__app = datastore_types.ResolveAppId(app).encode('utf-8')
File "/usr/local/google_appengine/google/appengine/api/datastore_types.py", line 229, in ResolveAppId
ValidateString(app, 'app', datastore_errors.BadArgumentError)
File "/usr/local/google_appengine/google/appengine/api/datastore_types.py", line 177, in ValidateString
raise exception('%s must not be empty.' % name)
google.appengine.api.datastore_errors.BadArgumentError: app must not be empty.
这是functional_test.py
的代码from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest
import sys
sys.path.append("/usr/local/google_appengine")
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")
import dev_appserver
from google.appengine.tools.devappserver2 import devappserver2
from google.appengine.tools.devappserver2 import python_runtime
from google.appengine.ext import testbed
from main import Customer
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
# setup the dev_appserver
APP_CONFIGS = ['app.yaml']
python_runtime._RUNTIME_ARGS = [
sys.executable,
os.path.join(os.path.dirname(dev_appserver.__file__),
'_python_runtime.py')
]
options = devappserver2.PARSER.parse_args([
'--admin_port', '0',
'--port', '9080',
'--datastore_path', ':memory:',
'--logs_path', ':memory:',
'--skip_sdk_update_check',
'--',
] + APP_CONFIGS)
server = devappserver2.DevelopmentServer()
server.start(options)
self.server = server
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
self.testbed.deactivate()
这是来自main.py的代码:
import os
import urllib
import logging
from google.appengine.api import users
from google.appengine.ext import ndb
import jinja2
import webapp2
JINJA_ENVIRONMENT = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
DEFAULT_LEADBOOK_NAME = 'NameCustomer'
# We set a parent key on the 'Customer' to ensure that they are all in the same
# entity group. Queries across the single entity group will be consistent.
# However, the write rate should be limited to ~1/second.
def leadbook_key(leadbook_name=DEFAULT_LEADBOOK_NAME):
"""Constructs a Datastore key for a LeadBook entity with leadbook_name."""
return ndb.Key('LeadBook', leadbook_name)
# Client logs in as a User
# take the User.id and use that to create a child Client
class Client(ndb.Model):
# It seems that I need to figure out how to have the user log in via Google then add the additional info
email = ndb.StringProperty() # I think this would be email address
name = ndb.StringProperty(indexed=True)
street1 = ndb.StringProperty()
street2 = ndb.StringProperty()
city = ndb.StringProperty()
zipcode = ndb.IntegerProperty()
phone = ndb.StringProperty()
signup = ndb.DateTimeProperty(auto_now_add=True)
if not ( Client.query( Client.name == "Bryan Wheelock").get()):
logging.info("create Admin")
client = Client(
email = "bryan@mail.com",
name = "Bryan Wheelock",
street1 = "555 Main St",
street2 = "unit 1",
city = "Atlanta",
zipcode = 99999,
phone = "(888)555-1212"
).put()
答案 0 :(得分:0)
我能够通过将模型导入unittest.TestCase的设置来解决badargumenterror。
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
#self.testbed.setup_env(app_id='dermalfillersecrets')
self.testbed.init_datastore_v3_stub()
# setup the dev_appserver
APP_CONFIGS = ['app.yaml']
python_runtime._RUNTIME_ARGS = [
sys.executable,
os.path.join(os.path.dirname(dev_appserver.__file__),
'_python_runtime.py')
]
######## This is the Where I moved the import clause ####
from main import Customer
#########################################################
options = devappserver2.PARSER.parse_args([
'--admin_port', '0',
'--port', '9080',
'--datastore_path', ':memory:',
'--logs_path', ':memory:',
'--skip_sdk_update_check',
'--',
] + APP_CONFIGS)
server = devappserver2.DevelopmentServer()
server.start(options)
self.server = server
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)