Google App Engine"搜索"的测试平台

Bri*_*unt 4 google-app-engine testbed

我正在尝试使用开发应用程序服务器在Python中测试Google App Engine的全新全文搜索功能.

是否有一个存根search,允许用testbed本地单元测试进行测试?

以下是抛出异常的示例代码:

#!/usr/bin/python
from google.appengine.ext import testbed

from google.appengine.api import search

def foo():
    d = search.Document(doc_id='X',
        fields=[search.TextField(name='abc', value='123')])
    s = search.Index(name='one').add(d)

tb = testbed.Testbed()
tb.activate()
# tb.init_search_stub() ## does this exist?

foo()
Run Code Online (Sandbox Code Playgroud)

抛出的异常foo()是:AssertionError: No api proxy found for service "search".是否为搜索编写了api代理?

赞赏的想法和评论.

ale*_*lex 10

更新此功能于2012年生效.2013年发生了变化:存根受到官方支持.见@ siebz0r回答.

它不在受支持的存根列表中(但是,我假设),但是在simple_search_stub.py中有一个SearchServiceStub,看起来就像你所追求的那样.

我自己没有测试过,但你可以尝试这样做:

testbed = testbed.Testbed()
testbed.activate()

stub = SearchServiceStub()
testbed._register_stub(SEARCH_SERVICE_NAME, stub)
Run Code Online (Sandbox Code Playgroud)

SEARCH_SERVICE_NAME应该是"search",它也应该出现在SUPPORTED_SERVICES列表中,否则testbed会引发异常.

"注入"这个新服务存根的方式是修改SDK的testbed/__ init__.py或者从代码中执行.真的不能说哪种方法更好,因为它会以任何一种方式成为黑客,直到init_search_stub()将正式出现在列表中.

此外,它不在列表中的事实可能是因为它还没有准备好:)所以,请自行承担风险.


sie*_*z0r 5

从SDK 1.8.4开始,可以从Testbed启用搜索存根:

from google.appengine.api import search
from google.appengine.ext import testbed

try:
    tb = testbed.Testbed()
    tb.activate()
    tb.init_search_stub()
    index = search.Index(name='test')
    index.put(search.Document())
finally:
    tb.deactivate()
Run Code Online (Sandbox Code Playgroud)