-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added REST API for posts #54
Conversation
Codecov Report
@@ Coverage Diff @@
## master #54 +/- ##
==========================================
- Coverage 93.99% 93.65% -0.34%
==========================================
Files 47 49 +2
Lines 932 1087 +155
Branches 42 54 +12
==========================================
+ Hits 876 1018 +142
- Misses 44 58 +14
+ Partials 12 11 -1
Continue to review full report at Codecov.
|
db7cf40
to
e1108de
Compare
I'll dig into this more after lunch, but I'm getting this error on some
|
open_discussions/betamax_config.py
Outdated
Betamax.register_request_matcher(CustomBodyMatcher) | ||
|
||
|
||
with Betamax.configure() as config: |
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.
I'm a little wary of module-level code like this, but it looks like that the only way to do this unless we want to pass betamax
configured sessions around, right?
My main concern is this code somehow getting triggered by some inadvertent import path down the road. Maybe we could move this into a function here and store in a global INITIALIZED = True
and invoke the method in other methods/fixtures as we need them? That way execution of this code is explicit.
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.
I think we can probably move this into the fixture function
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.
You import it in recorder.py too so I wasn't sure about suggesting that.
channels/serializers.py
Outdated
text = WriteableSerializerMethodField(allow_null=True) | ||
title = serializers.CharField() | ||
upvoted = WriteableSerializerMethodField() | ||
downvoted = WriteableSerializerMethodField() |
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.
I don't think we necessarily need this, but these aren't currently writable on the create. I think adding a comment here would suffice.
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.
The user is allowed to write them in the update though. What would the comment be for?
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.
You can pass them in create but they do nothing.
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.
I'll implement this for create, it seems like more consistent behavior to have it work in both cases
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.
Sounds fine to me.
channels/serializers.py
Outdated
**kwargs | ||
) | ||
|
||
def update(self, instance, validated_data): |
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.
Should it be an error to provide True
for both downvote
and upvote
in the same request?
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.
Yes, it's taken care of in validate
though
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.
I missed that, ignore this then.
channels/serializers.py
Outdated
upvote = validated_data.get('upvoted') | ||
|
||
if "text" in validated_data: | ||
instance = api.update_post(post_id=post_id, text=validated_data['text']) |
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 possible to provide url
at the same time as text, which will cause this to raise a ValueError
, (gives a 400 and stacktrace page in debug mode). Probably worth validating url
wasn't provided before this because it's an invalid request anyway.
Also begs the question whether we need validation code twice (here and in api.py)?
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 I'm not sure where the validation best fits, maybe it will become clearer in a future PR. I'll add the url
check
Other than the exception and 400 error mentioned above this tested functional. |
The post which caused the error, was it created with the script which generates fake data for reddit? |
Yes it was the fake data. Should we just ignore those? |
I don't know, it's their fake data script so you would think it would be valid fake data. I would feel better if we did some investigation on why it was happening |
eff9bfc
to
7e8476a
Compare
All comments should be addressed |
Just updated this to rename |
What are the relevant tickets?
Fixes #29
What's this PR do?
open_discussions/recorder.py
to aid in creating cassettes for use in mocking reddit during testingHow should this be manually tested?
Go to
/api/v0/channels/<subreddit>/posts/
to view a list of posts or to create a new one. Go to/api/v0/posts/<post_id>/
to view information on a specific post or to update or delete a post.