8000 Only provide the base level exception · pythonthings/github3.py@6e30d06 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e30d06

Browse files
committed
Only provide the base level exception
1 parent 2d5e615 commit 6e30d06

File tree

8 files changed

+58
-116
lines changed

8 files changed

+58
-116
lines changed

github3/__init__.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,13 @@
5151
zen
5252
)
5353
from .github import GitHub, GitHubEnterprise, GitHubStatus
54-
from .exceptions import (
55-
BadRequest, AuthenticationFailed, ForbiddenError, GitHubError,
56-
MethodNotAllowed, NotFoundError, ServerError, NotAcceptable,
57-
UnprocessableEntity
58-
)
54+
from .exceptions import GitHubError
5955

6056
__all__ = (
61-
'AuthenticationFailed',
62-
'BadRequest',
63-
'ForbiddenError',
6457
'GitHub',
6558
'GitHubEnterprise',
6659
'GitHubError',
6760
'GitHubStatus',
68-
'MethodNotAllowed',
69-
'NotAcceptable',
70-
'NotFoundError',
71-
'ServerError',
72-
'UnprocessableEntity',
7361
'authorize',
7462
'login',
7563
'enterprise_login',

tests/unit/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ def after_setup(self):
217217
self.session.auth = None
218218
self.session.has_auth.return_value = False
219219

220-
def assert_requires_auth(self, func):
220+
def assert_requires_auth(self, func, *args, **kwargs):
221221
"""
222222
Assert error is raised if function is called without
223223
authentication.
224224
"""
225-
with pytest.raises(github3.AuthenticationFailed):
226-
func()
225+
with pytest.raises(github3.exceptions.AuthenticationFailed):
226+
func(*args, **kwargs)
227227

228228

229229
class UnitGitHubObjectHelper(UnitHelper):

tests/unit/test_auths.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Unit tests for the auths module."""
22
import github3
3-
import pytest
43

54
from . import helper
65

@@ -62,20 +61,16 @@ def after_setup(self):
6261

6362
def test_add_scopes(self):
6463
"""Test that adding scopes requires authentication."""
65-
with pytest.raises(github3.AuthenticationFailed):
66-
self.instance.add_scopes()
64+
self.assert_requires_auth(self.instance.add_scopes)
6765

6866
def test_delete(self):
6967
"""Test that deleteing an authorization requires authentication."""
70-
with pytest.raises(github3.AuthenticationFailed):
71-
self.instance.delete()
68+
self.assert_requires_auth(self.instance.delete)
7269

7370
def test_remove_scopes(self):
7471
"""Test that removing scopes requires authentication."""
75-
with pytest.raises(github3.AuthenticationFailed):
76-
self.instance.remove_scopes()
72+
self.assert_requires_auth(self.instance.remove_scopes)
7773

7874
def test_replace_scopes(self):
7975
"""Test that replacing scopes requires authentication."""
80-
with pytest.raises(github3.AuthenticationFailed):
81-
self.instance.replace_scopes()
76+
self.assert_requires_auth(self.instance.replace_scopes)

tests/unit/test_github.py

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from github3 import AuthenticationFailed, GitHubEnterprise, GitHubError
3+
from github3 import GitHubEnterprise, GitHubError
44
from github3.github import GitHub, GitHubStatus
55

66
from . import helper
@@ -1232,138 +1232,113 @@ class TestGitHubRequiresAuthentication(
12321232

12331233
def test_add_email_addresses(self):
12341234
"""Verify a user must be authenticated to add email addresses."""
1235-
with pytest.raises(AuthenticationFailed):
1236-
self.instance.add_email_addresses([])
1235+
self.assert_requires_auth(self.instance.add_email_addresses, [])
12371236

12381237
def test_authorization(self):
12391238
"""A user must be authenticated to retrieve an authorization."""
1240-
with pytest.raises(AuthenticationFailed):
1241-
self.instance.authorization(1)
1239+
self.assert_requires_auth(self.instance.authorization, 1)
12421240

12431241
def test_authorizations(self):
12441242
"""Show that one needs to authenticate to use #authorizations."""
1245-
with pytest.raises(AuthenticationFailed):
1246-
self.instance.authorizations()
1243+
self.assert_requires_auth(self.instance.authorizations)
12471244

12481245
def test_create_issue(self):
12491246
"""Show that GitHub#create_issue requires auth."""
1250-
with pytest.raises(AuthenticationFailed):
1251-
self.instance.create_issue('owner', 'repo', 'title')
1247+
self.assert_requires_auth(self.instance.create_issue,
1248+
'owner', 'repo', 'title')
12521249

12531250
def test_create_key(self):
12541251
"""Show that GitHub#create_key requires auth."""
1255-
with pytest.raises(AuthenticationFailed):
1256-
self.instance.create_key('title', 'key')
1252+
self.assert_requires_auth(self.instance.create_key, 'title', 'key')
12571253

12581254
def test_create_repository(self):
12591255
"""Show that GitHub#create_repository requires auth."""
1260-
with pytest.raises(AuthenticationFailed):
1261-
self.instance.create_repository('repo')
1256+
self.assert_requires_auth(self.instance.create_repository, 'repo')
12621257

12631258
def test_delete_email_addresses(self):
12641259
"""Verify a user must be authenticated to delete email addresses."""
1265-
with pytest.raises(AuthenticationFailed):
1266-
self.instance.delete_email_addresses([])
1260+
self.assert_requires_auth(self.instance.delete_email_addresses, [])
12671261

12681262
def test_emails(self):
12691263
"""Show that one needs to authenticate to use #emails."""
1270-
with pytest.raises(AuthenticationFailed):
1271-
self.instance.emails()
1264+
self.assert_requires_auth(self.instance.emails)
12721265

12731266
def test_feeds(self):
12741267
"""Show that one needs to authenticate to use #feeds."""
1275-
with pytest.raises(AuthenticationFailed):
1276-
self.instance.feeds()
1268+
self.assert_requires_auth(self.instance.feeds)
12771269

12781270
def test_follow(self):
12791271
"""Show that one needs to authenticate to use #follow."""
1280-
with pytest.raises(AuthenticationFailed):
1281-
self.instance.follow('foo')
1272+
self.assert_requires_auth(self.instance.follow, 'foo')
12821273

12831274
def test_gists(self):
12841275
"""Show that one needs to authenticate to use #gists."""
1285-
with pytest.raises(AuthenticationFailed):
1286-
self.instance.gists()
1276+
self.assert_requires_auth(self.instance.gists)
12871277

12881278
def test_is_following(self):
12891279
"""Show that GitHub#is_following requires authentication."""
1290-
with pytest.raises(AuthenticationFailed):
1291-
self.instance.is_following('foo')
1280+
self.assert_requires_auth(self.instance.is_following, 'foo')
12921281

12931282
def test_is_starred(self):
12941283
"""Show that GitHub#is_starred requires authentication."""
1295-
with pytest.raises(AuthenticationFailed):
1296-
self.instance.is_starred('foo', 'bar')
1284+
self.assert_requires_auth(self.instance.is_starred, 'foo', 'bar')
12971285

12981286
def test_issues(self):
12991287
"""Show that one needs to authenticate to use #issues."""
1300-
with pytest.raises(AuthenticationFailed):
1301-
self.instance.issues()
1288+
self.assert_requires_auth(self.instance.issues)
13021289

13031290
def test_key(self):
13041291
"""Show that retrieving user key requires authentication."""
1305-
with pytest.raises(AuthenticationFailed):
1306-
self.instance.key(1)
1292+
self.assert_requires_auth(self.instance.key, 1)
13071293

13081294
def test_keys(self):
13091295
"""Show that one needs to authenticate to use #keys."""
1310-
with pytest.raises(AuthenticationFailed):
1311-
self.instance.keys()
1296+
self.assert_requires_auth(self.instance.keys)
13121297

13131298
def test_me(self):
13141299
"""Show that GitHub#me requires authentication."""
1315-
with pytest.raises(AuthenticationFailed):
1316-
self.instance.me()
1300+
self.assert_requires_auth(self.instance.me)
13171301

13181302
def test_notifications(self):
13191303
"""Show that one needs to authenticate to use #gists."""
1320-
with pytest.raises(AuthenticationFailed):
1321-
self.instance.notifications()
1304+
self.assert_requires_auth(self.instance.notifications)
13221305

13231306
def test_organization_issues(self):
13241307
"""Show that one needs to authenticate to use #organization_issues."""
1325-
with pytest.raises(AuthenticationFailed):
1326-
self.instance.organization_issues('org')
1308+
self.assert_requires_auth(self.instance.organization_issues, 'org')
13271309

13281310
def test_organizations(self):
13291311
"""Show that one needs to authenticate to use #organizations."""
1330-
with pytest.raises(AuthenticationFailed):
1331-
self.instance.organizations()
1312+
self.assert_requires_auth(self.instance.organizations)
13321313

13331314
def test_pubsubhubbub(self):
13341315
"""Show that one needs to authenticate to use pull request."""
1335-
with pytest.raises(AuthenticationFailed):
1336-
self.instance.pubsubhubbub(mode='', topic='', callback='')
1316+
self.assert_requires_auth(self.instance.pubsubhubbub,
1317+
mode='', topic='', callback='')
13371318

13381319
def test_repositories(self):
13391320
"""Show that one needs to authenticate to use #repositories."""
1340-
with pytest.raises(AuthenticationFailed):
1341-
self.instance.repositories()
1321+
self.assert_requires_auth(self.instance.repositories)
13421322

13431323
def test_star(self):
13441324
"""Show that starring a repository requires authentication."""
1345-
with pytest.raises(AuthenticationFailed):
1346-
self.instance.star(username='', repo='')
1325+
self.assert_requires_auth(self.instance.star, username='', repo='')
13471326

13481327
def test_starred(self):
13491328
"""Show that one needs to authenticate to use #starred."""
1350-
with pytest.raises(AuthenticationFailed):
1351-
self.instance.starred()
1329+
self.assert_requires_auth(self.instance.starred)
13521330

13531331
def test_unfollow(self):
13541332
"""Show that unfollowing a user requires authentication."""
1355-
with pytest.raises(AuthenticationFailed):
1356-
self.instance.unfollow('foo')
1333+
self.assert_requires_auth(self.instance.unfollow, 'foo')
13571334

13581335
def test_unstar(self):
13591336
"""Show that unstarring requires authentication."""
1360-
with pytest.raises(AuthenticationFailed):
1361-
self.instance.unstar(username='', repo='')
1337+
self.assert_requires_auth(self.instance.unstar, username='', repo='')
13621338

13631339
def test_user_issues(self):
13641340
"""Show that GitHub#user_issues requires authentication."""
1365-
with pytest.raises(AuthenticationFailed):
1366-
self.instance.user_issues()
1341+
self.assert_requires_auth(self.instance.user_issues)
13671342

13681343

13691344
class TestGitHubAuthorizations(helper.UnitHelper):

tests/unit/test_issues_issue.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Unit tests for the Issue class."""
22
import github3
3-
import pytest
43
import mock
54

65
from github3.issues.label import Label
@@ -31,7 +30,7 @@
3130
)
3231

3332

34-
class TestIssueRequiresAuth(helper.UnitHelper):
33+
class TestIssueRequiresAuth(helper.UnitRequiresAuthenticationHelper):
3534

3635
"""Test Issue methods that require Authentication."""
3736

@@ -43,53 +42,44 @@ def after_setup(self):
4342

4443
def test_add_labels(self):
4544
"""Verify that adding a label requires authentication."""
46-
with pytest.raises(github3.AuthenticationFailed):
47-
self.instance.add_labels('enhancement')
45+
self.assert_requires_auth(self.instance.add_labels, 'enhancement')
4846

4947
def test_assign(self):
5048
"""Verify that assigning an issue requires authentication."""
51-
with pytest.raises(github3.AuthenticationFailed):
52-
self.instance.assign('sigmavirus24')
49+
self.assert_requires_auth(self.instance.assign, 'sigmavirus24')
5350

5451
def test_close(self):
5552
"""Verify that closing an issue requires authentication."""
56-
with pytest.raises(github3.AuthenticationFailed):
57-
self.instance.close()
53+
self.assert_requires_auth(self.instance.close)
5854

5955
def test_create_comment(self):
6056
"""Verify that creating a comment requires authentication."""
61-
with pytest.raises(github3.AuthenticationFailed):
62-
self.instance.create_comment(body='comment body')
57+
self.assert_requires_auth(self.instance.create_comment,
58+
body='comment body')
6359

6460
def test_edit_comment(self):
6561
"""Verify that editing a comment requires authentication."""
66-
with pytest.raises(github3.AuthenticationFailed):
67-
self.instance.edit()
62+
self.assert_requires_auth(self.instance.edit)
6863

6964
def test_lock(self):
7065
"""Verify that locking an issue requires authentication."""
71-
with pytest.raises(github3.AuthenticationFailed):
72-
self.instance.lock()
66+
self.assert_requires_auth(self.instance.lock)
7367

7468
def test_remove_all_labels(self):
7569
"""Verify that removing all labels requires authentication."""
76-
with pytest.raises(github3.AuthenticationFailed):
77-
self.instance.remove_all_labels()
70+
self.assert_requires_auth(self.instance.remove_all_labels)
7871

7972
def test_remove_label(self):
8073
"""Verify that removing a label requires authentication."""
81-
with pytest.raises(github3.AuthenticationFailed):
82-
self.instance.remove_label('enhancement')
74+
self.assert_requires_auth(self.instance.remove_label, 'enhancement')
8375

8476
def test_reopen(self):
8577
"""Verify that reopening an issue equires authentication."""
86-
with pytest.raises(github3.AuthenticationFailed):
87-
self.instance.reopen()
78+
self.assert_requires_auth(self.instance.reopen)
8879

8980
def test_unlock(self):
9081
"""Verify that unlocking an issue requires authentication."""
91-
with pytest.raises(github3.AuthenticationFailed):
92-
self.instance.unlock()
82+
self.assert_requires_auth(self.instance.unlock)
9383

9484

9585
class TestIssue(helper.UnitHelper):
@@ -369,8 +359,7 @@ class TestLabelRequiresAuth(helper.UnitRequiresAuthenticationHelper):
369359

370360
def test_delete(self):
371361
"""Test that deleting a label requires authentication."""
372-
with pytest.raises(github3.AuthenticationFailed):
373-
self.instance.delete()
362+
self.assert_requires_auth(self.instance.delete)
374363

375364
def test_update(self):
376365
"""Test that updating label requires authentication."""
@@ -379,8 +368,7 @@ def test_update(self):
379368
'color': 'afafaf'
380369
}
381370

382-
with pytest.raises(github3.AuthenticationFailed):
383-
self.instance.update(**data)
371+
self.assert_requires_auth(self.instance.update, **data)
384372

385373

386374
class TestLabel(helper.UnitHelper):

tests/unit/test_issues_milestone.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Unit tests for the Milestone class."""
22
import datetime
33
import github3
4-
import pytest
54

65
from . import helper
76

@@ -22,8 +21,7 @@ class TestMilestoneRequiresAuth(helper.UnitRequiresAuthenticationHelper):
2221

2322
def test_delete(self):
2423
"""Test that deleting milestone requires authentication."""
25-
with pytest.raises(github3.AuthenticationFailed):
26-
self.instance.delete()
24+
self.assert_requires_auth(self.instance.delete)
2725

2826
def test_update(self):
2927
"""Test that updating a milestone requires authentication."""
@@ -33,8 +31,7 @@ def test_update(self):
3331
'description': ':sparkles:',
3432
'due_on': '2013-12-31T23:59:59Z'
3533
}
36-
with pytest.raises(github3.AuthenticationFailed):
37-
self.instance.update(**data)
34+
self.assert_requires_auth(self.instance.update, **data)
3835

3936

4037
class TestMilestone(helper.UnitHelper):

tests/unit/test_users.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ class TestUserKeyRequiresAuth(helper.UnitRequiresAuthenticationHelper):
7171

7272
def test_update(self):
7373
"""Test that updating a key requires authentication."""
74-
with pytest.raises(github3.AuthenticationFailed):
75-
self.instance.update(title='New Title', key='Fake key')
74+
self.assert_requires_auth(self.instance.update, title='New Title',
75+
key='Fake key')
7676

7777
def test_delete(self):
7878
"""Test that deleting a key requires authentication."""
79-
with pytest.raises(github3.AuthenticationFailed):
80-
self.instance.delete()
79+
self.assert_requires_auth(self.instance.delete)
8180

8281

8382
class TestUserKey(helper.UnitHelper):

0 commit comments

Comments
 (0)
0