Closed jhw closed 4 years ago
Hi @jhw, looks like you're missing a Response, which would be the missing link between the http-request and your backend.
If you compare it with the StepFunctions-mock, the url_paths need to be set: https://github.com/spulec/moto/blob/master/moto/stepfunctions/urls.py#L6
This links the actual HTTP request to a generic dispatch function. The dispatch function will call 'StepFunctionResponse.method' for each AWS method that you're trying to call.
Try adding this:
class TranslateResponse(BaseResponse):
def translate_text(self):
return TranslateBackend().translate_text(...)
And change the url_paths as appropriate to point to this Base response class
@bblommers works! Many thanks.
One final problem -
import datetime
def timestamp():
return datetime.datetime.now().strftime("%H:%M:%S")
print ("%s before" % timestamp())
from moto.core import BaseBackend
print ("%s after" % timestamp())
then -
justin@justin-XPS-13-9360:~/work$ python dev/test_moto_import.py
22:02:11 before
22:02:41 after
Gah! Why so long ? Any way of reducing this ? (by somehow importing less ?)
Thanks again.
Hey @jhw, happy to hear you got it working!
The import time is a known issue. The way moto is set up, it will always initialize everything - this can take some time. 30 secs is excessive though - does it get any better in subsequent runs?
(FYI, an outstanding PR to reduce the import time: https://github.com/spulec/moto/pull/2697)
justin@justin-XPS-13-9360:~/work$ python dev/test_moto_import.py
11:38:04 before
11:38:08 after
Better. Thing something up with my internet/machine last night. Many thanks for your help.
@jhw If you want to contribute, a PR is always welcome! Looks like a good addition to moto :)
Ah! Yes I should do that. I am generally an extremely poor contributor :-( I will have to investigate the Translate API a bit better, am only mocking a single method at the moment. Leave it with me. I promise to get back. Many thanks.
Hi,
I use
moto
a lot for testing event- based Lambda apps and love it :-)I have a new app which uses AWS Translate a lot, but then notice that
moto
doesn't (yet) support Translate:-(
However I really want to mock Translate to maintain testing consistency with other AWS components in my CI pipeline. So looks like I will have to roll my own, however basic.
My Lambda is very simple -
index.py
and the test pattern I'm looking to achieve also very simple -
test.py
but try as I might I can't figure out the
moto
mocking API. I've been looking closely at the Polly mocking code and have come up with this -moto_ext.py
which seems like I am in the right zone but that some stuff isn't quite right, as I get -
could someone possibly point me in the right direction to get this working ?
Many thanks.