Conversation
partial work on product some logging that will need to go later
* update some doc strings * add test cases for invalid ProductResource.obj_create input
from tastypie.authorization import Authorization | ||
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS | ||
from tastypie import fields | ||
|
||
from .models import Product, ProductVersion, ApiKey | ||
from ..environments.api import EnvironmentResource | ||
from ..mtapi import MTResource, MTAuthorization, MTApiKeyAuthentication |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, good call on this move.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a good thing you like it, because otherwise there was gonna be an unresolvable include loop =)
changes pursuant to review comments
if not isinstance(productversions, list): | ||
raise KeyError(pv_required_msg) | ||
if not len(productversions): | ||
raise KeyError(pv_required_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While looking into how to hide those 500 errors, it occurred to me that a 500 error is the wrong thing. If the data sent to the server is wrong, it should return a 400 (Bad Request). And so just throwing an exception here causing a 500 isn't the right way to go. I hunted around a bit, and here's the right way to initiate a 400 error:
except KeyError:
raise ImmediateHttpResponse(response=http.HttpBadRequest(pv_required_msg))
and at the top, import these:
from tastypie import http
from tastypie.exceptions import ImmediateHttpResponse
Then change your tests to expect 400s instead and you're good.
it is worth noting that ProductResource.obj_update() does not overwrite the productversion list, it just adds to it. This is not RESTful, but is in-line with the fact that we don't allow PUT to lists.