# Path: api/github/client.py
# class GitHubClientError(Exception):
#     def __init__(self, body, response):
#         self.body = body
#         self.response = response
# 
# Path: api/tests/conftest.py
# class BaseMockGitHubClient(GitHubClient):
# 
#     # Stub out request method
#     async def make_request(self, **kwargs):
#         pass
# 
#     async def repo_tags(self, username, repo):
#         raise NotImplementedError
# 
#     async def user_repos(self, username, sort='pushed'):
#         raise NotImplementedError
# 
#     async def compare(self, username: str, repo: str, base: str, head='HEAD'):
#         raise NotImplementedError
# 
#     async def rate_limit(self):
#         raise NotImplementedError


from unittest import mock
from webtest_aiohttp import TestApp
from api.github.client import GitHubClientError
from api.tests.conftest import BaseMockGitHubClient
import pytest

@pytest.fixture()
def error_app(make_app):
    return make_app(github=MockGitHubErrorClient('id', 'secret'))

@pytest.fixture()
def error_client(error_app):
    return TestApp(error_app)


class TestIndex:

    def test_index(self, client):
        res = client.get('/v1/')
        assert res.status_code == 200
        assert res.json['message'] == 'Welcome to the sir API'
        assert 'should_i_release' in res.json['links']
        assert res.json['links']['should_i_release'] == '/v1/should_i_release/:username/:repo/'

class TestShouldIRelease:

    def test_success(self, client):
        res = client.get('/v1/should_i_release/sloria/fakerepo/')
        assert res.status_code == 200

        assert res.json['latest_tag'] == '1.2.3'
        assert res.json['ahead_by'] == 42
        assert res.json['should_release'] is True
        assert res.json['base_commit_sha'] == '123abc'


# Path: api/github/client.py
# class GitHubClientError(Exception):
#     def __init__(self, body, response):
#         self.body = body
#         self.response = response
# 
# Path: api/tests/conftest.py
# class BaseMockGitHubClient(GitHubClient):
# 
#     # Stub out request method
#     async def make_request(self, **kwargs):
#         pass
# 
#     async def repo_tags(self, username, repo):
#         raise NotImplementedError
# 
#     async def user_repos(self, username, sort='pushed'):
#         raise NotImplementedError
# 
#     async def compare(self, username: str, repo: str, base: str, head='HEAD'):
#         raise NotImplementedError
# 
#     async def rate_limit(self):
#         raise NotImplementedError


# Path: api/tests/test_handlers.py
from unittest import mock
from webtest_aiohttp import TestApp
from api.github.client import GitHubClientError
from api.tests.conftest import BaseMockGitHubClient
import pytest


@pytest.fixture()
def error_app(make_app):
    return make_app(github=MockGitHubErrorClient('id', 'secret'))

@pytest.fixture()
def error_client(error_app):
    return TestApp(error_app)


class TestIndex:

    def test_index(self, client):
        res = client.get('/v1/')
        assert res.status_code == 200
        assert res.json['message'] == 'Welcome to the sir API'
        assert 'should_i_release' in res.json['links']
        assert res.json['links']['should_i_release'] == '/v1/should_i_release/:username/:repo/'

class TestShouldIRelease:

    def test_success(self, client):
        res = client.get('/v1/should_i_release/sloria/fakerepo/')
        assert res.status_code == 200

        assert res.json['latest_tag'] == '1.2.3'
        assert res.json['ahead_by'] == 42
        assert res.json['should_release'] is True
        assert res.json['base_commit_sha'] == '123abc'


    def test_handling_github_api_error(self, error_client):