Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion tests/test_oauth1_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import unicode_literals
from __future__ import unicode_literals, print_function
import mock
import unittest
import sys
Expand All @@ -13,13 +13,32 @@
except ImportError:
from io import StringIO

try:
import cryptography
except ImportError:
cryptography = None

if sys.version[0] == '3':
unicode_type = str
bytes_type = bytes
else:
unicode_type = unicode
bytes_type = str

# Monkey patch Python 2.6 unittest
if not hasattr(unittest, 'SkipTest'):
unittest.SkipTest = RuntimeWarning
unittest.TestResult.real_add_error = unittest.TestResult.addError

def patched_addError(self, test, exc_info):
if exc_info[0] is RuntimeWarning:
print(str(exc_info[1]), end=' ', file=sys.stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we bothering to print anything here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the unittest output shows something useful. i.e.
https://travis-ci.org/jayvdb/requests-oauthlib/jobs/82236301#L176

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to add unittest2 support so that this workaround is needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be better, yeah.

return
else:
self.real_add_error(test, exc_info)
unittest.TestResult.addError = patched_addError


TEST_RSA_KEY = (
"-----BEGIN RSA PRIVATE KEY-----\n"
"MIIEogIBAAKCAQEApF1JaMSN8TEsh4N4O/5SpEAVLivJyLH+Cgl3OQBPGgJkt8cg\n"
Expand Down Expand Up @@ -95,6 +114,9 @@ def fake_send(r, **kwargs):
@mock.patch('oauthlib.oauth1.rfc5849.generate_timestamp')
@mock.patch('oauthlib.oauth1.rfc5849.generate_nonce')
def test_signature_methods(self, generate_nonce, generate_timestamp):
if not cryptography:
raise unittest.SkipTest('cryptography module is required')

generate_nonce.return_value = 'abc'
generate_timestamp.return_value = '123'

Expand Down Expand Up @@ -239,6 +261,9 @@ def test_authorized_true(self):
@mock.patch('oauthlib.oauth1.rfc5849.generate_timestamp')
@mock.patch('oauthlib.oauth1.rfc5849.generate_nonce')
def test_authorized_true_rsa(self, generate_nonce, generate_timestamp):
if not cryptography:
raise unittest.SkipTest('cryptography module is required')

generate_nonce.return_value = 'abc'
generate_timestamp.return_value = '123'
signature = ('OAuth '
Expand Down