forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_auths.py
More file actions
80 lines (57 loc) · 2.57 KB
/
Copy pathtest_auths.py
File metadata and controls
80 lines (57 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Unit tests for the auths module."""
import github3
from . import helper
url_for = helper.create_url_helper("https://api.github.com/authorizations/1")
class TestAuthorization(helper.UnitHelper):
"""Authorization unit tests."""
described_class = github3.auths.Authorization
get_auth_example_data = helper.create_example_data_helper(
"authorization_example"
)
example_data = get_auth_example_data()
def test_add_scopes(self):
"""Test the request to add scopes to an authorization."""
self.instance.add_scopes(["scope-one", "scope-two"])
self.post_called_with(
url_for(""), data={"add_scopes": ["scope-one", "scope-two"]}
)
def test_delete(self):
"""Test the request to delete an authorization."""
self.instance.delete()
self.session.delete.assert_called_once_with(url_for(""))
def test_remove_scopes(self):
"""Test the request to remove scopes from an authorization."""
self.instance.remove_scopes(["scope-one", "scope-two", "scope-three"])
self.post_called_with(
url_for(""),
data={"rm_scopes": ["scope-one", "scope-two", "scope-three"]},
)
def test_replace_scopes(self):
"""Test the request to replace the scopes on an authorization."""
self.instance.replace_scopes(
["scope-one", "scope-two", "scope-three"]
)
self.post_called_with(
url_for(""),
data={"scopes": ["scope-one", "scope-two", "scope-three"]},
)
class TestAuthorizationRequiresAuth(helper.UnitRequiresAuthenticationHelper):
"""Test methods that require authentication on Authorization."""
described_class = github3.auths.Authorization
example_data = TestAuthorization.example_data.copy()
def after_setup(self):
"""Disable authentication on the Session."""
self.session.has_auth.return_value = False
self.session.auth = None
def test_add_scopes(self):
"""Test that adding scopes requires authentication."""
self.assert_requires_auth(self.instance.add_scopes)
def test_delete(self):
"""Test that deleteing an authorization requires authentication."""
self.assert_requires_auth(self.instance.delete)
def test_remove_scopes(self):
"""Test that removing scopes requires authentication."""
self.assert_requires_auth(self.instance.remove_scopes)
def test_replace_scopes(self):
"""Test that replacing scopes requires authentication."""
self.assert_requires_auth(self.instance.replace_scopes)