-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_repo_checks.py
92 lines (72 loc) · 2.76 KB
/
test_repo_checks.py
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
"""
(Incomplete) test suite for repo_checks.
"""
from __future__ import annotations
from unittest.mock import MagicMock, call, patch
import pytest
from edx_repo_tools.repo_checks import repo_checks
@pytest.fixture
def maintenance_label():
"""
Quickly make a basic label to return via the API.
"""
label = MagicMock()
label.name = "maintenance"
label.color = "ff9125"
label.description = (
"Routine upkeep necessary for the health of the platform"
)
return label
# Our list of expected labels, normally defined in labels.yaml.
labels_yaml = [
{
"name": "maintenance",
"color": "ff9125",
"description": "Routine upkeep necessary for the health of the platform",
}
]
@patch.object(repo_checks.Labels, "labels", labels_yaml)
class TestLabelsCheck:
def test_check_for_no_change(self, maintenance_label):
api = MagicMock()
api.issues.list_labels_for_repo.side_effect = [[maintenance_label], None]
check_cls = repo_checks.Labels(api, "test_org", "test_repo")
# Make sure that the check returns True, indicating that no changes need to be made.
assert check_cls.check()[0]
def test_addition(self, maintenance_label):
api = MagicMock()
api.issues.list_labels_for_repo.return_value = []
check_cls = repo_checks.Labels(api, "test_org", "test_repo")
# The check should be false because the maintenance label should be missing.
assert check_cls.check()[0] == False
check_cls.fix()
assert api.issues.create_label.called
call_args = api.issues.create_label.call_args
expected_call = call(
owner="test_org",
repo="test_repo",
name=maintenance_label.name,
color=maintenance_label.color,
description=maintenance_label.description,
)
assert call_args == expected_call
assert not api.issues.update_label.called
def test_update_label(self, maintenance_label):
maintenance_label.name = ":+1: Ma.in-t 'e'n_a\"nce!\" :-1:"
api = MagicMock()
api.issues.list_labels_for_repo.side_effect = [[maintenance_label], None]
check_cls = repo_checks.Labels(api, "test_org", "test_repo")
assert check_cls.check()[0] == False
check_cls.fix()
call_args = api.issues.update_label.call_args
expected_call = call(
owner="test_org",
repo="test_repo",
name=maintenance_label.name,
color=maintenance_label.color,
new_name="maintenance",
description=maintenance_label.description,
)
assert call_args == expected_call
assert not api.issues.create_label.called
assert api.issues.update_label.called