diff --git a/blogger.py b/blogger.py index 2ebe5454..cec40318 100644 --- a/blogger.py +++ b/blogger.py @@ -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?") diff --git a/blogger_test.py b/blogger_test.py index 51599158..3f0dac66 100644 --- a/blogger_test.py +++ b/blogger_test.py @@ -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))