Skip to content

Commit cf05d1e

Browse files
committed
Removing sure dependency. Going back to simple nose for readability.
1 parent 67a857e commit cf05d1e

File tree

7 files changed

+85
-74
lines changed

7 files changed

+85
-74
lines changed

dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ Pygments==1.5
1111
Jinja2==2.6
1212
docutils==0.8.1
1313
Sphinx==1.1.3
14-
sure==1.2.3
1514
httpretty==0.7.0

tests/integration/test.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from intercom import Impression
2020
from intercom import Note
2121
from nose.tools import nottest
22-
from sure import expect
22+
from nose.tools import eq_
23+
from nose.tools import ok_
24+
from nose.tools import raises
2325

2426
Intercom.app_id = 'dummy-app-id'
2527
Intercom.api_key = 'dummy-secret-key'
@@ -37,47 +39,56 @@ def fixture(fixture):
3739
@httpretty.activate
3840
def test_users():
3941
httpretty.register_uri(get, r(r"/v1/users"), body=fixture('v1-users'))
40-
expect(len(User.all())).should.be.greater_than(0)
42+
ok_(len(User.all()) > 0)
4143

4244
@httpretty.activate
4345
def test_user():
4446
httpretty.register_uri(get, r(r"/v1/users\?email="), body=fixture('v1-user'), match_querystring=True)
4547
user = User.find(email='somebody@example.com')
46-
expect(user.name).to.equal('Somebody')
48+
eq_(user.name, 'Somebody')
4749

4850
httpretty.register_uri(get, r(r"/v1/users\?user_id="), body=fixture('v1-user'), match_querystring=True)
4951
user = User.find_by_user_id('123')
50-
expect(user.name).to.equal('Somebody')
52+
eq_(user.name, 'Somebody')
5153

5254
@httpretty.activate
55+
@raises(ResourceNotFound)
5356
def test_not_found():
5457
httpretty.register_uri(get, r(r"/v1/users\?email=not-found"), status=404, match_querystring=True)
55-
User.find.when.called_with(email='not-found@example.com').should.throw(ResourceNotFound)
58+
User.find(email='not-found@example.com')
5659

60+
@httpretty.activate
61+
@raises(ResourceNotFound)
62+
def test_not_found_qs():
5763
httpretty.register_uri(get, r(r"/v1/users\?email=not-found"), body=fixture('v1-user_not_found'), status=404, match_querystring=True)
58-
User.find.when.called_with(email='not-found@example.com').should.throw(ResourceNotFound)
64+
User.find(email='not-found@example.com')
5965

6066
@httpretty.activate
67+
@raises(ServerError)
6168
def test_server_error():
6269
httpretty.register_uri(get, r(r"/v1/users\?email=server-error"), status=500, match_querystring=True)
63-
User.find.when.called_with(email='server-error@example.com').should.throw(ServerError)
70+
User.find(email='server-error@example.com')
6471

72+
@httpretty.activate
73+
@raises(ServerError)
74+
def test_server_error_qs():
6575
httpretty.register_uri(get, r(r"/v1/users\?email=server-error"), body=fixture('v1-user_server_error'), status=500, match_querystring=True)
66-
User.find.when.called_with(email='server-error@example.com').should.throw(ServerError)
76+
User.find(email='server-error@example.com')
6777

6878
@httpretty.activate
79+
@raises(AuthenticationError)
6980
def test_bad_api_key():
7081
httpretty.register_uri(get, r(r"/v1/users\?email=authentication-error"), status=401, match_querystring=True)
7182
Intercom.app_id = 'bad-app-id'
7283
Intercom.api_key = 'bad-secret-key'
73-
User.find.when.called_with(email='authentication-error@example.com').should.throw(AuthenticationError)
84+
User.find(email='authentication-error@example.com')
7485

7586
@httpretty.activate
7687
def test_message_threads():
7788
httpretty.register_uri(get, r(r"/v1/users/message_threads\?email=somebody"), body=fixture('v1-users-message_threads'), match_querystring=True)
7889
thread = MessageThread.find_all(email='somebody@example.com')[0]
7990
for attr in ['thread_id', 'read', 'messages', 'created_at', 'updated_at']:
80-
expect(getattr(thread, attr)).should.be.ok
91+
ok_(getattr(thread, attr))
8192

8293
@nottest
8394
@httpretty.activate
@@ -91,15 +102,15 @@ def test_message_thread():
91102
def test_impression():
92103
httpretty.register_uri(post, r(r"/v1/users/impressions"), body=fixture('v1-users-impressions'))
93104
impression = Impression.create(email='somebody@example.com')
94-
expect(impression.unread_messages).should.be.greater_than(0)
95-
# expect(impression.email).to.equal('somebody@example.com')
105+
ok_(impression.unread_messages > 0)
106+
# eq_(impression.email, 'somebody@example.com')
96107

97108
@httpretty.activate
98109
def test_note():
99110
httpretty.register_uri(post, r(r"/v1/users/notes"), body=fixture('v1-users-note'))
100111
note = Note.create(body="This is a note", email='somebody@example.com')
101-
expect(note.html).to.equal("<p>This is a note</p>")
102-
expect(note.user.email).to.equal("somebody@example.com")
112+
eq_(note.html, "<p>This is a note</p>")
113+
eq_(note.user.email, "somebody@example.com")
103114

104115
@nottest
105116
@httpretty.activate
@@ -108,7 +119,7 @@ def test_endpoints():
108119
httpretty.register_uri(get, r(r"/v1/users\?email="), body=fixture('v1-user'), match_querystring=True)
109120
Intercom.endpoints = ("http://127.0.0.7", "https://api.intercom.io")
110121
user = User.find(email='somebody@example.com')
111-
expect(user.name).to.equal('Somebody')
122+
eq_(user.name, 'Somebody')
112123

113124
@nottest
114125
@httpretty.activate
@@ -170,19 +181,19 @@ def request_callback(method, uri, headers):
170181
httpretty.register_uri(post, r(r"/v1/users/impressions"), body=fixture('v1-users-impressions'))
171182

172183
(failure_count, test_count) = doctest.testfile("../../intercom/user.py")
173-
expect(failure_count).to.equal(0)
184+
eq_(failure_count, 0)
174185

175186
(failure_count, test_count) = doctest.testfile("../../intercom/tag.py")
176-
expect(failure_count).to.equal(0)
187+
eq_(failure_count, 0)
177188

178189
(failure_count, test_count) = doctest.testfile("../../intercom/note.py")
179-
expect(failure_count).to.equal(0)
190+
eq_(failure_count, 0)
180191

181192
(failure_count, test_count) = doctest.testfile("../../intercom/message_thread.py")
182-
expect(failure_count).to.equal(0)
193+
eq_(failure_count, 0)
183194

184195
(failure_count, test_count) = doctest.testfile("../../intercom/impression.py")
185-
expect(failure_count).to.equal(0)
196+
eq_(failure_count, 0)
186197

187198
(failure_count, test_count) = doctest.testfile("../../intercom/intercom.py")
188-
expect(failure_count).to.equal(0)
199+
eq_(failure_count, 0)

tests/unit/test_impression.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77

88
from intercom import Impression
9-
from sure import expect
9+
from nose.tools import eq_
1010

1111

1212
def test_properties():
@@ -15,6 +15,6 @@ def test_properties():
1515
impression.location = 'http://example.com/profile/'
1616
impression.user_agent = 'Mozilla/5.0'
1717

18-
expect(impression.user_ip).to.equal('192.168.1.100')
19-
expect(impression.location).to.equal('http://example.com/profile/')
20-
expect(impression.user_agent).to.equal('Mozilla/5.0')
18+
eq_(impression.user_ip, '192.168.1.100')
19+
eq_(impression.location, 'http://example.com/profile/')
20+
eq_(impression.user_agent, 'Mozilla/5.0')

tests/unit/test_message_thread.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
#
77

88
from intercom.message_thread import MessageThread
9-
from sure import expect
9+
from nose.tools import eq_
10+
from nose.tools import raises
1011

1112

13+
@raises(ValueError)
1214
def test_find_no_thread_id():
13-
MessageThread.find.when.called_with(email='xxx@example.com')\
14-
.should.throw(ValueError)
15+
MessageThread.find(email='xxx@example.com')
1516

1617

1718
def test_properties():
@@ -20,8 +21,8 @@ def test_properties():
2021
message_thread.read = False
2122
message_thread.body = 'ABCDE'
2223

23-
expect(message_thread.thread_id).to.equal(12345)
24-
expect(message_thread.read).to.equal(False)
24+
eq_(message_thread.thread_id, 12345)
25+
eq_(message_thread.read, False)
2526

2627
try:
2728
message_thread.body

tests/unit/test_note.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from datetime import datetime
88
from intercom import Note
9-
from sure import expect
9+
from nose.tools import eq_
1010

1111

1212
def test_properties():
@@ -16,6 +16,6 @@ def test_properties():
1616
note.user_id = '123'
1717
note.created_at = datetime.fromtimestamp(1331764344)
1818

19-
expect(note.body).to.equal('xxx')
20-
expect(note.email).to.equal('xxx@example.com')
21-
expect(note.user_id).to.equal('123')
19+
eq_(note.body, 'xxx')
20+
eq_(note.email, 'xxx@example.com')
21+
eq_(note.user_id, '123')

tests/unit/test_tag.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77

88
from intercom.tag import Tag
9-
from sure import expect
9+
from nose.tools import eq_
1010
from nose.tools import raises
1111

1212

@@ -19,7 +19,7 @@ def test_writeonly_emails():
1919
def test_write_emails():
2020
tag = Tag()
2121
tag.emails = ["joe@example.com"]
22-
expect(tag['emails']).to.equal(["joe@example.com"])
22+
eq_(tag['emails'], ["joe@example.com"])
2323

2424

2525
@raises(AttributeError)
@@ -31,7 +31,7 @@ def test_writeonly_user_ids():
3131
def test_write_user_ids():
3232
tag = Tag()
3333
tag.user_ids = ["abc123"]
34-
expect(tag['user_ids']).to.equal(["abc123"])
34+
eq_(tag['user_ids'], ["abc123"])
3535

3636

3737
@raises(AttributeError)
@@ -43,7 +43,7 @@ def test_writeonly_tag_or_untag():
4343
def test_write_tag_or_untag():
4444
tag = Tag()
4545
tag.tag_or_untag = "tag"
46-
expect(tag['tag_or_untag']).to.equal("tag")
46+
eq_(tag['tag_or_untag'], "tag")
4747

4848

4949
@raises(AttributeError)
@@ -72,4 +72,4 @@ def test_readonly_id():
7272
def test_accessor():
7373
tag = Tag()
7474
tag.name = "xyz"
75-
expect(tag.name).to.equal("xyz")
75+
eq_(tag.name, "xyz")

tests/unit/test_user.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
from intercom.user import SocialProfile
1212
from intercom.user import User
1313
from intercom.user import Company
14+
from nose.tools import eq_
1415
from nose.tools import raises
15-
from sure import expect
1616

1717

1818
def test_init_no_arg():
1919
# no arg __init__
2020
custom_data = CustomData()
21-
expect(len(custom_data)).to.equal(0)
21+
eq_(0, len(custom_data))
2222

2323

2424
def test_init_dict_arg():
2525
# dict arg __init__
2626
custom_data = CustomData({'color': 'red'})
27-
expect(len(custom_data)).to.equal(1)
27+
eq_(1, len(custom_data))
2828

2929

3030
def test_string_key():
@@ -86,10 +86,10 @@ def test_attr():
8686
}
8787

8888
social_profile = SocialProfile(sc_dict)
89-
expect(social_profile.type).to.equal('twitter')
90-
expect(social_profile.url).to.equal('http://twitter.com/myname')
91-
expect(social_profile.username).to.equal('myname')
92-
expect(social_profile.id).to.equal('123456789')
89+
eq_('twitter', social_profile.type)
90+
eq_('http://twitter.com/myname', social_profile.url)
91+
eq_('myname', social_profile.username)
92+
eq_('123456789', social_profile.id)
9393

9494

9595
@raises(NotImplementedError)
@@ -125,18 +125,18 @@ def test_user_properties():
125125
except AttributeError:
126126
pass
127127

128-
expect(user.email).to.equal('somebody@example.com')
129-
expect(user.user_id).to.equal(1234)
130-
expect(user.name).to.equal('Somebody')
131-
expect(user.last_seen_ip).to.equal('192.168.1.100')
132-
expect(user.last_seen_user_agent).to.equal('Mozilla/5.0')
133-
expect(user.last_request_at).to.equal(last_request_at)
134-
expect(user.last_impression_at).to.equal(last_impression_at)
135-
expect(user.relationship_score).to.equal(None)
136-
expect(user.created_at).to.equal(created_at)
137-
expect(user.unsubscribed_from_emails).to.equal(True)
138-
expect(user.custom_data['name']).to.equal('Ace')
139-
expect(user.session_count).to.equal(0)
128+
eq_(user.email, 'somebody@example.com')
129+
eq_(user.user_id, 1234)
130+
eq_(user.name, 'Somebody')
131+
eq_(user.last_seen_ip, '192.168.1.100')
132+
eq_(user.last_seen_user_agent, 'Mozilla/5.0')
133+
eq_(user.last_request_at, last_request_at)
134+
eq_(user.last_impression_at, last_impression_at)
135+
eq_(user.relationship_score, None)
136+
eq_(user.created_at, created_at)
137+
eq_(user.unsubscribed_from_emails, True)
138+
eq_(user.custom_data['name'], 'Ace')
139+
eq_(user.session_count, 0)
140140
raises(AttributeError, lambda: user.companies)
141141

142142

@@ -147,16 +147,16 @@ def test_company_properties():
147147
'created_at': 1331764344
148148
}
149149
company = Company(c_dict)
150-
expect(company.id).to.equal(1)
151-
expect(company.name).to.equal('Intercom')
152-
expect(company.created_at).to.equal(datetime.fromtimestamp(1331764344))
150+
eq_(company.id, 1)
151+
eq_(company.name, 'Intercom')
152+
eq_(company.created_at, datetime.fromtimestamp(1331764344))
153153

154154
company.id = 100
155155
company.name = 'ACME Inc.'
156156
company.created_at = datetime.fromtimestamp(1331764300)
157-
expect(company.id).to.equal(100)
158-
expect(company.name).to.equal('ACME Inc.')
159-
expect(company.created_at).to.equal(datetime.fromtimestamp(1331764300))
157+
eq_(company.id, 100)
158+
eq_(company.name, 'ACME Inc.')
159+
eq_(company.created_at, datetime.fromtimestamp(1331764300))
160160

161161

162162
@raises(ValueError)
@@ -215,12 +215,12 @@ def test_location_properties():
215215
"country_code": "CHL"
216216
})
217217

218-
expect(location_data.city_name).to.equal('Santiago')
219-
expect(location_data.continent_code).to.equal('SA')
220-
expect(location_data.country_name).to.equal('Chile')
221-
expect(location_data.latitude).to.equal(-33.44999999999999)
222-
expect(location_data.longitude).to.equal(-70.6667)
223-
expect(location_data.postal_code).to.equal('')
224-
expect(location_data.region_name).to.equal('12')
225-
expect(location_data.timezone).to.equal('Chile/Continental')
226-
expect(location_data.country_code).to.equal('CHL')
218+
eq_(location_data.city_name, 'Santiago')
219+
eq_(location_data.continent_code, 'SA')
220+
eq_(location_data.country_name, 'Chile')
221+
eq_(location_data.latitude, -33.44999999999999)
222+
eq_(location_data.longitude, -70.6667)
223+
eq_(location_data.postal_code, '')
224+
eq_(location_data.region_name, '12')
225+
eq_(location_data.timezone, 'Chile/Continental')
226+
eq_(location_data.country_code, 'CHL')

0 commit comments

Comments
 (0)