2020-07-11 19:15:00 +03:00
|
|
|
"""Tests module."""
|
|
|
|
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from github import Github
|
|
|
|
from flask import url_for
|
|
|
|
|
2020-07-14 05:45:15 +03:00
|
|
|
from .application import create_app
|
2020-07-11 19:15:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2020-07-14 05:45:15 +03:00
|
|
|
def app():
|
2020-10-09 22:16:27 +03:00
|
|
|
app = create_app()
|
|
|
|
yield app
|
|
|
|
app.container.unwire()
|
2020-07-11 19:15:00 +03:00
|
|
|
|
|
|
|
|
2020-07-14 05:45:15 +03:00
|
|
|
def test_index(client, app):
|
2020-07-11 19:15:00 +03:00
|
|
|
github_client_mock = mock.Mock(spec=Github)
|
|
|
|
github_client_mock.search_repositories.return_value = [
|
|
|
|
mock.Mock(
|
|
|
|
html_url='repo1-url',
|
|
|
|
name='repo1-name',
|
|
|
|
owner=mock.Mock(
|
|
|
|
login='owner1-login',
|
|
|
|
html_url='owner1-url',
|
|
|
|
avatar_url='owner1-avatar-url',
|
|
|
|
),
|
|
|
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
|
|
|
),
|
|
|
|
mock.Mock(
|
|
|
|
html_url='repo2-url',
|
|
|
|
name='repo2-name',
|
|
|
|
owner=mock.Mock(
|
|
|
|
login='owner2-login',
|
|
|
|
html_url='owner2-url',
|
|
|
|
avatar_url='owner2-avatar-url',
|
|
|
|
),
|
|
|
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2020-07-14 05:45:15 +03:00
|
|
|
with app.container.github_client.override(github_client_mock):
|
2020-07-11 19:15:00 +03:00
|
|
|
response = client.get(url_for('index'))
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
2020-07-20 23:58:18 +03:00
|
|
|
assert b'Results found: 2' in response.data
|
2020-07-11 19:15:00 +03:00
|
|
|
|
|
|
|
assert b'repo1-url' in response.data
|
|
|
|
assert b'repo1-name' in response.data
|
|
|
|
assert b'owner1-login' in response.data
|
|
|
|
assert b'owner1-url' in response.data
|
|
|
|
assert b'owner1-avatar-url' in response.data
|
|
|
|
|
|
|
|
assert b'repo2-url' in response.data
|
|
|
|
assert b'repo2-name' in response.data
|
|
|
|
assert b'owner2-login' in response.data
|
|
|
|
assert b'owner2-url' in response.data
|
|
|
|
assert b'owner2-avatar-url' in response.data
|
|
|
|
|
|
|
|
|
2020-07-14 05:45:15 +03:00
|
|
|
def test_index_no_results(client, app):
|
2020-07-11 19:15:00 +03:00
|
|
|
github_client_mock = mock.Mock(spec=Github)
|
|
|
|
github_client_mock.search_repositories.return_value = []
|
|
|
|
|
2020-07-14 05:45:15 +03:00
|
|
|
with app.container.github_client.override(github_client_mock):
|
2020-07-11 19:15:00 +03:00
|
|
|
response = client.get(url_for('index'))
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
2020-07-20 23:58:18 +03:00
|
|
|
assert b'Results found: 0' in response.data
|