Skip to content

Commit 34254ff

Browse files
committed
Fix: additional tests for contribs
1 parent e51fe1d commit 34254ff

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

src/pyosmeta/contributors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, github_api: GitHubAPI, json_files: List) -> None:
2525

2626
self.github_api = github_api
2727
self.json_files = json_files
28-
# self.GITHUB_TOKEN = GITHUB_TOKEN
28+
2929
self.update_keys = [
3030
"twitter",
3131
"website",

tests/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
11
import pytest
22

3+
from pyosmeta.contributors import ProcessContributors
34
from pyosmeta.github_api import GitHubAPI
45
from pyosmeta.parse_issues import ProcessIssues
56

67

8+
@pytest.fixture
9+
def ghuser_response():
10+
"""This is the initial github response. I changed the username to
11+
create this object"""
12+
expected_response = {
13+
"login": "chayadecacao",
14+
"id": 123456,
15+
"node_id": "MDQ6VXNlcjU3ODU0Mw==",
16+
"avatar_url": "https://avatars.githubusercontent.com/u/123456?v=4",
17+
"gravatar_id": "",
18+
"url": "https://api.github.com/users/cacao",
19+
"html_url": "https://github.com/cacao",
20+
}
21+
return expected_response
22+
23+
24+
@pytest.fixture
25+
def mock_github_api(mocker, ghuser_response):
26+
mock_api = mocker.Mock(spec=GitHubAPI)
27+
mock_api.get_user_info.return_value = ghuser_response
28+
return mock_api
29+
30+
31+
@pytest.fixture
32+
def process_contribs(contrib_github_api):
33+
"""A fixture that creates a"""
34+
return ProcessContributors(contrib_github_api)
35+
36+
737
@pytest.fixture
838
def github_api():
39+
"""A fixture that instantiates an instance of the GitHubAPI object"""
940
return GitHubAPI(
1041
org="pyopensci", repo="pyosmeta", labels=["label1", "label2"]
1142
)

tests/unit/test_contributors_module.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ def test_init(mocker):
1414

1515
assert process_contributors.github_api == github_api_mock
1616
assert process_contributors.json_files == json_files
17+
18+
19+
def test_return_user_info(mock_github_api, ghuser_response):
20+
"""Test that return from github API user info returns expected
21+
GH username."""
22+
23+
process_contributors = ProcessContributors(mock_github_api, [])
24+
gh_handle = "chayadecacao"
25+
user_info = process_contributors.return_user_info(gh_handle)
26+
27+
assert user_info["github_username"] == gh_handle

tests/unit/test_github_api.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@
66
from pyosmeta.github_api import GitHubAPI
77

88

9-
@pytest.fixture
10-
def expected_ghuser_response():
11-
"""I took a valid response and changed the username to create this object"""
12-
expected_response = {
13-
"login": "chayadecacao",
14-
"id": 578543,
15-
"node_id": "MDQ6VXNlcjU3ODU0Mw==",
16-
"avatar_url": "https://avatars.githubusercontent.com/u/578543?v=4",
17-
"gravatar_id": "",
18-
"url": "https://api.github.com/users/webknjaz",
19-
"html_url": "https://github.com/webknjaz",
20-
}
21-
return expected_response
22-
23-
249
@pytest.fixture
2510
def mock_github_token(monkeypatch):
2611
"""Fixture to create a mock token - i don't believe this
@@ -68,10 +53,10 @@ def test_api_endpoint(github_api):
6853
assert github_api.api_endpoint == expected_endpoint
6954

7055

71-
def test_get_user_info_successful(mocker, expected_ghuser_response):
56+
def test_get_user_info_successful(mocker, ghuser_response):
7257
"""Test that an expected response returns properly"""
7358

74-
expected_response = expected_ghuser_response
59+
expected_response = ghuser_response
7560
mock_response = mocker.Mock()
7661
mock_response.status_code = 200
7762
mock_response.json.return_value = expected_response

0 commit comments

Comments
 (0)