@@ -20,66 +20,44 @@ def test_should_be_constructable(self):
2020 Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = False )
2121
2222 def test_app_id_should_be_text (self ):
23- with self .assertRaises (TypeError ):
24- Config (key = u'key' , secret = u'secret' , ssl = False )
25-
26- with self .assertRaises (TypeError ):
27- Config (app_id = 4 , key = u'key' , secret = u'secret' , ssl = False )
28-
29- with self .assertRaises (TypeError ):
30- Config (app_id = b'4' , key = u'key' , secret = u'secret' , ssl = False )
23+ self .assertRaises (TypeError , lambda : Config (key = u'key' , secret = u'secret' , ssl = False ))
24+ self .assertRaises (TypeError , lambda : Config (app_id = 4 , key = u'key' , secret = u'secret' , ssl = False ))
25+ self .assertRaises (TypeError , lambda : Config (app_id = b'4' , key = u'key' , secret = u'secret' , ssl = False ))
3126
3227 def test_key_should_be_text (self ):
33- with self .assertRaises (TypeError ):
34- Config (app_id = u'4' , secret = u'secret' , ssl = False )
35-
36- with self .assertRaises (TypeError ):
37- Config (app_id = u'4' , key = 4 , secret = u'secret' , ssl = False )
38-
39- with self .assertRaises (TypeError ):
40- Config (app_id = u'4' , key = b'key' , secret = u'secret' , ssl = False )
28+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , secret = u'secret' , ssl = False ))
29+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = 4 , secret = u'secret' , ssl = False ))
30+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = b'key' , secret = u'secret' , ssl = False ))
4131
4232 def test_secret_should_be_text (self ):
43- with self .assertRaises (TypeError ):
44- Config (app_id = u'4' , key = u'key' , secret = 4 , ssl = False )
45-
46- with self .assertRaises (TypeError ):
47- Config (app_id = u'4' , key = u'key' , secret = b'secret' , ssl = False )
33+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = 4 , ssl = False ))
34+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = b'secret' , ssl = False ))
4835
4936 def test_ssl_should_be_required (self ):
50- with self .assertRaises (TypeError ):
51- Config (app_id = u'4' , key = u'key' , secret = b'secret' )
37+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = b'secret' ))
5238
5339 def test_ssl_should_be_boolean (self ):
5440 Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = False )
5541 Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True )
5642
57- with self .assertRaises (TypeError ):
58- Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = 4 )
43+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = 4 ))
5944
6045 def test_host_should_be_text (self ):
6146 Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , host = u'foo' )
6247
63- with self .assertRaises (TypeError ):
64- Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , host = b'foo' )
65-
66- with self .assertRaises (TypeError ):
67- Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , host = 4 )
48+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , host = b'foo' ))
49+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , host = 4 ))
6850
6951 def test_port_should_be_number (self ):
7052 Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , port = 400 )
7153
72- with self .assertRaises (TypeError ):
73- Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , port = u'400' )
54+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , port = u'400' ))
7455
7556 def test_cluster_should_be_text (self ):
7657 Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = u'eu' )
7758
78- with self .assertRaises (TypeError ):
79- Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = b'eu' )
80-
81- with self .assertRaises (TypeError ):
82- Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = 4 )
59+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = b'eu' ))
60+ self .assertRaises (TypeError , lambda : Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = 4 ))
8361
8462 def test_host_behaviour (self ):
8563 conf = Config (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True )
@@ -105,14 +83,9 @@ def test_port_behaviour(self):
10583 self .assertEqual (conf .port , 4000 , u'the port setting override the default' )
10684
10785 def test_initialize_from_url (self ):
108- with self .assertRaises (TypeError ):
109- Config .from_url (4 )
110-
111- with self .assertRaises (TypeError ):
112- Config .from_url (b'http://foo:bar@host/apps/4' )
113-
114- with self .assertRaises (Exception ):
115- Config .from_url (u'httpsahsutaeh' )
86+ self .assertRaises (TypeError , lambda : Config .from_url (4 ))
87+ self .assertRaises (TypeError , lambda : Config .from_url (b'http://foo:bar@host/apps/4' ))
88+ self .assertRaises (Exception , lambda : Config .from_url (u'httpsahsutaeh' ))
11689
11790 conf = Config .from_url (u'http://foo:bar@host/apps/4' )
11891 self .assertEqual (conf .ssl , False )
@@ -148,14 +121,9 @@ def test_initialize_from_env(self):
148121 def test_authenticate_subscription_types (self ):
149122 conf = Config .from_url (u'http://foo:bar@host/apps/4' )
150123
151- with self .assertRaises (TypeError ):
152- conf .authenticate_subscription (b'plah' , u'34554' )
153-
154- with self .assertRaises (TypeError ):
155- conf .authenticate_subscription (u'plah' , b'324435' )
156-
157- with self .assertRaises (ValueError ):
158- conf .authenticate_subscription (u'::' , u'345345' )
124+ self .assertRaises (TypeError , lambda : conf .authenticate_subscription (b'plah' , u'34554' ))
125+ self .assertRaises (TypeError , lambda : conf .authenticate_subscription (u'plah' , b'324435' ))
126+ self .assertRaises (ValueError , lambda : conf .authenticate_subscription (u'::' , u'345345' ))
159127
160128 def test_authenticate_subscription_for_private_channels (self ):
161129 conf = Config .from_url (u'http://foo:bar@host/apps/4' )
@@ -205,23 +173,12 @@ def test_validate_webhook_bad_types(self):
205173 # sensible.
206174
207175 with mock .patch ('time.time' ) as time_mock :
208- with self .assertRaises (TypeError ):
209- conf .validate_webhook (4 , u'signature' , u'body' )
210-
211- with self .assertRaises (TypeError ):
212- conf .validate_webhook (b'test' , u'signature' , u'body' )
213-
214- with self .assertRaises (TypeError ):
215- conf .validate_webhook (u'key' , 4 , u'body' )
216-
217- with self .assertRaises (TypeError ):
218- conf .validate_webhook (u'key' , b'signature' , u'body' )
219-
220- with self .assertRaises (TypeError ):
221- conf .validate_webhook (u'key' , u'signature' , 4 )
222-
223- with self .assertRaises (TypeError ):
224- conf .validate_webhook (u'key' , u'signature' , b'body' )
176+ self .assertRaises (TypeError , lambda : conf .validate_webhook (4 , u'signature' , u'body' ))
177+ self .assertRaises (TypeError , lambda : conf .validate_webhook (b'test' , u'signature' , u'body' ))
178+ self .assertRaises (TypeError , lambda : conf .validate_webhook (u'key' , 4 , u'body' ))
179+ self .assertRaises (TypeError , lambda : conf .validate_webhook (u'key' , b'signature' , u'body' ))
180+ self .assertRaises (TypeError , lambda : conf .validate_webhook (u'key' , u'signature' , 4 ))
181+ self .assertRaises (TypeError , lambda : conf .validate_webhook (u'key' , u'signature' , b'body' ))
225182
226183 time_mock .assert_not_called ()
227184
@@ -251,7 +208,7 @@ def test_validate_webhook_bad_time(self):
251208 conf = Config .from_url (u'http://foo:bar@host/apps/4' )
252209
253210 body = u'{"time_ms": 1000000}'
254- signature = six .text_type (hmac .new (conf .secret .encode (u 'utf8' ), body .encode (u 'utf8' ), hashlib .sha256 ).hexdigest ())
211+ signature = six .text_type (hmac .new (conf .secret .encode ('utf8' ), body .encode ('utf8' ), hashlib .sha256 ).hexdigest ())
255212
256213 with mock .patch ('time.time' , return_value = 1301 ):
257214 self .assertEqual (conf .validate_webhook (conf .key , signature , body ), None )
0 commit comments