Skip to content

Commit b7c0b19

Browse files
authored
port nose tools (#878)
reduce usage of nose tools (assert_equals / true / false) unless its really needed
1 parent 43bdfe0 commit b7c0b19

File tree

3 files changed

+48
-51
lines changed

3 files changed

+48
-51
lines changed

tests/test_accept.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from flask import Flask
33
import flask_restful
44
from werkzeug import exceptions
5-
from nose.tools import assert_equals
65

76

87

@@ -21,8 +20,8 @@ def get(self):
2120

2221
with app.test_client() as client:
2322
res = client.get('/', headers=[('Accept', 'application/json')])
24-
assert_equals(res.status_code, 200)
25-
assert_equals(res.content_type, 'application/json')
23+
self.assertEqual(res.status_code, 200)
24+
self.assertEqual(res.content_type, 'application/json')
2625

2726

2827
def test_accept_no_default_match_acceptable(self):
@@ -38,8 +37,8 @@ def get(self):
3837

3938
with app.test_client() as client:
4039
res = client.get('/', headers=[('Accept', 'application/json')])
41-
assert_equals(res.status_code, 200)
42-
assert_equals(res.content_type, 'application/json')
40+
self.assertEqual(res.status_code, 200)
41+
self.assertEqual(res.content_type, 'application/json')
4342

4443

4544
def test_accept_default_override_accept(self):
@@ -55,8 +54,8 @@ def get(self):
5554

5655
with app.test_client() as client:
5756
res = client.get('/', headers=[('Accept', 'text/plain')])
58-
assert_equals(res.status_code, 200)
59-
assert_equals(res.content_type, 'application/json')
57+
self.assertEqual(res.status_code, 200)
58+
self.assertEqual(res.content_type, 'application/json')
6059

6160

6261
def test_accept_default_any_pick_first(self):
@@ -77,8 +76,8 @@ def text_rep(data, status_code, headers=None):
7776

7877
with app.test_client() as client:
7978
res = client.get('/', headers=[('Accept', '*/*')])
80-
assert_equals(res.status_code, 200)
81-
assert_equals(res.content_type, 'application/json')
79+
self.assertEqual(res.status_code, 200)
80+
self.assertEqual(res.content_type, 'application/json')
8281

8382

8483
def test_accept_no_default_no_match_not_acceptable(self):
@@ -94,8 +93,8 @@ def get(self):
9493

9594
with app.test_client() as client:
9695
res = client.get('/', headers=[('Accept', 'text/plain')])
97-
assert_equals(res.status_code, 406)
98-
assert_equals(res.content_type, 'application/json')
96+
self.assertEqual(res.status_code, 406)
97+
self.assertEqual(res.content_type, 'application/json')
9998

10099

101100
def test_accept_no_default_custom_repr_match(self):
@@ -117,8 +116,8 @@ def text_rep(data, status_code, headers=None):
117116

118117
with app.test_client() as client:
119118
res = client.get('/', headers=[('Accept', 'text/plain')])
120-
assert_equals(res.status_code, 200)
121-
assert_equals(res.content_type, 'text/plain')
119+
self.assertEqual(res.status_code, 200)
120+
self.assertEqual(res.content_type, 'text/plain')
122121

123122

124123
def test_accept_no_default_custom_repr_not_acceptable(self):
@@ -140,8 +139,8 @@ def text_rep(data, status_code, headers=None):
140139

141140
with app.test_client() as client:
142141
res = client.get('/', headers=[('Accept', 'application/json')])
143-
assert_equals(res.status_code, 406)
144-
assert_equals(res.content_type, 'text/plain')
142+
self.assertEqual(res.status_code, 406)
143+
self.assertEqual(res.content_type, 'text/plain')
145144

146145

147146
def test_accept_no_default_match_q0_not_acceptable(self):
@@ -161,8 +160,8 @@ def get(self):
161160

162161
with app.test_client() as client:
163162
res = client.get('/', headers=[('Accept', 'application/json; q=0')])
164-
assert_equals(res.status_code, 406)
165-
assert_equals(res.content_type, 'application/json')
163+
self.assertEqual(res.status_code, 406)
164+
self.assertEqual(res.content_type, 'application/json')
166165

167166
def test_accept_no_default_accept_highest_quality_of_two(self):
168167
class Foo(flask_restful.Resource):
@@ -181,8 +180,8 @@ def text_rep(data, status_code, headers=None):
181180

182181
with app.test_client() as client:
183182
res = client.get('/', headers=[('Accept', 'application/json; q=0.1, text/plain; q=1.0')])
184-
assert_equals(res.status_code, 200)
185-
assert_equals(res.content_type, 'text/plain')
183+
self.assertEqual(res.status_code, 200)
184+
self.assertEqual(res.content_type, 'text/plain')
186185

187186

188187
def test_accept_no_default_accept_highest_quality_of_three(self):
@@ -203,8 +202,8 @@ def text_rep(data, status_code, headers=None):
203202

204203
with app.test_client() as client:
205204
res = client.get('/', headers=[('Accept', 'application/json; q=0.1, text/plain; q=0.3, text/html; q=0.2')])
206-
assert_equals(res.status_code, 200)
207-
assert_equals(res.content_type, 'text/plain')
205+
self.assertEqual(res.status_code, 200)
206+
self.assertEqual(res.content_type, 'text/plain')
208207

209208

210209
def test_accept_no_default_no_representations(self):
@@ -221,8 +220,8 @@ def get(self):
221220

222221
with app.test_client() as client:
223222
res = client.get('/', headers=[('Accept', 'text/plain')])
224-
assert_equals(res.status_code, 406)
225-
assert_equals(res.content_type, 'text/plain')
223+
self.assertEqual(res.status_code, 406)
224+
self.assertEqual(res.content_type, 'text/plain')
226225

227226
def test_accept_invalid_default_no_representations(self):
228227

@@ -238,4 +237,4 @@ def get(self):
238237

239238
with app.test_client() as client:
240239
res = client.get('/', headers=[('Accept', 'text/plain')])
241-
assert_equals(res.status_code, 500)
240+
self.assertEqual(res.status_code, 500)

tests/test_api.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
import flask_restful.fields
1717
from flask_restful import OrderedDict
1818
from json import dumps, loads, JSONEncoder
19-
#noinspection PyUnresolvedReferences
20-
from nose.tools import assert_equals, assert_true, assert_false # you need it for tests in form of continuations
19+
from nose.tools import assert_equal # you need it for tests in form of continuations
2120
import six
2221

2322

2423
def check_unpack(expected, value):
25-
assert_equals(expected, value)
24+
assert_equal(expected, value)
2625

2726

2827
def test_unpack():
@@ -62,7 +61,7 @@ def test_unauthorized_no_challenge_by_default(self):
6261
response.headers = {}
6362
with app.test_request_context('/foo'):
6463
response = api.unauthorized(response)
65-
assert_false('WWW-Authenticate' in response.headers)
64+
self.assertFalse('WWW-Authenticate' in response.headers)
6665

6766
def test_unauthorized(self):
6867
app = Flask(__name__)
@@ -433,10 +432,10 @@ def get(self):
433432
app = app.test_client()
434433

435434
resp = app.get("/api")
436-
assert_equals(resp.status_code, 404)
437-
assert_equals('application/json', resp.headers['Content-Type'])
435+
self.assertEqual(resp.status_code, 404)
436+
self.assertEqual('application/json', resp.headers['Content-Type'])
438437
data = loads(resp.data.decode())
439-
assert_true('message' in data)
438+
self.assertTrue('message' in data)
440439

441440
def test_handle_non_api_error(self):
442441
app = Flask(__name__)
@@ -742,7 +741,7 @@ def test_abort_custom_message(self):
742741
flask_restful.abort(404, message="no user")
743742
assert False # We should never get here
744743
except Exception as e:
745-
assert_equals(e.data['message'], "no user")
744+
self.assertEqual(e.data['message'], "no user")
746745

747746
def test_abort_type(self):
748747
self.assertRaises(HTTPException, lambda: flask_restful.abort(404))

tests/test_cors.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from flask import Flask
33
import flask_restful
44
from flask_restful.utils import cors
5-
from nose.tools import assert_equals, assert_true
65

76

87
class CORSTestCase(unittest.TestCase):
@@ -20,12 +19,12 @@ def get(self):
2019

2120
with app.test_client() as client:
2221
res = client.get('/')
23-
assert_equals(res.status_code, 200)
24-
assert_equals(res.headers['Access-Control-Allow-Origin'], '*')
25-
assert_equals(res.headers['Access-Control-Max-Age'], '21600')
26-
assert_true('HEAD' in res.headers['Access-Control-Allow-Methods'])
27-
assert_true('OPTIONS' in res.headers['Access-Control-Allow-Methods'])
28-
assert_true('GET' in res.headers['Access-Control-Allow-Methods'])
22+
self.assertEqual(res.status_code, 200)
23+
self.assertEqual(res.headers['Access-Control-Allow-Origin'], '*')
24+
self.assertEqual(res.headers['Access-Control-Max-Age'], '21600')
25+
self.assertTrue('HEAD' in res.headers['Access-Control-Allow-Methods'])
26+
self.assertTrue('OPTIONS' in res.headers['Access-Control-Allow-Methods'])
27+
self.assertTrue('GET' in res.headers['Access-Control-Allow-Methods'])
2928

3029
def test_access_control_expose_headers(self):
3130

@@ -41,9 +40,9 @@ def get(self):
4140

4241
with app.test_client() as client:
4342
res = client.get('/')
44-
assert_equals(res.status_code, 200)
45-
assert_true('X-MY-HEADER' in res.headers['Access-Control-Expose-Headers'])
46-
assert_true('X-ANOTHER-HEADER' in res.headers['Access-Control-Expose-Headers'])
43+
self.assertEqual(res.status_code, 200)
44+
self.assertTrue('X-MY-HEADER' in res.headers['Access-Control-Expose-Headers'])
45+
self.assertTrue('X-ANOTHER-HEADER' in res.headers['Access-Control-Expose-Headers'])
4746

4847
def test_access_control_allow_methods(self):
4948

@@ -62,11 +61,11 @@ def post(self):
6261

6362
with app.test_client() as client:
6463
res = client.get('/')
65-
assert_equals(res.status_code, 200)
66-
assert_true('HEAD' in res.headers['Access-Control-Allow-Methods'])
67-
assert_true('OPTIONS' in res.headers['Access-Control-Allow-Methods'])
68-
assert_true('GET' in res.headers['Access-Control-Allow-Methods'])
69-
assert_true('POST' not in res.headers['Access-Control-Allow-Methods'])
64+
self.assertEqual(res.status_code, 200)
65+
self.assertTrue('HEAD' in res.headers['Access-Control-Allow-Methods'])
66+
self.assertTrue('OPTIONS' in res.headers['Access-Control-Allow-Methods'])
67+
self.assertTrue('GET' in res.headers['Access-Control-Allow-Methods'])
68+
self.assertTrue('POST' not in res.headers['Access-Control-Allow-Methods'])
7069

7170
def test_no_crossdomain(self):
7271

@@ -80,7 +79,7 @@ def get(self):
8079

8180
with app.test_client() as client:
8281
res = client.get('/')
83-
assert_equals(res.status_code, 200)
84-
assert_true('Access-Control-Allow-Origin' not in res.headers)
85-
assert_true('Access-Control-Allow-Methods' not in res.headers)
86-
assert_true('Access-Control-Max-Age' not in res.headers)
82+
self.assertEqual(res.status_code, 200)
83+
self.assertTrue('Access-Control-Allow-Origin' not in res.headers)
84+
self.assertTrue('Access-Control-Allow-Methods' not in res.headers)
85+
self.assertTrue('Access-Control-Max-Age' not in res.headers)

0 commit comments

Comments
 (0)