Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Api for product and productversion #12

Merged
merged 12 commits into from Jan 4, 2013
Merged

Conversation

klrmn
Copy link
Contributor

@klrmn klrmn commented Dec 22, 2012

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.

* 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
Copy link
Contributor

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.

Copy link
Contributor Author

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 =)

if not isinstance(productversions, list):
raise KeyError(pv_required_msg)
if not len(productversions):
raise KeyError(pv_required_msg)
Copy link
Contributor

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.

camd pushed a commit that referenced this pull request Jan 4, 2013
OK, this is merged!  Nice work!
@camd camd merged commit 0cfcdef into mozilla:master Jan 4, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants