This repository was archived by the owner on Dec 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Fix #196: Revise awards JSON feed format #197
Open
lmorchard
wants to merge
1
commit into
mozilla:master
Choose a base branch
from
lmorchard:196-obi-displayer-feed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import logging | ||
| import feedparser | ||
| import json | ||
|
|
||
| from django.conf import settings | ||
|
|
||
|
|
@@ -38,12 +39,13 @@ def tearDown(self): | |
| Award.objects.all().delete() | ||
| Badge.objects.all().delete() | ||
|
|
||
| def test_award_feeds(self): | ||
| """Can view award detail""" | ||
| def test_award_atom_feeds(self): | ||
| """Can view award atom feeds""" | ||
| user = self._get_user() | ||
| user2 = self._get_user(username='tester2') | ||
|
|
||
| b1, created = Badge.objects.get_or_create(creator=user, title="Code Badge #1") | ||
| b1, created = Badge.objects.get_or_create(creator=user, | ||
| title="Code Badge #1") | ||
| award = b1.award_to(user2) | ||
|
|
||
| # The award should show up in each of these feeds. | ||
|
|
@@ -72,6 +74,71 @@ def test_award_feeds(self): | |
|
|
||
| ok_(found_it) | ||
|
|
||
| def test_badge_json_feeds(self): | ||
| user = self._get_user() | ||
| user2 = self._get_user(username='tester2') | ||
|
|
||
| b1, created = Badge.objects.get_or_create(creator=user, | ||
| title="Code Badge #1") | ||
|
|
||
| # The award should show up in each of these feeds. | ||
| feed_urls = ( | ||
| reverse('badger.feeds.badges_recent', | ||
| args=('json', )), | ||
| ) | ||
|
|
||
| # Check each of the feeds | ||
| for feed_url in feed_urls: | ||
| r = self.client.get(feed_url, follow=True) | ||
|
|
||
| # The feed should be parsed without issues by feedparser | ||
| feed = json.loads(r.content) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment mentions feedparser, but this line is doing a json.loads on the response content. Is the content Atom/RSS or is it JSON? |
||
|
|
||
| ok_('badges' in feed) | ||
| b1_url = ('http://testserver%s' % | ||
| b1.get_absolute_url()) | ||
| found_it = False | ||
| for badge in feed['badges']: | ||
| if badge['criteria'] == b1_url: | ||
| found_it = True | ||
|
|
||
| ok_(found_it) | ||
|
|
||
| def test_award_json_feeds(self): | ||
| user = self._get_user() | ||
| user2 = self._get_user(username='tester2') | ||
|
|
||
| b1, created = Badge.objects.get_or_create(creator=user, | ||
| title="Code Badge #1") | ||
| award = b1.award_to(user2) | ||
|
|
||
| # The award should show up in each of these feeds. | ||
| feed_urls = ( | ||
| reverse('badger.feeds.awards_recent', | ||
| args=('json', )), | ||
| reverse('badger.feeds.awards_by_badge', | ||
| args=('json', b1.slug, )), | ||
| reverse('badger.feeds.awards_by_user', | ||
| args=('json', user2.username,)), | ||
| ) | ||
|
|
||
| # Check each of the feeds | ||
| for feed_url in feed_urls: | ||
| r = self.client.get(feed_url, follow=True) | ||
|
|
||
| # The feed should be parsed without issues by feedparser | ||
| feed = json.loads(r.content) | ||
|
|
||
| ok_('badges' in feed) | ||
| b1_url = ('http://testserver%s' % | ||
| b1.get_absolute_url(format='json')) | ||
| found_it = False | ||
| for badge in feed['badges']: | ||
| if badge['badge'] == b1_url: | ||
| found_it = True | ||
|
|
||
| ok_(found_it) | ||
|
|
||
| def _get_user(self, username="tester", email="tester@example.com", | ||
| password="trustno1"): | ||
| (user, created) = User.objects.get_or_create(username=username, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Funky! I had no idea you could do that. I have countless places where that would have made life a lot easier.