Skip to content

Commit 2e6330a

Browse files
committed
Flake8ing the module.
1 parent a190549 commit 2e6330a

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

tests/unit/user_spec.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
13
import httpretty
24
import json
3-
import re
45
import mock
6+
import re
57
import time
68

7-
from describe import expect
89
from datetime import datetime
10+
from describe import expect
911
from intercom.collection_proxy import CollectionProxy
1012
from intercom.lib.flat_store import FlatStore
1113
from intercom.user import User
@@ -22,10 +24,11 @@
2224

2325
class DescribeIntercomUser:
2426

25-
2627
def it_to_dict_itself(self):
2728
created_at = datetime.utcnow()
28-
user = User(email="jim@example.com", user_id="12345", created_at=created_at, name="Jim Bob")
29+
user = User(
30+
email="jim@example.com", user_id="12345",
31+
created_at=created_at, name="Jim Bob")
2932
as_dict = user.to_dict
3033
expect(as_dict["email"]) == "jim@example.com"
3134
expect(as_dict["user_id"]) == "12345"
@@ -35,13 +38,14 @@ def it_to_dict_itself(self):
3538
def it_presents_created_at_and_last_impression_at_as_datetime(self):
3639
now = datetime.utcnow()
3740
now_ts = time.mktime(now.timetuple())
38-
user = User.from_api({'created_at': now_ts, 'last_impression_at': now_ts})
41+
user = User.from_api(
42+
{'created_at': now_ts, 'last_impression_at': now_ts})
3943
expect(user.created_at).to.be_instance_of(datetime)
4044
expect(now.strftime('%c')) == user.created_at.strftime('%c')
4145
expect(user.last_impression_at).to.be_instance_of(datetime)
4246
expect(now.strftime('%c')) == user.last_impression_at.strftime('%c')
4347

44-
def it_throws_an_attribute_error_on_trying_to_access_an_attribute_that_has_not_been_set(self):
48+
def it_throws_an_attribute_error_on_trying_to_access_an_attribute_that_has_not_been_set(self): # noqa
4549
with expect.to_raise_error(AttributeError):
4650
user = User()
4751
user.foo_property
@@ -57,12 +61,13 @@ def it_presents_a_complete_user_record_correctly(self):
5761
expect(1393613864) == time.mktime(user.remote_created_at.timetuple())
5862
expect(1401970114) == time.mktime(user.updated_at.timetuple())
5963

60-
Avatar = create_class_instance('Avatar')
61-
Company = create_class_instance('Company')
62-
SocialProfile = create_class_instance('SocialProfile')
63-
LocationData = create_class_instance('LocationData')
64+
Avatar = create_class_instance('Avatar') # noqa
65+
Company = create_class_instance('Company') # noqa
66+
SocialProfile = create_class_instance('SocialProfile') # noqa
67+
LocationData = create_class_instance('LocationData') # noqa
6468
expect(user.avatar).to.be_instance_of(Avatar.__class__)
65-
expect('https://graph.facebook.com/1/picture?width=24&height=24') == user.avatar.image_url
69+
img_url = 'https://graph.facebook.com/1/picture?width=24&height=24'
70+
expect(img_url) == user.avatar.image_url
6671

6772
expect(user.companies).to.be_instance_of(list)
6873
expect(1) == len(user.companies)
@@ -71,21 +76,24 @@ def it_presents_a_complete_user_record_correctly(self):
7176
expect('bbbbbbbbbbbbbbbbbbbbbbbb') == user.companies[0].id
7277
expect('the-app-id') == user.companies[0].app_id
7378
expect('Company 1') == user.companies[0].name
74-
expect(1390936440) == time.mktime(user.companies[0].remote_created_at.timetuple())
75-
expect(1401970114) == time.mktime(user.companies[0].created_at.timetuple())
76-
expect(1401970114) == time.mktime(user.companies[0].updated_at.timetuple())
77-
expect(1401970113) == time.mktime(user.companies[0].last_request_at.timetuple())
79+
expect(1390936440) == time.mktime(
80+
user.companies[0].remote_created_at.timetuple())
81+
expect(1401970114) == time.mktime(
82+
user.companies[0].created_at.timetuple())
83+
expect(1401970114) == time.mktime(
84+
user.companies[0].updated_at.timetuple())
85+
expect(1401970113) == time.mktime(
86+
user.companies[0].last_request_at.timetuple())
7887
expect(0) == user.companies[0].monthly_spend
7988
expect(0) == user.companies[0].session_count
8089
expect(1) == user.companies[0].user_count
8190
expect([]) == user.companies[0].tag_ids
8291

83-
8492
expect(user.custom_attributes).to.be_instance_of(FlatStore)
8593
expect('b') == user.custom_attributes["a"]
8694
expect(2) == user.custom_attributes["b"]
8795

88-
expect(4) == len(user.social_profiles)
96+
expect(4) == len(user.social_profiles)
8997
twitter_account = user.social_profiles[0]
9098
expect(twitter_account).to.be_instance_of(SocialProfile.__class__)
9199
expect('twitter') == twitter_account.name
@@ -101,7 +109,7 @@ def it_presents_a_complete_user_record_correctly(self):
101109
expect('IRL') == user.location_data.country_code
102110

103111
expect(user.unsubscribed_from_emails)
104-
expect("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11") == user.user_agent_data
112+
expect("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11") == user.user_agent_data # noqa
105113

106114
def it_allows_update_last_request_at(self):
107115
payload = {
@@ -120,7 +128,8 @@ def it_allows_easy_setting_of_custom_data(self):
120128
user.custom_attributes["mad"] = 123
121129
user.custom_attributes["other"] = now_ts
122130
user.custom_attributes["thing"] = "yay"
123-
expect(user.to_dict["custom_attributes"]) == {"mad": 123, "other": now_ts, "thing": "yay"}
131+
attrs = {"mad": 123, "other": now_ts, "thing": "yay"}
132+
expect(user.to_dict["custom_attributes"]) == attrs
124133

125134
def it_allows_easy_setting_of_multiple_companies(self):
126135
user = User()
@@ -137,10 +146,10 @@ def it_rejects_nested_data_structures_in_custom_attributes(self):
137146
user.custom_attributes["thing"] = [1]
138147

139148
with expect.to_raise_error(ValueError):
140-
user.custom_attributes["thing"] = { 1: 2 }
149+
user.custom_attributes["thing"] = {1: 2}
141150

142151
with expect.to_raise_error(ValueError):
143-
user.custom_attributes = { 1: { 2: 3}}
152+
user.custom_attributes = {1: {2: 3}}
144153

145154
user = User.from_api(test_user())
146155
with expect.to_raise_error(ValueError):
@@ -160,7 +169,7 @@ def it_fetches_a_user(self):
160169
@httpretty.activate
161170
def it_saves_a_user_always_sends_custom_attributes(self):
162171
user = User(email="jo@example.com", user_id="i-1224242")
163-
172+
164173
body = json.dumps({
165174
'email': 'jo@example.com',
166175
'user_id': 'i-1224242',
@@ -272,7 +281,7 @@ def it_allows_setting_dates_to_none_without_converting_them_to_0(self):
272281
}
273282
httpretty.register_uri(post, r("/users"), body=json.dumps(payload))
274283
user = User.create(email="jo@example.com", remote_created_at=None)
275-
expect(user.remote_created_at) == None
284+
expect(user.remote_created_at) is None
276285

277286
@httpretty.activate
278287
def it_gets_sets_rw_keys(self):
@@ -298,8 +307,8 @@ def it_will_allow_extra_attributes_in_response_from_api(self):
298307
user = User.from_api({'new_param': 'some value'})
299308
expect('some value') == user.new_param
300309

301-
def it_returns_a_CollectionProxy_for_all_without_making_any_requests(self):
302-
with mock.patch('intercom.Intercom.send_request_to_path', new_callable=mock.NonCallableMock):
310+
def it_returns_a_collectionproxy_for_all_without_making_any_requests(self):
311+
with mock.patch('intercom.Intercom.send_request_to_path', new_callable=mock.NonCallableMock): # noqa
303312
res = User.all()
304313
expect(res).to.be_instance_of(CollectionProxy)
305314

@@ -340,7 +349,7 @@ def it_can_increment_new_custom_data_fields(self):
340349
self.user.increment('new_field', 3)
341350
expect(self.user.to_dict['custom_attributes']['new_field']) == 3
342351

343-
def it_can_call_increment_on_the_same_key_twice_and_increment_by_2(self):
352+
def it_can_call_increment_on_the_same_key_twice_and_increment_by_2(self): # noqa
344353
self.user.increment('mad')
345354
self.user.increment('mad')
346355
expect(self.user.to_dict['custom_attributes']['mad']) == 125

0 commit comments

Comments
 (0)