Skip to content

Commit

Permalink
blogger signup: if they have no blogs, show error and redirect to fro…
Browse files Browse the repository at this point in the history
…nt page
  • Loading branch information
snarfed committed Jan 24, 2015
1 parent e576abb commit 70fc50e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions blogger.py
Expand Up @@ -169,11 +169,14 @@ class OAuthCallback(util.Handler):
oauth-dropin doesn't yet allow multiple callback handlers. :/
"""
def get(self):
auth_entity = None
auth_entity_str_key = self.request.get('auth_entity')
if auth_entity_str_key:
auth_entity = ndb.Key(urlsafe=auth_entity_str_key).get()
else:
auth_entity = None
if not auth_entity.blog_ids or not auth_entity.blog_hostnames:
auth_entity = None

if not auth_entity:
self.messages.add(
"Couldn't fetch your blogs. Maybe you're not a Blogger user?")

Expand Down
18 changes: 16 additions & 2 deletions blogger_test.py
Expand Up @@ -60,11 +60,25 @@ def test_new_oauth_dropins_error(self):
currently intercept Blogger declines.
"""
resp = blogger.application.get_response('/blogger/oauth_handler')
self.assertIn("Couldn't fetch your blogs",
urllib.unquote(urlparse.urlparse(resp.headers['Location']).fragment))
self.assertEquals(302, resp.status_int)
location = urlparse.urlparse(resp.headers['Location'])
self.assertEquals('/', location.path)
self.assertIn("Couldn't fetch your blogs", urllib.unquote(location.fragment))
self.assertEquals(0, BloggerV2Auth.query().count())
self.assertEquals(0, Blogger.query().count())

def test_oauth_handler_no_blogs(self):
self.auth_entity = BloggerV2Auth(id='123', name='name', picture_url='pic',
blogs_atom='x', user_atom='y', creds_json='z')
self.auth_entity.put()

resp = blogger.application.get_response(
'/blogger/oauth_handler?auth_entity=%s' % self.auth_entity.key.urlsafe())
self.assertEquals(302, resp.status_int)
location = urlparse.urlparse(resp.headers['Location'])
self.assertEquals('/', location.path)
self.assertIn("Couldn't fetch your blogs", urllib.unquote(location.fragment))

def test_new_no_blogs(self):
self.auth_entity.blog_hostnames = []
self.assertIsNone(Blogger.new(self.handler, auth_entity=self.auth_entity))
Expand Down

0 comments on commit 70fc50e

Please sign in to comment.