| 1 |
"""Test issues namespace.""" |
| 2 |
import pytest |
| 3 |
|
| 4 |
from aiogithubapi import GitHubAPI, GitHubIssueCommentModel, GitHubIssueModel |
| 5 |
|
| 6 |
from tests.common import ( |
| 7 |
TEST_REPOSITORY_NAME, |
| 8 |
MockedRequests, |
| 9 |
MockResponse, |
| 10 |
load_fixture, |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
@pytest.mark.asyncio |
| 15 |
async def test_list(github_api: GitHubAPI, mock_requests: MockedRequests): |
| 16 |
response = await github_api.repos.issues.list(TEST_REPOSITORY_NAME) |
| 17 |
assert response.status == 200 |
| 18 |
assert isinstance(response.data, list) |
| 19 |
assert len(response.data) == 1 |
| 20 |
assert response.data[0].title == "Test issue" |
| 21 |
assert not response.data[0].is_pull_request |
| 22 |
assert mock_requests.called == 1 |
| 23 |
assert ( |
| 24 |
mock_requests.last_request["url"] |
| 25 |
== "https://api.github.com/repos/octocat/hello-world/issues" |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
@pytest.mark.asyncio |
| 30 |
async def test_get( |
| 31 |
github_api: GitHubAPI, |
| 32 |
mock_requests: MockedRequests, |
| 33 |
mock_response: MockResponse, |
| 34 |
): |
| 35 |
mock_response.mock_data = load_fixture( |
| 36 |
"repos_octocat_hello-world_issues.json", |
| 37 |
asjson=True, |
| 38 |
legacy=False, |
| 39 |
)[0] |
| 40 |
response = await github_api.repos.issues.get(TEST_REPOSITORY_NAME, 1) |
| 41 |
assert response.status == 200 |
| 42 |
assert isinstance(response.data, GitHubIssueModel) |
| 43 |
assert response.data.title == "Test issue" |
| 44 |
assert mock_requests.called == 1 |
| 45 |
assert ( |
| 46 |
mock_requests.last_request["url"] |
| 47 |
== "https://api.github.com/repos/octocat/hello-world/issues/1" |
| 48 |
) |
| 49 |
|
| 50 |
|
| 51 |
@pytest.mark.asyncio |
| 52 |
async def test_get_pull_request_from_issues_namespace( |
| 53 |
github_api: GitHubAPI, |
| 54 |
mock_requests: MockedRequests, |
| 55 |
mock_response: MockResponse, |
| 56 |
): |
| 57 |
mock_response.mock_data = { |
| 58 |
**load_fixture( |
| 59 |
"repos_octocat_hello-world_issues.json", |
| 60 |
asjson=True, |
| 61 |
legacy=False, |
| 62 |
)[0], |
| 63 |
"pull_request": {"url": ""}, |
| 64 |
} |
| 65 |
response = await github_api.repos.issues.get(TEST_REPOSITORY_NAME, 1) |
| 66 |
assert response.status == 200 |
| 67 |
assert isinstance(response.data, GitHubIssueModel) |
| 68 |
assert response.data.title == "Test issue" |
| 69 |
assert isinstance(response.data.as_dict, dict) |
| 70 |
assert response.data.is_pull_request |
| 71 |
assert mock_requests.called == 1 |
| 72 |
assert ( |
| 73 |
mock_requests.last_request["url"] |
| 74 |
== "https://api.github.com/repos/octocat/hello-world/issues/1" |
| 75 |
) |
| 76 |
|
| 77 |
|
| 78 |
@pytest.mark.asyncio |
| 79 |
async def test_create( |
| 80 |
github_api: GitHubAPI, |
| 81 |
mock_requests: MockedRequests, |
| 82 |
mock_response: MockResponse, |
| 83 |
): |
| 84 |
mock_response.mock_data = load_fixture( |
| 85 |
"repos_octocat_hello-world_issues.json", |
| 86 |
asjson=True, |
| 87 |
legacy=False, |
| 88 |
)[0] |
| 89 |
response = await github_api.repos.issues.create(TEST_REPOSITORY_NAME, {"title": "test"}) |
| 90 |
assert response.status == 200 |
| 91 |
assert isinstance(response.data, GitHubIssueModel) |
| 92 |
assert response.data.title == "Test issue" |
| 93 |
assert mock_requests.called == 1 |
| 94 |
assert mock_requests.last_request["method"] == "post" |
| 95 |
assert mock_requests.last_request["json"] == {"title": "test"} |
| 96 |
assert ( |
| 97 |
mock_requests.last_request["url"] |
| 98 |
== "https://api.github.com/repos/octocat/hello-world/issues" |
| 99 |
) |
| 100 |
|
| 101 |
|
| 102 |
@pytest.mark.asyncio |
| 103 |
async def test_update( |
| 104 |
github_api: GitHubAPI, |
| 105 |
mock_requests: MockedRequests, |
| 106 |
mock_response: MockResponse, |
| 107 |
): |
| 108 |
mock_response.mock_data = load_fixture( |
| 109 |
"repos_octocat_hello-world_issues.json", |
| 110 |
asjson=True, |
| 111 |
legacy=False, |
| 112 |
)[0] |
| 113 |
response = await github_api.repos.issues.update(TEST_REPOSITORY_NAME, 1, {"title": "test"}) |
| 114 |
assert response.status == 200 |
| 115 |
assert isinstance(response.data, GitHubIssueModel) |
| 116 |
assert response.data.title == "Test issue" |
| 117 |
assert mock_requests.called == 1 |
| 118 |
assert mock_requests.last_request["method"] == "patch" |
| 119 |
assert mock_requests.last_request["json"] == {"title": "test"} |
| 120 |
assert ( |
| 121 |
mock_requests.last_request["url"] |
| 122 |
== "https://api.github.com/repos/octocat/hello-world/issues/1" |
| 123 |
) |
| 124 |
|
| 125 |
|
| 126 |
@pytest.mark.asyncio |
| 127 |
async def test_lock( |
| 128 |
github_api: GitHubAPI, |
| 129 |
mock_requests: MockedRequests, |
| 130 |
mock_response: MockResponse, |
| 131 |
): |
| 132 |
mock_response.mock_status = 204 |
| 133 |
response = await github_api.repos.issues.lock(TEST_REPOSITORY_NAME, 1, "spam") |
| 134 |
assert response.status == 204 |
| 135 |
assert response.data is None |
| 136 |
assert mock_requests.called == 1 |
| 137 |
assert mock_requests.last_request["method"] == "put" |
| 138 |
assert mock_requests.last_request["json"] == {"lock_reason": "spam"} |
| 139 |
assert ( |
| 140 |
mock_requests.last_request["url"] |
| 141 |
== "https://api.github.com/repos/octocat/hello-world/issues/1/lock" |
| 142 |
) |
| 143 |
|
| 144 |
|
| 145 |
@pytest.mark.asyncio |
| 146 |
async def test_unlock( |
| 147 |
github_api: GitHubAPI, |
| 148 |
mock_requests: MockedRequests, |
| 149 |
mock_response: MockResponse, |
| 150 |
): |
| 151 |
mock_response.mock_status = 204 |
| 152 |
response = await github_api.repos.issues.unlock(TEST_REPOSITORY_NAME, 1) |
| 153 |
assert response.status == 204 |
| 154 |
assert response.data is None |
| 155 |
assert mock_requests.called == 1 |
| 156 |
assert mock_requests.last_request["method"] == "delete" |
| 157 |
assert ( |
| 158 |
mock_requests.last_request["url"] |
| 159 |
== "https://api.github.com/repos/octocat/hello-world/issues/1/lock" |
| 160 |
) |
| 161 |
|
| 162 |
|
| 163 |
@pytest.mark.asyncio |
| 164 |
async def test_list_comments(github_api: GitHubAPI, mock_requests: MockedRequests): |
| 165 |
response = await github_api.repos.issues.list_comments(TEST_REPOSITORY_NAME, 1) |
| 166 |
assert response.status == 200 |
| 167 |
assert isinstance(response.data, list) |
| 168 |
assert len(response.data) == 1 |
| 169 |
assert response.data[0].body == "No logs, no issue!" |
| 170 |
assert mock_requests.called == 1 |
| 171 |
assert ( |
| 172 |
mock_requests.last_request["url"] |
| 173 |
== "https://api.github.com/repos/octocat/hello-world/issues/1/comments" |
| 174 |
) |
| 175 |
|
| 176 |
|
| 177 |
@pytest.mark.asyncio |
| 178 |
async def test_get_comment( |
| 179 |
github_api: GitHubAPI, |
| 180 |
mock_requests: MockedRequests, |
| 181 |
mock_response: MockResponse, |
| 182 |
): |
| 183 |
mock_response.mock_data = load_fixture( |
| 184 |
"repos_octocat_hello-world_issues_1_comments.json", |
| 185 |
asjson=True, |
| 186 |
legacy=False, |
| 187 |
)[0] |
| 188 |
response = await github_api.repos.issues.get_comment(TEST_REPOSITORY_NAME, 1) |
| 189 |
assert response.status == 200 |
| 190 |
assert isinstance(response.data, GitHubIssueCommentModel) |
| 191 |
assert response.data.body == "No logs, no issue!" |
| 192 |
assert mock_requests.called == 1 |
| 193 |
assert ( |
| 194 |
mock_requests.last_request["url"] |
| 195 |
== "https://api.github.com/repos/octocat/hello-world/issues/comments/1" |
| 196 |
) |
| 197 |
|
| 198 |
|
| 199 |
@pytest.mark.asyncio |
| 200 |
async def test_create_comment( |
| 201 |
github_api: GitHubAPI, |
| 202 |
mock_requests: MockedRequests, |
| 203 |
mock_response: MockResponse, |
| 204 |
): |
| 205 |
mock_response.mock_data = load_fixture( |
| 206 |
"repos_octocat_hello-world_issues_1_comments.json", |
| 207 |
asjson=True, |
| 208 |
legacy=False, |
| 209 |
)[0] |
| 210 |
response = await github_api.repos.issues.create_comment( |
| 211 |
TEST_REPOSITORY_NAME, 1, {"title": "test"} |
| 212 |
) |
| 213 |
assert response.status == 200 |
| 214 |
assert isinstance(response.data, GitHubIssueCommentModel) |
| 215 |
assert response.data.body == "No logs, no issue!" |
| 216 |
assert mock_requests.called == 1 |
| 217 |
assert mock_requests.last_request["method"] == "post" |
| 218 |
assert mock_requests.last_request["json"] == {"title": "test"} |
| 219 |
assert ( |
| 220 |
mock_requests.last_request["url"] |
| 221 |
== "https://api.github.com/repos/octocat/hello-world/issues/1/comments" |
| 222 |
) |
| 223 |
|
| 224 |
|
| 225 |
@pytest.mark.asyncio |
| 226 |
async def test_update_comment( |
| 227 |
github_api: GitHubAPI, |
| 228 |
mock_requests: MockedRequests, |
| 229 |
mock_response: MockResponse, |
| 230 |
): |
| 231 |
mock_response.mock_data = load_fixture( |
| 232 |
"repos_octocat_hello-world_issues_1_comments.json", |
| 233 |
asjson=True, |
| 234 |
legacy=False, |
| 235 |
)[0] |
| 236 |
response = await github_api.repos.issues.update_comment( |
| 237 |
TEST_REPOSITORY_NAME, 1, {"title": "test"} |
| 238 |
) |
| 239 |
assert response.status == 200 |
| 240 |
assert isinstance(response.data, GitHubIssueCommentModel) |
| 241 |
assert response.data.body == "No logs, no issue!" |
| 242 |
assert mock_requests.called == 1 |
| 243 |
assert mock_requests.last_request["method"] == "patch" |
| 244 |
assert mock_requests.last_request["json"] == {"title": "test"} |
| 245 |
assert ( |
| 246 |
mock_requests.last_request["url"] |
| 247 |
== "https://api.github.com/repos/octocat/hello-world/issues/comments/1" |
| 248 |
) |
| 249 |
|
| 250 |
|
| 251 |
@pytest.mark.asyncio |
| 252 |
async def test_delete_comment( |
| 253 |
github_api: GitHubAPI, |
| 254 |
mock_requests: MockedRequests, |
| 255 |
mock_response: MockResponse, |
| 256 |
): |
| 257 |
mock_response.mock_status = 204 |
| 258 |
response = await github_api.repos.issues.delete_comment(TEST_REPOSITORY_NAME, 1) |
| 259 |
assert response.status == 204 |
| 260 |
assert response.data is None |
| 261 |
assert mock_requests.called == 1 |
| 262 |
assert mock_requests.last_request["method"] == "delete" |
| 263 |
assert ( |
| 264 |
mock_requests.last_request["url"] |
| 265 |
== "https://api.github.com/repos/octocat/hello-world/issues/comments/1" |
| 266 |
) |