Untitled
unknown
plain_text
3 years ago
2.1 kB
13
Indexable
def test_get_user_projects():
assert get_user_projects("JohnDoe") is not None
def test_get_user_projects_invalid_user():
assert get_user_projects("InvalidUser123") is None
def test_get_project_list_personal_projects(capfd):
# Replace the username and add a sample project data to simulate a successful API response
username = "JohnDoe"
project_data = [{"id": 1, "name": "Project 1", "owner": {"id": "1"}},
{"id": 2, "name": "Project 2", "owner": {"id": "2"}}]
# Mock the get_user_projects function to return the sample project data
def mock_get_user_projects(username):
return project_data
# Call the get_project_list function with the mocked get_user_projects function
get_project_list(username, get_user_projects=mock_get_user_projects)
# Capture the printed output using the capfd fixture and assert the output
captured = capfd.readouterr()
expected_output = "List of projects (personal and forked) for user JohnDoe:\nPersonal project: Project 1\nPersonal project: Project 2\n"
assert captured.out == expected_output
def test_get_project_list_forked_projects(capfd):
# Replace the username and add a sample project data to simulate a successful API response
username = "JohnDoe"
project_data = [{"id": 1, "name": "Project 1", "owner": {"id": "2"}, "forked_from_project": {"id": 100}},
{"id": 2, "name": "Project 2", "owner": {"id": "3"}, "forked_from_project": {"id": 200}}]
# Mock the get_user_projects function to return the sample project data
def mock_get_user_projects(username):
return project_data
# Call the get_project_list function with the mocked get_user_projects function
get_project_list(username, get_user_projects=mock_get_user_projects)
# Capture the printed output using the capfd fixture and assert the output
captured = capfd.readouterr()
expected_output = "List of projects (personal and forked) for user JohnDoe:\nForked project: Project 1\nForked project: Project 2\n"
assert captured.out == expected_output
Editor is loading...