8000 Bring tests up to PEP8 compliance (almost) · Stackdriver/twilio-python@7afdff1 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.

Commit 7afdff1

Browse files
committed
Bring tests up to PEP8 compliance (almost)
1 parent 7cc88e4 commit 7afdff1

11 files changed

+37
-56
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ install:
1010
- pip install -r tests/requirements.txt --use-mirrors
1111
script:
1212
- flake8 --ignore=F401 twilio
13-
- flake8 --ignore=E501 tests
13+
- flake8 --ignore=E123,E126,E128,E501 tests
1414
- nosetests

tests/test_authorized_connect_apps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_get(self, mock):
2525

2626
self.resource.get("SID")
2727
mock.assert_called_with("GET", "/base/AuthorizedConnectApps/SID",
28-
auth=self.auth)
28+
auth=self.auth)
2929

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

3535
self.resource.list()
3636
mock.assert_called_with("GET", "/base/AuthorizedConnectApps",
37-
params={}, auth=self.auth)
37+
params={}, auth=self.auth)
3838

3939
def test_load(self):
4040
instance = AuthorizedConnectApp(Mock(), "sid")
@@ -47,7 +47,7 @@ def test_load(self):
4747
"connect_app_company_name": "bar",
4848
"connect_app_homepage_url": "http://www.google.com",
4949
"uri": "/2010-04-01/Accounts/",
50-
})
50+
})
5151

5252
self.assertEquals(instance.permissions, ["get-all"])
5353
self.assertEquals(instance.sid, "SID")

tests/test_base_resource.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
else:
77
import unittest2 as unittest
88

9-
from mock import Mock, patch
9+
from mock import Mock
1010
from nose.tools import assert_equals
11-
from nose.tools import raises
1211
from twilio.rest.resources import Resource
1312
from twilio.rest.resources import ListResource
1413
from twilio.rest.resources import InstanceResource
@@ -27,6 +26,7 @@ def test_resource_init():
2726
assert_equals(r.auth, auth)
2827
assert_equals(r.uri, uri)
2928

29+
3030
def test_equivalence():
3131
p = ListResource(base_uri, auth)
3232
r1 = p.load_instance({"sid": "AC123"})
@@ -43,7 +43,7 @@ def testListResourceInit(self):
4343
uri = "%s/%s" % (base_uri, self.r.name)
4444
self.assertEquals(self.r.uri, uri)
4545

46-
def testKeyValue(self):
46+
def testKeyValueLower(self):
4747
self.assertEquals(self.r.key, self.r.name.lower())
4848

4949
def testIterNoKey(self):
@@ -58,7 +58,7 @@ def testRequest(self):
5858
self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]}
5959
advance_iterator(self.r.iter())
6060
self.r.request.assert_called_with("GET", "https://api.twilio.com/2010-04-01/Resources", params={})
61-
61+
6262
def testIterOneItem(self):
6363
self.r.request = Mock()
6464
self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]}
@@ -68,24 +68,17 @@ def testIterOneItem(self):
6868

6969
with self.assertRaises(StopIteration):
7070
advance_iterator(items)
71-
71+
7272
def testIterNoNextPage(self):
7373
self.r.request = Mock()
7474
self.r.request.return_value = Mock(), {self.r.key: []}
7575

7676
with self.assertRaises(StopIteration):
7777
advance_iterator(self.r.iter())
78-
78+
7979
def testKeyValue(self):
8080
self.r.key = "Hey"
8181
self.assertEquals(self.r.key, "Hey")
82-
83-
def testInstanceLoading(self):
84-
instance = self.r.load_instance({"sid": "foo"})
85-
86-
self.assertIsInstance(instance, InstanceResource)
87-
self.assertEquals(instance.sid, "foo")
88-
8982

9083
def testInstanceLoading(self):
9184
instance = self.r.load_instance({"sid": "foo"})
@@ -122,4 +115,3 @@ def testLoadSubresources(self):
122115
self.r.subresources = [m]
123116
self.r.load_subresources()
124117
m.assert_called_with(self.r.uri, self.r.auth)
125-

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from mock import patch, Mock
99
from tools import create_mock_json
1010

11-
1211
AUTH = ("ACCOUNT_SID", "AUTH_TOKEN")
1312

13+
1414
class RestClientTest(unittest.TestCase):
1515

1616
def setUp(self):

tests/test_conferences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest2 as unittest
66

77
from datetime import date
8-
from mock import patch, Mock
8+
from mock import Mock
99
from twilio.rest.resources import Conferences
1010

1111
DEFAULT = {

tests/test_core.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616
class CoreTest(unittest.TestCase):
1717

1818
def test_date(self):
19-
d = date(2009,10,10)
19+
d = date(2009, 10, 10)
2020
self.assertEquals(parse_date(d), "2009-10-10")
2121

2222
def test_datetime(self):
23-
d = datetime(2009,10,10)
23+
d = datetime(2009, 10, 10)
2424
self.assertEquals(parse_date(d), "2009-10-10")
2525

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

30-
def test_string_date(self):
30+
def test_string_date_none(self):
3131
d = None
3232
self.assertEquals(parse_date(d), None)
3333

34-
def test_string_date(self):
34+
def test_string_date_false(self):
3535
d = False
3636
self.assertEquals(parse_date(d), None)
3737

3838
def test_fparam(self):
3939
d = {"HEY": None, "YOU": 3}
40-
ed = {"YOU":3}
40+
ed = {"YOU": 3}
4141
self.assertEquals(transform_params(d), ed)
4242

4343
def test_fparam_booleans(self):
4444
d = {"HEY": None, "YOU": 3, "Activated": False}
45-
ed = {"YOU":3, "Activated": "false"}
45+
ed = {"YOU": 3, "Activated": "false"}
4646
self.assertEquals(transform_params(d), ed)
4747

4848
def test_normalize_dates(self):
@@ -55,8 +55,8 @@ def foo(on=None, before=None, after=None):
5555
"after": after,
5656
}
5757

58-
d = foo(on="2009-10-10", before=date(2009,10,10),
59-
after=datetime(2009,10,10))
58+
d = foo(on="2009-10-10", before=date(2009, 10, 10),
59+
after=datetime(2009, 10, 10))
6060

6161
self.assertEquals(d["on"], "2009-10-10")
6262
self.assertEquals(d["after"], "2009-10-10")
@@ -88,4 +88,3 @@ def test_convert_keys(self):
8888
}
8989

9090
self.assertEquals(ed, convert_keys(d))
91-

tests/test_jwt.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from twilio.util import TwilioCapability
1010

11+
1112
class JwtTest(unittest.TestCase):
1213

1314
def assertIn(self, foo, bar, msg=None):
@@ -64,7 +65,6 @@ def test_events_with_filters(self):
6465
event_uri = "scope:strea F438 m:subscribe?path=%2F2010-04-01%2FEvents&params=foobar%3Dhey"
6566
self.assertEquals(payload["scope"], event_uri)
6667

67-
6868
def test_decode(self):
6969
token = TwilioCapability("AC123", "XXXXX")
7070
token.allow_client_outgoing("AP123", foobar=3)
@@ -106,18 +106,14 @@ def test_decodes_valid_jwt(self):
106106

107107
def test_allow_skip_verification(self):
108108
right_secret = 'foo'
109-
bad_secret = 'bar'
110109
jwt_message = jwt.encode(self.payload, right_secret)
111110
decoded_payload = jwt.decode(jwt_message, verify=False)
112111
self.assertEqual(decoded_payload, self.payload)
113112

114113
def test_no_secret(self):
115114
right_secret = 'foo'
116-
bad_secret = 'bar'
117115
jwt_message = jwt.encode(self.payload, right_secret)
118116
self.assertRaises(jwt.DecodeError, jwt.decode, jwt_message)
119117

120118
def test_invalid_crypto_alg(self):
121119
self.assertRaises(NotImplementedError, jwt.encode, self.payload, "secret", "HS1024")
122-
123-

tests/test_make_request.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
44
Uses the awesome httpbin.org to validate responses
55
"""
6-
try:
7-
import json
8-
except ImportError:
9-
import simplejson as json
10-
11-
126
import twilio
137
from nose.tools import raises
148
from mock import patch, Mock

tests/test_phone_numbers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import unittest
99
else:
1010
import unittest2 as unittest
11-
from mock import Mock, patch
12-
from twilio import TwilioException
11+
from mock import Mock
1312
from twilio.rest.resources import PhoneNumbers
1413
from twilio.rest.resources import PhoneNumber
1514

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

58-
5957
def test_status_callback_url(self):
6058
resource = PhoneNumbers(self.uri, self.auth)
6159
resource.update_instance = Mock()
@@ -86,8 +84,6 @@ def test_base_uri(self):
8684
entry = json.load(f)
8785
resource.load(entry)
8886

89-
self.assertEquals(resource.parent.base_uri,
87+
self.assertEquals(resource.parent.base_uri,
9088
("https://api.twilio.com/2010-04-01/Accounts/AC4bf2dafbed59a573"
9189
"3d2c1c1c69a83a28"))
92-
93-

tests/test_twiml.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def improperAppend(self, verb):
3434
self.assertRaises(TwimlException, verb.append, twiml.Sms(""))
3535
self.assertRaises(TwimlException, verb.append, twiml.Pause())
3636

37+
3738
class TestResponse(TwilioTest):
3839

3940
def testEmptyResponse(self):
@@ -44,6 +45,7 @@ def testResponseAddAttribute(self):
4445
r = Response(foo="bar")
4546
self.assertEquals(self.strip(r), '<?xml version="1.0" encoding="UTF-8"?><Response foo="bar" />')
4647

48+
4749
class TestSay(TwilioTest):
4850

4951
def testEmptySay(self):
@@ -62,7 +64,7 @@ def testSayHelloWorld(self):
6264
def testSayFrench(self):
6365
"""should say hello monkey"""
6466
r = Response()
65-
r.append(twiml.Say(u("n\xe9cessaire et d'autres"))) # it works on python 2.6 with the from __future__ import unicode_literal
67+
r.append(twiml.Say(u("n\xe9cessaire et d'autres"))) # it works on python 2.6 with the from __future__ import unicode_literal
6668
self.assertEquals(text_type(r),
6769
'<?xml version="1.0" encoding="UTF-8"?><Response><Say>n&#233;cessaire et d\'autres</Say></Response>')
6870

@@ -96,22 +98,23 @@ def testSayConvienceMethod(self):
9698

9799
def testSayAddAttribute(self):
98100
"""add attribute"""
99-
r = twiml.Say("",foo="bar")
101+
r = twiml.Say("", foo="bar")
100102
r = self.strip(r)
101103
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Say foo="bar" />')
102104

103105
def testSayBadAppend(self):
104106
""" should raise exceptions for wrong appending"""
105107
self.improperAppend(twiml.Say(""))
106108

109+
107110
class TestPlay(TwilioTest):
108111

109112
def testEmptyPlay(self):
110113
"""should play hello monkey"""
111114
r = Response()
112115
r.append(twiml.Play(""))
113116
r = self.strip(r)
114-
self.assertEqual(r,'<?xml version="1.0" encoding="UTF-8"?><Response><Play /></Response>')
117+
self.assertEqual(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Play /></Response>')
115118

116119
def testPlayHello(self):
117120
"""should play hello monkey"""
@@ -136,14 +139,15 @@ def testPlayConvienceMethod(self):
136139

137140
def testPlayAddAttribute(self):
138141
"""add attribute"""
139-
r = twiml.Play("",foo="bar")
142+
r = twiml.Play("", foo="bar")
140143
r = self.strip(r)
141144
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Play foo="bar" />')
142145

143146
def testPlayBadAppend(self):
144147
""" should raise exceptions for wrong appending"""
145148
self.improperAppend(twiml.Play(""))
146149

150+
147151
class TestRecord(TwilioTest):
148152

149153
def testRecordEmpty(self):
@@ -163,7 +167,7 @@ def testRecordActionMethod(self):
163167
def testRecordMaxlengthFinishTimeout(self):
164168
"""should record with an maxlength, finishonkey, and timeout"""
165169
r = Response()
166-
r.append(twiml.Record(timeout=4,finishOnKey="#", maxLength=30))
170+
r.append(twiml.Record(timeout=4, finishOnKey="#", maxLength=30))
167171
r = self.strip(r)
168172
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Record finishOnKey="#" maxLength="30" timeout="4" /></Response>')
169173

@@ -184,6 +188,7 @@ def testRecordBadAppend(self):
184188
""" should raise exceptions for wrong appending"""
185189
self.improperAppend(twiml.Record())
186190

191+
187192
class TestRedirect(TwilioTest):
188193

189194
def testRedirectEmpty(self):
@@ -206,7 +211,7 @@ def testRedirectMethodGetParams(self):
206211

207212
def testAddAttribute(self):
208213
"""add attribute"""
209-
r = twiml.Redirect("",foo="bar")
214+
r = twiml.Redirect("", foo="bar")
210215
r = self.strip(r)
211216
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Redirect foo="bar" />')
212217

@@ -224,7 +229,6 @@ def testHangup(self):
224229
r = self.strip(r)
225230
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Hangup /></Response>')
226231

227-
228232
def testHangupConvience(self):
229233
"""should raises exceptions for wrong appending"""
230234
r = Response()
@@ -271,6 +275,7 @@ def testBadAppend(self):
271275
""" should raise exceptions for wrong appending"""
272276
self.improperAppend(twiml.Reject())
273277

278+
274279
class TestSms(TwilioTest):
275280

276281
def testEmpty(self):
@@ -469,11 +474,10 @@ def testAddConferenceConvenceMethod(self):
469474

470475
def testAddAttribute(self):
471476
"""add attribute"""
472-
r = twiml.Conference("MyRoom",foo="bar")
477+
r = twiml.Conference("MyRoom", foo="bar")
473478
r = self.strip(r)
474479
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Conference foo="bar">MyRoom</Conference>')
475480

476-
477481
def testBadAppend(self):
478482
""" should raise exceptions for wrong appending"""
479483
self.improperAppend(twiml.Conference("Hello"))
@@ -506,7 +510,6 @@ def testNestedSayPlayPause(self):
506510
r = self.strip(r)
507511
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><Say>Hey</Say><Play>hey.mp3</Play><Pause /></Gather></Response>')
508512

509-
510513
def testNestedSayPlayPauseConvience(self):
511514
""" a gather with a say, play, and pause"""
512515
r = Response()

tests/tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import with_statement
22
from mock import Mock
33

4+
45
def create_mock_json(path):
56
with open(path) as f:
67
resp = Mock()

0 commit comments

Comments
 (0)
0