I am trying to test Google App Engine's new full text search functionality in Python with the development appserver.
Is there a stub for the search
that allows one to test it with the testbed
local unit testing?
The following is example code that throws an exception:
#!/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()
The exception thrown by foo()
is: AssertionError: No api proxy found for service "search"
. Has an api proxy been written for search?
Thoughts and comments appreciated.
UPDATE this was valid in 2012. Things changed in 2013: the stub is officially supported. See @siebz0r answer.
It's not in the list of supported stubs (yet, I assume), but there's a SearchServiceStub in simple_search_stub.py which looks like what you're after.
I haven't tested it myself but you could try do something like this:
testbed = testbed.Testbed()
testbed.activate()
stub = SearchServiceStub()
testbed._register_stub(SEARCH_SERVICE_NAME, stub)
SEARCH_SERVICE_NAME
should be "search"
, and it should also be present in SUPPORTED_SERVICES list, otherwise testbed will raise an exception.
The way you "inject" this new service stub is either modify SDK's testbed/__init__.py or do it from your code. Can't really say which approach is better since it's gonna be a hack in either way, 'till the init_search_stub() will officially appear on the list.
Also, the fact that it's not in the list yet is probably because it's just not ready :) So, use it on your own risk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With