Skip to content

Commit

Permalink
instagram: fix tests for HTTP 403 errors for bad tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Feb 5, 2021
1 parent 7278926 commit bcfcb4c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/test_instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def test_get_activities_response_no_activity_id(self):
Activity(id='tag:instagram.com,2013:789', source=other,
activity_json=json_dumps({'boo': 'bah'})).put()


resp = self.ig.get_activities_response()
self.assert_equals([{'foo': 'bar'}, {'baz': 'biff'}], resp['items'])

Expand Down Expand Up @@ -174,15 +173,15 @@ def test_profile_no_stored_token(self):
resp = app.application.get_response(
'/instagram/browser/profile?token=towkin', method='POST',
text=HTML_PROFILE_COMPLETE)
self.assertEqual(400, resp.status_int)
self.assertEqual(403, resp.status_int)
self.assertIn("towkin is not authorized for any of: {'snarfed.org'}", resp.text)

def test_profile_bad_token(self):
resp = app.application.get_response(
'/instagram/browser/profile?token=nope', method='POST',
text=HTML_PROFILE_COMPLETE)
self.assertEqual(400, resp.status_int)
self.assertIn('', resp.text)
self.assertEqual(403, resp.status_int)
self.assertIn("nope is not authorized for any of: {'snarfed.org'}", resp.text)

def test_post(self):
self.ig.put()
Expand Down Expand Up @@ -213,9 +212,11 @@ def test_post_empty(self):
self.assertIn('No Instagram post found in HTML', resp.text)

def test_post_missing_token(self):
key = self.ig.put()
empty = HTML_HEADER + json_dumps({'config': HTML_VIEWER_CONFIG}) + HTML_FOOTER
resp = app.application.get_response(
'/instagram/browser/post', method='POST', text=HTML_VIDEO_COMPLETE)
f'/instagram/browser/post?key={key.urlsafe().decode()}',
method='POST', text=HTML_VIDEO_COMPLETE)
self.assertEqual(400, resp.status_int)
self.assertIn('Missing required parameter: token', resp.text)

Expand Down Expand Up @@ -276,7 +277,7 @@ def test_likes_bad_token(self):
resp = app.application.get_response(
'/instagram/browser/likes?id=tag:instagram.com,2013:123_456&token=nope',
method='POST', text=json_dumps(HTML_PHOTO_LIKES_RESPONSE))
self.assertEqual(400, resp.status_int)
self.assertEqual(403, resp.status_int)
self.assertIn("nope is not authorized for any of: {'snarfed.org'}", resp.text)

def test_poll(self):
Expand Down

0 comments on commit bcfcb4c

Please sign in to comment.