Skip to content

Commit

Permalink
Fix: additional tests for contribs
Browse files Browse the repository at this point in the history
  • Loading branch information
lwasser committed Mar 19, 2024
1 parent e51fe1d commit 34254ff
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/pyosmeta/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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"]
)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_contributors_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 2 additions & 17 deletions tests/unit/test_github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 34254ff

Please sign in to comment.