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
100 lines (71 loc) · 2.89 KB
/
Copy pathtest_git.py
File metadata and controls
100 lines (71 loc) · 2.89 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
100
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("git_commit_example")
get_git_tag_example_data = create_example_data_helper("git_tag_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(), self.session)
assert self.instance == tree
def test_ne(self):
"""Assert that two trees are not equal."""
tree = github3.git.Tree(get_example_data(), self.session)
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")
class TestGitTag(UnitHelper):
"""Git Tag unit test."""
described_class = github3.git.Tag
example_data = get_git_tag_example_data()
def test_repr(self):
assert repr(self.instance).startswith("<Tag")
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}'
)