-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathtest_github.py
More file actions
85 lines (69 loc) · 3.25 KB
/
Copy pathtest_github.py
File metadata and controls
85 lines (69 loc) · 3.25 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
# (C) Datadog, Inc. 2023-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import pytest
from ddev.utils.github import PullRequest
class TestGetPullRequest:
def test_no_match(self, github_manager, network_replay):
network_replay('github/get_pr_no_match.yaml')
assert github_manager.get_pull_request('fcd9c178cb01bcb349c694d34fe6ae237e3c1aa8') is None
def test_found(self, helpers, network_replay, github_manager):
network_replay('github/get_pr_found.yaml')
pr = github_manager.get_pull_request('382cbb0af210897599cbe5fd8d69a38d4017e425')
assert pr.number == 14849
assert pr.title == 'Update formatting for changelogs'
assert pr.body == helpers.dedent(
"""
### Motivation
Make changelogs more readable"""
)
assert pr.author == 'swang392'
assert pr.labels == ['changelog/no-changelog', 'documentation', 'integration/apache']
@pytest.mark.parametrize(
'incoming_body, expected_body',
[
pytest.param(None, '', id='body is empty'),
pytest.param(r'abc\r\ndef\n', r'abc\ndef\n', id='body with Windows-style carriage-returns'),
],
)
def test_pr_description(self, incoming_body, expected_body):
assert (
PullRequest(
{
'number': 1,
'title': 'Title',
'pull_request': {'html_url': 'abc', 'diff_url': 'abc'},
'body': incoming_body,
'user': {'login': 'mrnobody'},
'labels': [],
}
).body
== expected_body
)
class TestListOpenPullRequestsTargetingBase:
def test_returns_pull_requests(self, github_manager, mocker):
response = mocker.MagicMock()
response.text = (
'{"items":[{"number":10,"title":"PR title","pull_request":{"html_url":"https://example.invalid/pr/10","diff_url":"https://example.invalid/pr/10.diff"},'
'"body":"","user":{"login":"someone"},"labels":[{"name":"foo"}]}]}'
)
mocker.patch('ddev.utils.github.GitHubManager._GitHubManager__api_get', return_value=response)
prs = github_manager.list_open_pull_requests_targeting_base('7.99.x')
assert len(prs) == 1
assert prs[0].number == 10
assert prs[0].title == 'PR title'
assert prs[0].html_url == 'https://example.invalid/pr/10'
assert prs[0].labels == ['foo']
def test_returns_empty_list_when_no_results(self, github_manager, mocker):
response = mocker.MagicMock()
response.text = '{"items":[],"total_count":0}'
mocker.patch('ddev.utils.github.GitHubManager._GitHubManager__api_get', return_value=response)
prs = github_manager.list_open_pull_requests_targeting_base('7.99.x')
assert prs == []
class TestCreateLabel:
def test_create_label(self, network_replay, github_manager):
network_replay('github/create_label.yaml', record_mode='none')
github_manager.create_label('my_custom_label', 'ff0000')
label = github_manager.get_label('my_custom_label')
assert label.json()['name'] == 'my_custom_label'
assert label.json()['color'] == 'ff0000'