8000 Add automatic PEP8 compliance via Flake8 by kyleconroy · Pull Request #112 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Add automatic PEP8 compliance via Flake8 #112

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

Merged
merged 3 commits into from
Mar 11, 2013
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ python:
install:
- pip install . --use-mirrors
- pip install -r requirements.txt --use-mirrors
script: nosetests
- pip install -r tests/requirements.txt --use-mirrors
script:
- flake8 --ignore=F401 twilio
- flake8 --ignore=E123,E126,E128,E501 tests
- nosetests
4 changes: 1 addition & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
sphinx
mock==0.8.0
nose
simplejson
unittest2
coverage
nosexcover
six
flake8
6 changes: 3 additions & 3 deletions tests/test_authorized_connect_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_get(self, mock):

self.resource.get("SID")
mock.assert_called_with("GET", "/base/AuthorizedConnectApps/SID",
auth=self.auth)
auth=self.auth)

@patch("twilio.rest.resources.base.make_twilio_request")
def test_list(self, mock):
Expand All @@ -34,7 +34,7 @@ def test_list(self, mock):

self.resource.list()
mock.assert_called_with("GET", "/base/AuthorizedConnectApps",
params={}, auth=self.auth)
params={}, auth=self.auth)

def test_load(self):
instance = AuthorizedConnectApp(Mock(), "sid")
Expand All @@ -47,7 +47,7 @@ def test_load(self):
"connect_app_company_name": "bar",
"connect_app_homepage_url": "http://www.google.com",
"uri": "/2010-04-01/Accounts/",
})
})

self.assertEquals(instance.permissions, ["get-all"])
self.assertEquals(instance.sid, "SID")
Expand Down
20 changes: 6 additions & 14 deletions tests/test_base_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
else:
import unittest2 as unittest

from mock import Mock, patch
from mock import Mock
from nose.tools import assert_equals
from nose.tools import raises
from twilio.rest.resources import Resource
from twilio.rest.resources import ListResource
from twilio.rest.resources import InstanceResource
Expand All @@ -27,6 +26,7 @@ def test_resource_init():
assert_equals(r.auth, auth)
assert_equals(r.uri, uri)


def test_equivalence():
p = ListResource(base_uri, auth)
r1 = p.load_instance({"sid": "AC123"})
Expand All @@ -43,7 +43,7 @@ def testListResourceInit(self):
uri = "%s/%s" % (base_uri, self.r.name)
self.assertEquals(self.r.uri, uri)

def testKeyValue(self):
def testKeyValueLower(self):
self.assertEquals(self.r.key, self.r.name.lower())

def testIterNoKey(self):
Expand All @@ -58,7 +58,7 @@ def testRequest(self):
self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]}
advance_iterator(self.r.iter())
self.r.request.assert_called_with("GET", "https://api.twilio.com/2010-04-01/Resources", params={})

def testIterOneItem(self):
self.r.request = Mock()
self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]}
Expand All @@ -68,24 +68,17 @@ def testIterOneItem(self):

with self.assertRaises(StopIteration):
advance_iterator(items)

def testIterNoNextPage(self):
self.r.request = Mock()
self.r.request.return_value = Mock(), {self.r.key: []}

with self.assertRaises(StopIteration):
advance_iterator(self.r.iter())

def testKeyValue(self):
self.r.key = "Hey"
self.assertEquals(self.r.key, "Hey")

def testInstanceLoading(self):
instance = self.r.load_instance({"sid": "foo"})

self.assertIsInstance(instance, InstanceResource)
self.assertEquals(instance.sid, "foo")


def testInstanceLoading(self):
instance = self.r.load_instance({"sid": "foo"})
Expand Down Expand Up @@ -122,4 +115,3 @@ def testLoadSubresources(self):
self.r.subresources = [m]
self.r.load_subresources()
m.assert_called_with(self.r.uri, self.r.auth)

2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from mock import patch, Mock
from tools import create_mock_json


AUTH = ("ACCOUNT_SID", "AUTH_TOKEN")


class RestClientTest(unittest.TestCase):

def setUp(self):
Expand Down
5 changes: 1 addition & 4 deletions tests/test_conferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest2 as unittest

from datetime import date
from mock import patch, Mock
from mock import Mock
from twilio.rest.resources import Conferences

DEFAULT = {
Expand Down Expand Up @@ -46,6 +46,3 @@ def test_list_before(self):
self.resource.list(created_before=date(2011, 1, 1))
self.params["DateCreated<"] = "2011-01-01"
self.resource.get_instances.assert_called_with(self.params)



17 changes: 8 additions & 9 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@
class CoreTest(unittest.TestCase):

def test_date(self):
d = date(2009,10,10)
d = date(2009, 10, 10)
self.assertEquals(parse_date(d), "2009-10-10")

def test_datetime(self):
d = datetime(2009,10,10)
d = datetime(2009, 10, 10)
self.assertEquals(parse_date(d), "2009-10-10")

def test_string_date(self):
d = "2009-10-10"
self.assertEquals(parse_date(d), "2009-10-10")

def test_string_date(self):
def test_string_date_none(self):
d = None
self.assertEquals(parse_date(d), None)

def test_string_date(self):
def test_string_date_false(self):
d = False
self.assertEquals(parse_date(d), None)

def test_fparam(self):
d = {"HEY": None, "YOU": 3}
ed = {"YOU":3}
ed = {"YOU": 3}
self.assertEquals(transform_params(d), ed)

def test_fparam_booleans(self):
d = {"HEY": None, "YOU": 3, "Activated": False}
ed = {"YOU":3, "Activated": "false"}
ed = {"YOU": 3, "Activated": "false"}
self.assertEquals(transform_params(d), ed)

def test_normalize_dates(self):
Expand All @@ -55,8 +55,8 @@ def foo(on=None, before=None, after=None):
"after": after,
}

d = foo(on="2009-10-10", before=date(2009,10,10),
after=datetime(2009,10,10))
d = foo(on="2009-10-10", before=date(2009, 10, 10),
after=datetime(2009, 10, 10))

self.assertEquals(d["on"], "2009-10-10")
self.assertEquals(d["after"], "2009-10-10")
Expand Down Expand Up @@ -88,4 +88,3 @@ def test_convert_keys(self):
}

self.assertEquals(ed, convert_keys(d))

6 changes: 1 addition & 5 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from twilio.util import TwilioCapability


class JwtTest(unittest.TestCase):

def assertIn(self, foo, bar, msg=None):
Expand Down Expand Up @@ -64,7 +65,6 @@ def test_events_with_filters(self):
event_uri = "scope:stream:subscribe?path=%2F2010-04-01%2FEvents&params=foobar%3Dhey"
self.assertEquals(payload["scope"], event_uri)


def test_decode(self):
token = TwilioCapability("AC123", "XXXXX")
token.allow_client_outgoing("AP123", foobar=3)
Expand Down Expand Up @@ -106,18 +106,14 @@ def test_decodes_valid_jwt(self):

def test_allow_skip_verification(self):
right_secret = 'foo'
bad_secret = 'bar'
jwt_message = jwt.encode(self.payload, right_secret)
decoded_payload = jwt.decode(jwt_message, verify=False)
self.assertEqual(decoded_payload, self.payload)

def test_no_secret(self):
right_secret = 'foo'
bad_secret = 'bar'
jwt_message = jwt.encode(self.payload, right_secret)
self.assertRaises(jwt.DecodeError, jwt.decode, jwt_message)

def test_invalid_crypto_alg(self):
self.assertRaises(NotImplementedError, jwt.encode, self.payload, "secret", "HS1024")


6 changes: 0 additions & 6 deletions tests/test_make_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
Uses the awesome httpbin.org to validate responses
"""
try:
import json
except ImportError:
import simplejson as json


import twilio
from nose.tools import raises
from mock import patch, Mock
Expand Down
8 changes: 2 additions & 6 deletions tests/test_phone_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import unittest
else:
import unittest2 as unittest
from mock import Mock, patch
from twilio import TwilioException
from mock import Mock
from twilio.rest.resources import PhoneNumbers
from twilio.rest.resources import PhoneNumber

Expand Down Expand Up @@ -55,7 +54,6 @@ def test_sms_application_sid(self):
resource.update_instance.assert_called_with(
"SID", {"sms_application_sid": "foo"})


def test_status_callback_url(self):
resource = PhoneNumbers(self.uri, self.auth)
resource.update_instance = Mock()
Expand Down Expand Up @@ -86,8 +84,6 @@ def test_base_uri(self):
entry = json.load(f)
resource.load(entry)

self.assertEquals(resource.parent.base_uri,
self.assertEquals(resource.parent.base_uri,
("https://api.twilio.com/2010-04-01/Accounts/AC4bf2dafbed59a573"
"3d2c1c1c69a83a28"))


Loading
0