diff --git a/src/pyosmeta/contributors.py b/src/pyosmeta/contributors.py index 5417092..6362bbd 100644 --- a/src/pyosmeta/contributors.py +++ b/src/pyosmeta/contributors.py @@ -25,7 +25,7 @@ def __init__(self, github_api: GitHubAPI, json_files: List) -> None: self.github_api = github_api self.json_files = json_files - # self.GITHUB_TOKEN = GITHUB_TOKEN + self.update_keys = [ "twitter", "website", diff --git a/tests/conftest.py b/tests/conftest.py index 4a8f2ac..995191c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,11 +1,42 @@ import pytest +from pyosmeta.contributors import ProcessContributors from pyosmeta.github_api import GitHubAPI from pyosmeta.parse_issues import ProcessIssues +@pytest.fixture +def ghuser_response(): + """This is the initial github response. I changed the username to + create this object""" + expected_response = { + "login": "chayadecacao", + "id": 123456, + "node_id": "MDQ6VXNlcjU3ODU0Mw==", + "avatar_url": "https://avatars.githubusercontent.com/u/123456?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/cacao", + "html_url": "https://github.com/cacao", + } + return expected_response + + +@pytest.fixture +def mock_github_api(mocker, ghuser_response): + mock_api = mocker.Mock(spec=GitHubAPI) + mock_api.get_user_info.return_value = ghuser_response + return mock_api + + +@pytest.fixture +def process_contribs(contrib_github_api): + """A fixture that creates a""" + return ProcessContributors(contrib_github_api) + + @pytest.fixture def github_api(): + """A fixture that instantiates an instance of the GitHubAPI object""" return GitHubAPI( org="pyopensci", repo="pyosmeta", labels=["label1", "label2"] ) diff --git a/tests/unit/test_contributors_module.py b/tests/unit/test_contributors_module.py index 6b96796..22d387f 100644 --- a/tests/unit/test_contributors_module.py +++ b/tests/unit/test_contributors_module.py @@ -14,3 +14,14 @@ def test_init(mocker): assert process_contributors.github_api == github_api_mock assert process_contributors.json_files == json_files + + +def test_return_user_info(mock_github_api, ghuser_response): + """Test that return from github API user info returns expected + GH username.""" + + process_contributors = ProcessContributors(mock_github_api, []) + gh_handle = "chayadecacao" + user_info = process_contributors.return_user_info(gh_handle) + + assert user_info["github_username"] == gh_handle diff --git a/tests/unit/test_github_api.py b/tests/unit/test_github_api.py index fd772e1..783056a 100644 --- a/tests/unit/test_github_api.py +++ b/tests/unit/test_github_api.py @@ -6,21 +6,6 @@ from pyosmeta.github_api import GitHubAPI -@pytest.fixture -def expected_ghuser_response(): - """I took a valid response and changed the username to create this object""" - expected_response = { - "login": "chayadecacao", - "id": 578543, - "node_id": "MDQ6VXNlcjU3ODU0Mw==", - "avatar_url": "https://avatars.githubusercontent.com/u/578543?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/webknjaz", - "html_url": "https://github.com/webknjaz", - } - return expected_response - - @pytest.fixture def mock_github_token(monkeypatch): """Fixture to create a mock token - i don't believe this @@ -68,10 +53,10 @@ def test_api_endpoint(github_api): assert github_api.api_endpoint == expected_endpoint -def test_get_user_info_successful(mocker, expected_ghuser_response): +def test_get_user_info_successful(mocker, ghuser_response): """Test that an expected response returns properly""" - expected_response = expected_ghuser_response + expected_response = ghuser_response mock_response = mocker.Mock() mock_response.status_code = 200 mock_response.json.return_value = expected_response