rest_gae icon indicating copy to clipboard operation
rest_gae copied to clipboard

Build a comprehensive test suite

Open dankrause opened this issue 11 years ago • 7 comments
trafficstars

Most tests would require interacting with the dev_appserver, and I'm not yet sure what that will mean for their design.

dankrause avatar Feb 14 '14 20:02 dankrause

Some useful information that came up in a quick search: https://developers.google.com/appengine/docs/python/tools/localunittesting

If I have some time later today, I'll get started on this.

dankrause avatar Feb 20 '14 16:02 dankrause

Interesting problem: rest_gae.RestHandlerClass acts like a webapp2.RequestHandler (and in fact, is a subclass of it). However, it is also a subclass of webapp.RequestHandler (notice the lack of the number two there) via the blobstore_handlers that it subclasses. This actually breaks the webapp2 unit testing helpers. The helpers check to see if your handler is a subclass of webapp.RequestHandler first, and if so, treat it like one. This fails because we're acting like a webapp2.RequestHandler, and requiring the request and response objects as args to rest_gae.RestHandlerClass.__init__, but webapp2 doesn't pass them while testing. I'm not 100% sure why testing via Request.get_response acts that much differently than normal use of webapp2, but it does.

I'm still trying to figure out the best way to work around this.

dankrause avatar Feb 20 '14 20:02 dankrause

I think that the best way to fix this might be to refactor how we implement blobkey property handlers. The way I see it, RESTHandlerClass should only be for models and instances. We would call get_rest_class in RESTHandler, and we'd call a new get_blobstore_class for each BlobKeyProperty which would build a handler that subclasses both BlobstoreUploadHandler and BlobstoreDownloadHandler (and not webapp2.RequestHandler).

I think this would actually end up simplifying RESTHandlerClass for us, by stripping away the blobstore stuff and keeping it in one place. I'm still thinking about this one.

dankrause avatar Feb 20 '14 20:02 dankrause

That's what I initially thought of doing - the problem was without subclassing from BaseRESTHandler, those blob handlers would lose any permission-based checking - e.g. is the user permitted to POST to /my_model/123/blob_prop? (and this would mean we'd have to write the same code twice - in both classes). Maybe now, with the new permission system you're writing - could there be a DRY-friendly way of doing this?

budowski avatar Feb 22 '14 22:02 budowski

@budowski could you please tell whether you have some progress with this issue ?

signalpillar avatar Oct 30 '14 14:10 signalpillar

Could you please check this version, where we do not inherit but aggregate instances of download/upload handlers when needed.

What I can see from the code of these helpers they rely on the request and response parameters and do not rely on the method overridden in our RESTHandlerClass.

signalpillar avatar Oct 30 '14 16:10 signalpillar

I have added simple tests also. The show that rest_gae can be used in testing but they do not prove that upload/download for blogs works correctly.

signalpillar avatar Oct 30 '14 17:10 signalpillar