-
Notifications
You must be signed in to change notification settings - Fork 766
Voice response devx5021 and Python testing, compatibility #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a99e483
3c5ade2
fb43f65
d833182
3519817
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
language: python | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
- "3.3" | ||
- "3.4" | ||
- "3.5" | ||
- "3.6" | ||
install: | ||
- pip install virtualenv --upgrade | ||
- make install | ||
- make test-install | ||
script: | ||
script: | ||
- make test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import six | ||
|
||
import unittest | ||
|
||
import mock | ||
from mock import patch, Mock | ||
from requests import Request | ||
from requests import Session | ||
|
||
from twilio.http.http_client import TwilioHttpClient | ||
|
||
|
||
class TestHttpClientRequest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.session_patcher = patch('twilio.http.http_client.Session') | ||
|
||
self.session_mock = Mock(wraps=Session()) | ||
self.request_mock = Mock() | ||
|
||
self.session_mock.prepare_request.return_value = self.request_mock | ||
self.session_mock.send.return_value = Mock(status_code=200, content=six.u('testing-unicodeΩ≈ç√')) | ||
self.request_mock.headers = {} | ||
|
||
session_constructor_mock = self.session_patcher.start() | ||
session_constructor_mock.return_value = self.session_mock | ||
|
||
self.client = TwilioHttpClient() | ||
|
||
def tearDown(self): | ||
self.session_patcher.stop() | ||
|
||
def test_request_sets_host_header_if_missing(self): | ||
self.request_mock.url = 'https://api.twilio.com/' | ||
self.request_mock.headers = {'Host': 'other.twilio.com'} | ||
|
||
self.client.request('doesnt matter', 'doesnt matter') | ||
|
||
self.assertEqual('other.twilio.com', self.request_mock.headers['Host']) | ||
|
||
def test_request_with_unicode_response(self): | ||
self.request_mock.url = 'https://api.twilio.com/' | ||
self.request_mock.headers = {'Host': 'other.twilio.com'} | ||
|
||
response = self.client.request('doesnt matter', 'doesnt matter') | ||
|
||
self.assertEqual('other.twilio.com', self.request_mock.headers['Host']) | ||
self.assertEqual(200, response.status_code) | ||
self.assertEqual(six.u('testing-unicodeΩ≈ç√'), response.content) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
[tox] | ||
envlist = py26, py27, py33, py34, py35, py36, pypy | ||
envlist = py27, py33, py34, py35, py36, pypy | ||
|
||
[testenv] | ||
deps= -r{toxinidir}/tests/requirements.txt | ||
commands= | ||
nosetests \ | ||
[] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,11 @@ def deprecated(func): | |
|
||
@functools.wraps(func) | ||
def new_func(*args, **kwargs): | ||
warnings.warn_explicit( | ||
"Call to deprecated function {}.".format(func.__name__), | ||
category=DeprecationWarning, | ||
filename=func.func_code.co_filename, | ||
lineno=func.func_code.co_firstlineno + 1 | ||
) | ||
warnings.simplefilter('always', DeprecationWarning) | ||
warnings.warn("Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, stacklevel=2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did this need to change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
warnings.simplefilter('default', DeprecationWarning) | ||
return func(*args, **kwargs) | ||
|
||
return new_func | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the benefit of doing --python=python? Isnt that the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
--python=python
uses the standard alias Travis-CI sets up in each environment, which seemed to be the simplest way to use the intended test version. I can look around for another way if you think there is one.