Skip to content

Commit

Permalink
Update test_get_access_information (no longer interactive).
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Apr 27, 2015
1 parent e90ef5d commit 4619d4d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
1 change: 1 addition & 0 deletions tests/cassettes/test_get_access_information.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions": [{"request": {"body": {"string": "redirect_uri=https%3A%2F%2F127.0.0.1%3A65010%2Fauthorize_callback&code=MQALrr1di8GzcnT8szbTWhLcBUQ&grant_type=authorization_code", "encoding": "utf-8"}, "headers": {"Content-Length": ["128"], "Accept-Encoding": ["gzip, deflate"], "Accept": ["*/*"], "User-Agent": ["PRAW_test_suite PRAW/3.0a1 Python/2.7.5 Darwin-13.4.0-x86_64-i386-64bit"], "Connection": ["keep-alive"], "Content-Type": ["application/x-www-form-urlencoded"], "Authorization": ["Basic c3RKbFVTVWJQUWU1bFE6aVUtTHNPenlKSDdCRFZvcS1xT1dORXEyenVJ"]}, "method": "POST", "uri": "https://api.reddit.com/api/v1/access_token/"}, "response": {"body": {"base64_string": "H4sIAAAAAAAAA6pWSkxOTi0uji/Jz07NU7JSUDI3NjCyMDPXzff1iHINM60w9g43dy9yT6sMt0wOdM4sM3I2UNJRUAKrjy+pLEgFaUpKTSxKLQKJp1YUZBalFsdnggwzNjMw0FFQKk7OhyjLTEnNK8ksqVSqBQAAAP//AwDGxFtHeAAAAA==", "encoding": "UTF-8"}, "headers": {"x-xss-protection": ["1; mode=block"], "x-content-type-options": ["nosniff"], "content-encoding": ["gzip"], "transfer-encoding": ["chunked"], "set-cookie": ["__cfduid=d7c954cc974d51dff88d18fc05e19f7a81430148424; expires=Tue, 26-Apr-16 15:27:04 GMT; path=/; domain=.reddit.com; HttpOnly"], "server": ["cloudflare-nginx"], "connection": ["keep-alive"], "cache-control": ["no-cache"], "date": ["Mon, 27 Apr 2015 15:27:05 GMT"], "x-frame-options": ["SAMEORIGIN"], "x-moose": ["majestic"], "content-type": ["application/json; charset=UTF-8"], "cf-ray": ["1ddb8ca5c8410962-DFW"]}, "status": {"message": "OK", "code": 200}, "url": "https://api.reddit.com/api/v1/access_token/"}, "recorded_at": "2015-04-27T15:27:06"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept": ["*/*"], "Connection": ["keep-alive"], "Accept-Encoding": ["gzip, deflate"], "Authorization": ["bearer 7302867-oMHZEV5x3KW7GrGfyW9cQCiv2C0"], "User-Agent": ["PRAW_test_suite PRAW/3.0a1 Python/2.7.5 Darwin-13.4.0-x86_64-i386-64bit"]}, "method": "GET", "uri": "https://oauth.reddit.com/api/v1/me.json"}, "response": {"body": {"base64_string": "H4sIAAAAAAAAA0yQwWrDMBBEf0Xs2ZQ4OMHRrcfecmjPiyKt2yWStqzk4FLy70HGhFxnhzez8w/ZJQJr4Pz3fv74pFK/CukeOgNeyVUKYE2/H4djf9iNh7ddZ+CHA+GkklDlIrWANZOLhToD3xIDeqUQeNWbfePgXP2T1Q8bK3K+4tVpcuut2SUlyvUpnjoDciPFfgRrqs4thwu2qJdkLpikCZtjbULLL6urLBmsyXOMrb0reCPliSkgJcfxBdsAMHheprYA54ss6GXOtf1yfwAAAP//AwC+4cimLgEAAA==", "encoding": "UTF-8"}, "headers": {"x-ratelimit-remaining": ["599.0"], "x-xss-protection": ["1; mode=block"], "x-content-type-options": ["nosniff"], "content-encoding": ["gzip"], "transfer-encoding": ["chunked"], "set-cookie": ["__cfduid=ddfa37fe8d1e3f1014521f3d11918a2801430148425; expires=Tue, 26-Apr-16 15:27:05 GMT; path=/; domain=.reddit.com; HttpOnly"], "server": ["cloudflare-nginx"], "connection": ["keep-alive"], "pragma": ["no-cache"], "cache-control": ["no-cache, no-cache"], "date": ["Mon, 27 Apr 2015 15:27:05 GMT"], "x-frame-options": ["SAMEORIGIN"], "x-moose": ["majestic"], "content-type": ["application/json; charset=UTF-8"], "cf-ray": ["1ddb8cacd90d0956-DFW"], "x-ratelimit-used": ["1"], "x-ratelimit-reset": ["175"]}, "status": {"message": "OK", "code": 200}, "url": "https://oauth.reddit.com/api/v1/me.json"}, "recorded_at": "2015-04-27T15:27:06"}], "recorded_with": "betamax/0.4.2"}
22 changes: 0 additions & 22 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import print_function, unicode_literals

import os
import sys
import time
import unittest
from betamax import Betamax, BaseMatcher
Expand Down Expand Up @@ -132,24 +131,3 @@ def flair_diff(root, other):
other_items = set(tuple(item[key].lower() if key in item and item[key] else
'' for key in keys) for item in other)
return list(root_items - other_items)


def interactive_only(function):
@wraps(function)
def interactive_only_function(obj):
if os.getenv('INTERACTIVE'):
return function(obj)
print('Passing interactive only test: {0}.{1}'
.format(obj.__class__.__name__, function.__name__))
return interactive_only_function


def prompt(msg):
sys.stdout.write(msg)
sys.stdout.flush()
response = ''
cur = ''
while cur != '\n':
cur = sys.stdin.read(1)
response += cur
return response.strip()
25 changes: 8 additions & 17 deletions tests/old.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
"""PRAW outdated test suite."""
"""PRAW outdated test suite.
The tests in this file do not run on travis.ci and need to each be moved
into a respective test_NAME.py module. Individual test functions that require
network connectivity should be wrapped with a @betamax decorator.
"""

from __future__ import print_function, unicode_literals

Expand All @@ -9,22 +15,7 @@
from six import text_type
from praw import decorators, errors, helpers
from praw.objects import Comment, MoreComments
from .helper import (AuthenticatedHelper, BasicHelper, flair_diff,
interactive_only, prompt)


class OtherTests(unittest.TestCase):
@interactive_only
def test_get_access_information(self):
"""TODO: Remove the interactive requirement via betamax."""
print('Visit this URL: {0}'.format(self.r.get_authorize_url('...')))
code = prompt('Code from redir URL: ')
token = self.r.get_access_information(code)
expected = {'access_token': self.r.access_token,
'refresh_token': None,
'scope': set(('identity',))}
self.assertEqual(expected, token)
self.assertNotEqual(None, self.r.user)
from .helper import AuthenticatedHelper, BasicHelper, flair_diff


class AccessControlTests(unittest.TestCase, BasicHelper):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_oauth2_reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from praw import Reddit, errors
from praw.objects import Submission
from six import text_type
from .helper import PRAWTest, USER_AGENT, betamax


Expand Down Expand Up @@ -33,6 +34,18 @@ def test_authorize_url(self):
'state': '...'}
self.assertEqual(expected, params)

@betamax
def test_get_access_information(self):
# If this test fails, the following URL will need to be visted in order
# to obtain a new code to pass to `get_access_information`:
# self.r.get_authorize_url('...')
token = self.r.get_access_information('MQALrr1di8GzcnT8szbTWhLcBUQ')
expected = {'access_token': self.r.access_token,
'refresh_token': None,
'scope': set(('identity',))}
self.assertEqual(expected, token)
self.assertEqual('PyAPITestUser2', text_type(self.r.user))

@betamax
def test_get_access_information_with_invalid_code(self):
self.assertRaises(errors.OAuthInvalidGrant,
Expand Down

0 comments on commit 4619d4d

Please sign in to comment.