Skip to content
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

Add test for double sticky #470

Merged
merged 3 commits into from
Jul 17, 2015
Merged

Add test for double sticky #470

merged 3 commits into from
Jul 17, 2015

Conversation

voussoir
Copy link
Contributor

Also added the num parameter to get_sticky

@danthedaniel
Copy link
Contributor

Lookin' good.

@bboe
Copy link
Member

bboe commented Jul 16, 2015

We haven't released this feature yet, and every time I look at these functions it's not clear what the number value really means. What do you think about calling the argument "bottom" and setting it to false by default for both set and get? Then we fill in the missing pieces. This approach makes testing simpler as we need only test a true or false value.

@voussoir
Copy link
Contributor Author

We just used it because that's the name that Deimorz assigned to it in the ModSupport thread.

I'm cool with making it a bool, but setting the sticky should default to bottom=True, because that's the behavior you get on the site when you click "sticky". I think getting the sticky should default to bottom=False, because the top sticky is generally the more important one.

Thoughts? Can we compromise?

@danthedaniel
Copy link
Contributor

That sounds fine

@bboe
Copy link
Member

bboe commented Jul 16, 2015

Bottom default works for me.

@voussoir
Copy link
Contributor Author

Alright, there we go. That should be a little more intuitive now.

"""Return a Submission object for the sticky of the subreddit."""
return objects.Submission.from_json(self.request_json(
self.config['sticky'] % six.text_type(subreddit)))
def get_sticky(self, subreddit, bottom=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should bottom default to True here, so calling get_sticky without the arguments returns one that was set via set without the argument? We should probably assert that that is in fact the case.

@voussoir
Copy link
Contributor Author

If you make a GET request with no parameters, reddit assumes you wanted the top sticky. For POST, reddit assumes you're replacing the bottom sticky unless you state otherwise.

In my opinion, PRAW should act the same way so it is in line with the site and predictable, so I'd like to leave it. I can add an extra note in the docstrings that the two methods behave differently though.

@bboe
Copy link
Member

bboe commented Jul 17, 2015

I don't like their inconsistency on this matter and strongly suggest we make our code better than theirs. Many PRAW users don't know the default API behavior, and shouldn't have to.

@voussoir
Copy link
Contributor Author

With bottom=True as the default, get_sticky() on a subreddit with only 1 sticky now raises a 404. I could set both of them to False, but then set_sticky() will be overwriting the top slot, even though it behaves oppositely in the browser

untitled-1

That's not so much a matter of who knows the default API behavior, it's just an unexpected difference between what "sticky this please" means on the site and in praw.

You're the owner, so if you insist on the change then I'll go ahead with it. I just want to explain why I feel it should be another way.

@bboe
Copy link
Member

bboe commented Jul 17, 2015

Okay, I think I'm getting it. So on reddit sticky-ing one item puts it on top, and all others puts it on bottom replacing the bottom if it exists. From their interface the only way to move something to the top is to remove the top sticky thereby promoting the bottom sticky to the top.

Am I right that if there are not stickys, and we add something to the bottom, it really is adding it to the top?

Ideally reddit would provide an endpoint that returns a list of the up to two stickies. But until such a time I'm okay with the default get_sticky to return the top one.

Thanks for providing the explanation.

@voussoir
Copy link
Contributor Author

That is all correct. Here's Deimorz' comments:

So if you have one sticky at the time this post is made, it will add a second one. If you already have two, it will replace the bottom one. If you have no stickies, it will go into the top slot (and the next day's one would then go into the second slot)
https://www.reddit.com/r/AutoModerator/comments/3db8ks/_/ct3il4j

You'd have to unsticky/resticky currently, there isn't really any easier way to swap the ordering of them.
https://www.reddit.com/r/ModSupport/comments/3d6q8l/_/ct2i3mp

The rationale being:

This fits what I think will be the most common case of using the top sticky for a longer-lived post like the subreddit rules, and the bottom one for shorter ones like daily/weekly discussions
https://www.reddit.com/r/ModSupport/comments/3cu18x/

 

So we can't set them both to True without giving people surprise 404s, and can't set them both to False without mismatching the site UI.

Last call for changes?

@@ -1301,7 +1301,7 @@ def short_link(self):
return urljoin(self.reddit_session.config.short_domain, self.id)

@restrict_access(scope='modposts')
def sticky(self, num=2):
def sticky(self, bottom=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name should be updated. Also we should probably explain what actually happens, e.g., setting bottom when there is no top will make it the top.

@voussoir
Copy link
Contributor Author

Okay, I've added some additional notes. Not sure if the wording came out a little clunky, it's hard to use the word "sticky" three times in the same sentence without sounding weird.

bboe added a commit that referenced this pull request Jul 17, 2015
Add test for double sticky
@bboe bboe merged commit e4c2071 into praw-dev:master Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants