forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_git.py
More file actions
99 lines (73 loc) · 3.11 KB
/
Copy pathtest_git.py
File metadata and controls
99 lines (73 loc) · 3.11 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import github3
from .helper import (UnitHelper, create_example_data_helper, create_url_helper)
get_example_data = create_example_data_helper('tree_example')
url_for = create_url_helper('https://api.github.com/repos/octocat/Hello-World/'
'trees/9fb037999f264ba9a7fc6274d15fa3ae2ab98312')
reference_url_for = create_url_helper('https://api.github.com/repos/'
'octocat/Hello-World/'
'git/refs/heads/featureA')
get_commit_example_data = create_example_data_helper('commit_example')
get_reference_example_data = create_example_data_helper('reference_example')
class TestTree(UnitHelper):
"""Tree unit test"""
described_class = github3.git.Tree
example_data = get_example_data()
def test_eq(self):
"""Assert that two trees are equal."""
tree = github3.git.Tree(get_example_data())
assert self.instance == tree
def test_ne(self):
"""Assert that two trees are not equal."""
tree = github3.git.Tree(get_example_data())
tree._json_data['truncated'] = True
assert self.instance != tree
def test_repr(self):
"""Assert Tree in in the repr."""
assert isinstance(self.instance, github3.git.Tree)
assert repr(self.instance).startswith('<Tree')
def test_recurse(self):
"""Assert that URL is called"""
self.instance.recurse()
self.session.get.assert_called_once_with(
url_for(),
params={'recursive': '1'}
)
class TestCommit(UnitHelper):
"""Commit unit test."""
described_class = github3.git.Commit
example_data = get_commit_example_data()
def test_repr(self):
assert repr(self.instance).startswith('<Commit')
def test_committer_as_User(self):
"""Show that commit_as_User() returns instance of User."""
user = self.instance.committer_as_User()
assert isinstance(user, github3.users.User)
def test_author_as_User(self):
"""Show that commit_as_Author() returns instance of User."""
user = self.instance.author_as_User()
assert isinstance(user, github3.users.User)
class TestReference(UnitHelper):
"""Reference unit test."""
described_class = github3.git.Reference
example_data = get_reference_example_data()
def test_delete(self):
self.instance.delete()
self.session.delete.assert_called_once_with(
reference_url_for()
)
def test_repr(self):
assert repr(self.instance).startswith('<Reference')
assert repr(self.instance.object).startswith('<Git Object')
def test_update(self):
"""Show that a user can update the reference."""
self.instance.update('fakesha', True)
try:
self.session.patch.assert_called_once_with(
reference_url_for(),
data='{"force": true, "sha": "fakesha"}'
)
except AssertionError:
self.session.patch.assert_called_once_with(
reference_url_for(),
data='{"sha": "fakesha", "force": true}'
)