mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-28 04:23:59 +03:00
Update quotes in flask tutorial and example
This commit is contained in:
parent
7e794c41dd
commit
c92a941fe5
|
@ -129,7 +129,7 @@ Put next into the ``views.py``:
|
||||||
|
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
return 'Hello, World!'
|
return "Hello, World!"
|
||||||
|
|
||||||
Ok, we have the view.
|
Ok, we have the view.
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ Put next into the ``application.py``:
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.container = container
|
app.container = container
|
||||||
app.add_url_rule('/', 'index', views.index)
|
app.add_url_rule("/", "index", views.index)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ Edit ``application.py``:
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.container = container
|
app.container = container
|
||||||
app.add_url_rule('/', 'index', views.index)
|
app.add_url_rule("/", "index", views.index)
|
||||||
|
|
||||||
bootstrap = Bootstrap()
|
bootstrap = Bootstrap()
|
||||||
bootstrap.init_app(app)
|
bootstrap.init_app(app)
|
||||||
|
@ -398,13 +398,13 @@ Edit ``views.py``:
|
||||||
|
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
query = request.args.get('query', 'Dependency Injector')
|
query = request.args.get("query", "Dependency Injector")
|
||||||
limit = request.args.get('limit', 10, int)
|
limit = request.args.get("limit", 10, int)
|
||||||
|
|
||||||
repositories = []
|
repositories = []
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'index.html',
|
"index.html",
|
||||||
query=query,
|
query=query,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
repositories=repositories,
|
repositories=repositories,
|
||||||
|
@ -553,12 +553,12 @@ Edit ``application.py``:
|
||||||
|
|
||||||
def create_app() -> Flask:
|
def create_app() -> Flask:
|
||||||
container = Container()
|
container = Container()
|
||||||
container.config.from_yaml('config.yml')
|
container.config.from_yaml("config.yml")
|
||||||
container.config.github.auth_token.from_env('GITHUB_TOKEN')
|
container.config.github.auth_token.from_env("GITHUB_TOKEN")
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.container = container
|
app.container = container
|
||||||
app.add_url_rule('/', 'index', views.index)
|
app.add_url_rule("/", "index", views.index)
|
||||||
|
|
||||||
bootstrap = Bootstrap()
|
bootstrap = Bootstrap()
|
||||||
bootstrap.init_app(app)
|
bootstrap.init_app(app)
|
||||||
|
@ -639,7 +639,7 @@ and put next into it:
|
||||||
"""Search for repositories and return formatted data."""
|
"""Search for repositories and return formatted data."""
|
||||||
repositories = self._github_client.search_repositories(
|
repositories = self._github_client.search_repositories(
|
||||||
query=query,
|
query=query,
|
||||||
**{'in': 'name'},
|
**{"in": "name"},
|
||||||
)
|
)
|
||||||
return [
|
return [
|
||||||
self._format_repo(repository)
|
self._format_repo(repository)
|
||||||
|
@ -649,22 +649,22 @@ and put next into it:
|
||||||
def _format_repo(self, repository: Repository):
|
def _format_repo(self, repository: Repository):
|
||||||
commits = repository.get_commits()
|
commits = repository.get_commits()
|
||||||
return {
|
return {
|
||||||
'url': repository.html_url,
|
"url": repository.html_url,
|
||||||
'name': repository.name,
|
"name": repository.name,
|
||||||
'owner': {
|
"owner": {
|
||||||
'login': repository.owner.login,
|
"login": repository.owner.login,
|
||||||
'url': repository.owner.html_url,
|
"url": repository.owner.html_url,
|
||||||
'avatar_url': repository.owner.avatar_url,
|
"avatar_url": repository.owner.avatar_url,
|
||||||
},
|
},
|
||||||
'latest_commit': self._format_commit(commits[0]) if commits else {},
|
"latest_commit": self._format_commit(commits[0]) if commits else {},
|
||||||
}
|
}
|
||||||
|
|
||||||
def _format_commit(self, commit: Commit):
|
def _format_commit(self, commit: Commit):
|
||||||
return {
|
return {
|
||||||
'sha': commit.sha,
|
"sha": commit.sha,
|
||||||
'url': commit.html_url,
|
"url": commit.html_url,
|
||||||
'message': commit.commit.message,
|
"message": commit.commit.message,
|
||||||
'author_name': commit.commit.author.name,
|
"author_name": commit.commit.author.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
Now let's add ``SearchService`` to the container.
|
Now let's add ``SearchService`` to the container.
|
||||||
|
@ -720,13 +720,13 @@ Edit ``views.py``:
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
def index(search_service: SearchService = Provide[Container.search_service]):
|
def index(search_service: SearchService = Provide[Container.search_service]):
|
||||||
query = request.args.get('query', 'Dependency Injector')
|
query = request.args.get("query", "Dependency Injector")
|
||||||
limit = request.args.get('limit', 10, int)
|
limit = request.args.get("limit", 10, int)
|
||||||
|
|
||||||
repositories = search_service.search_repositories(query, limit)
|
repositories = search_service.search_repositories(query, limit)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'index.html',
|
"index.html",
|
||||||
query=query,
|
query=query,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
repositories=repositories,
|
repositories=repositories,
|
||||||
|
@ -752,13 +752,13 @@ Edit ``application.py``:
|
||||||
|
|
||||||
def create_app() -> Flask:
|
def create_app() -> Flask:
|
||||||
container = Container()
|
container = Container()
|
||||||
container.config.from_yaml('config.yml')
|
container.config.from_yaml("config.yml")
|
||||||
container.config.github.auth_token.from_env('GITHUB_TOKEN')
|
container.config.github.auth_token.from_env("GITHUB_TOKEN")
|
||||||
container.wire(modules=[views])
|
container.wire(modules=[views])
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.container = container
|
app.container = container
|
||||||
app.add_url_rule('/', 'index', views.index)
|
app.add_url_rule("/", "index", views.index)
|
||||||
|
|
||||||
bootstrap = Bootstrap()
|
bootstrap = Bootstrap()
|
||||||
bootstrap.init_app(app)
|
bootstrap.init_app(app)
|
||||||
|
@ -801,13 +801,13 @@ Edit ``views.py``:
|
||||||
default_query: str = Provide[Container.config.default.query],
|
default_query: str = Provide[Container.config.default.query],
|
||||||
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
||||||
):
|
):
|
||||||
query = request.args.get('query', default_query)
|
query = request.args.get("query", default_query)
|
||||||
limit = request.args.get('limit', default_limit, int)
|
limit = request.args.get("limit", default_limit, int)
|
||||||
|
|
||||||
repositories = search_service.search_repositories(query, limit)
|
repositories = search_service.search_repositories(query, limit)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'index.html',
|
"index.html",
|
||||||
query=query,
|
query=query,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
repositories=repositories,
|
repositories=repositories,
|
||||||
|
@ -900,44 +900,44 @@ and put next into it:
|
||||||
github_client_mock = mock.Mock(spec=Github)
|
github_client_mock = mock.Mock(spec=Github)
|
||||||
github_client_mock.search_repositories.return_value = [
|
github_client_mock.search_repositories.return_value = [
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
html_url='repo1-url',
|
html_url="repo1-url",
|
||||||
name='repo1-name',
|
name="repo1-name",
|
||||||
owner=mock.Mock(
|
owner=mock.Mock(
|
||||||
login='owner1-login',
|
login="owner1-login",
|
||||||
html_url='owner1-url',
|
html_url="owner1-url",
|
||||||
avatar_url='owner1-avatar-url',
|
avatar_url="owner1-avatar-url",
|
||||||
),
|
),
|
||||||
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
||||||
),
|
),
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
html_url='repo2-url',
|
html_url="repo2-url",
|
||||||
name='repo2-name',
|
name="repo2-name",
|
||||||
owner=mock.Mock(
|
owner=mock.Mock(
|
||||||
login='owner2-login',
|
login="owner2-login",
|
||||||
html_url='owner2-url',
|
html_url="owner2-url",
|
||||||
avatar_url='owner2-avatar-url',
|
avatar_url="owner2-avatar-url",
|
||||||
),
|
),
|
||||||
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
with app.container.github_client.override(github_client_mock):
|
with app.container.github_client.override(github_client_mock):
|
||||||
response = client.get(url_for('index'))
|
response = client.get(url_for("index"))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert b'Results found: 2' in response.data
|
assert b"Results found: 2" in response.data
|
||||||
|
|
||||||
assert b'repo1-url' in response.data
|
assert b"repo1-url" in response.data
|
||||||
assert b'repo1-name' in response.data
|
assert b"repo1-name" in response.data
|
||||||
assert b'owner1-login' in response.data
|
assert b"owner1-login" in response.data
|
||||||
assert b'owner1-url' in response.data
|
assert b"owner1-url" in response.data
|
||||||
assert b'owner1-avatar-url' in response.data
|
assert b"owner1-avatar-url" in response.data
|
||||||
|
|
||||||
assert b'repo2-url' in response.data
|
assert b"repo2-url" in response.data
|
||||||
assert b'repo2-name' in response.data
|
assert b"repo2-name" in response.data
|
||||||
assert b'owner2-login' in response.data
|
assert b"owner2-login" in response.data
|
||||||
assert b'owner2-url' in response.data
|
assert b"owner2-url" in response.data
|
||||||
assert b'owner2-avatar-url' in response.data
|
assert b"owner2-avatar-url" in response.data
|
||||||
|
|
||||||
|
|
||||||
def test_index_no_results(client, app):
|
def test_index_no_results(client, app):
|
||||||
|
@ -945,10 +945,10 @@ and put next into it:
|
||||||
github_client_mock.search_repositories.return_value = []
|
github_client_mock.search_repositories.return_value = []
|
||||||
|
|
||||||
with app.container.github_client.override(github_client_mock):
|
with app.container.github_client.override(github_client_mock):
|
||||||
response = client.get(url_for('index'))
|
response = client.get(url_for("index"))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert b'Results found: 0' in response.data
|
assert b"Results found: 0" in response.data
|
||||||
|
|
||||||
Now let's run it and check the coverage:
|
Now let's run it and check the coverage:
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ from .blueprints import example
|
||||||
|
|
||||||
def create_app() -> Flask:
|
def create_app() -> Flask:
|
||||||
container = Container()
|
container = Container()
|
||||||
container.config.from_yaml('config.yml')
|
container.config.from_yaml("config.yml")
|
||||||
container.config.github.auth_token.from_env('GITHUB_TOKEN')
|
container.config.github.auth_token.from_env("GITHUB_TOKEN")
|
||||||
container.wire(modules=[example])
|
container.wire(modules=[example])
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
|
@ -7,23 +7,23 @@ from githubnavigator.services import SearchService
|
||||||
from githubnavigator.containers import Container
|
from githubnavigator.containers import Container
|
||||||
|
|
||||||
|
|
||||||
blueprint = Blueprint('example', __name__, template_folder='templates/')
|
blueprint = Blueprint("example", __name__, template_folder="templates/")
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/')
|
@blueprint.route("/")
|
||||||
@inject
|
@inject
|
||||||
def index(
|
def index(
|
||||||
search_service: SearchService = Provide[Container.search_service],
|
search_service: SearchService = Provide[Container.search_service],
|
||||||
default_query: str = Provide[Container.config.default.query],
|
default_query: str = Provide[Container.config.default.query],
|
||||||
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
||||||
):
|
):
|
||||||
query = request.args.get('query', default_query)
|
query = request.args.get("query", default_query)
|
||||||
limit = request.args.get('limit', default_limit, int)
|
limit = request.args.get("limit", default_limit, int)
|
||||||
|
|
||||||
repositories = search_service.search_repositories(query, limit)
|
repositories = search_service.search_repositories(query, limit)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'index.html',
|
"index.html",
|
||||||
query=query,
|
query=query,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
repositories=repositories,
|
repositories=repositories,
|
||||||
|
|
|
@ -15,7 +15,7 @@ class SearchService:
|
||||||
"""Search for repositories and return formatted data."""
|
"""Search for repositories and return formatted data."""
|
||||||
repositories = self._github_client.search_repositories(
|
repositories = self._github_client.search_repositories(
|
||||||
query=query,
|
query=query,
|
||||||
**{'in': 'name'},
|
**{"in": "name"},
|
||||||
)
|
)
|
||||||
return [
|
return [
|
||||||
self._format_repo(repository)
|
self._format_repo(repository)
|
||||||
|
@ -25,20 +25,20 @@ class SearchService:
|
||||||
def _format_repo(self, repository: Repository):
|
def _format_repo(self, repository: Repository):
|
||||||
commits = repository.get_commits()
|
commits = repository.get_commits()
|
||||||
return {
|
return {
|
||||||
'url': repository.html_url,
|
"url": repository.html_url,
|
||||||
'name': repository.name,
|
"name": repository.name,
|
||||||
'owner': {
|
"owner": {
|
||||||
'login': repository.owner.login,
|
"login": repository.owner.login,
|
||||||
'url': repository.owner.html_url,
|
"url": repository.owner.html_url,
|
||||||
'avatar_url': repository.owner.avatar_url,
|
"avatar_url": repository.owner.avatar_url,
|
||||||
},
|
},
|
||||||
'latest_commit': self._format_commit(commits[0]) if commits else {},
|
"latest_commit": self._format_commit(commits[0]) if commits else {},
|
||||||
}
|
}
|
||||||
|
|
||||||
def _format_commit(self, commit: Commit):
|
def _format_commit(self, commit: Commit):
|
||||||
return {
|
return {
|
||||||
'sha': commit.sha,
|
"sha": commit.sha,
|
||||||
'url': commit.html_url,
|
"url": commit.html_url,
|
||||||
'message': commit.commit.message,
|
"message": commit.commit.message,
|
||||||
'author_name': commit.commit.author.name,
|
"author_name": commit.commit.author.name,
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,44 +20,44 @@ def test_index(client, app):
|
||||||
github_client_mock = mock.Mock(spec=Github)
|
github_client_mock = mock.Mock(spec=Github)
|
||||||
github_client_mock.search_repositories.return_value = [
|
github_client_mock.search_repositories.return_value = [
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
html_url='repo1-url',
|
html_url="repo1-url",
|
||||||
name='repo1-name',
|
name="repo1-name",
|
||||||
owner=mock.Mock(
|
owner=mock.Mock(
|
||||||
login='owner1-login',
|
login="owner1-login",
|
||||||
html_url='owner1-url',
|
html_url="owner1-url",
|
||||||
avatar_url='owner1-avatar-url',
|
avatar_url="owner1-avatar-url",
|
||||||
),
|
),
|
||||||
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
||||||
),
|
),
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
html_url='repo2-url',
|
html_url="repo2-url",
|
||||||
name='repo2-name',
|
name="repo2-name",
|
||||||
owner=mock.Mock(
|
owner=mock.Mock(
|
||||||
login='owner2-login',
|
login="owner2-login",
|
||||||
html_url='owner2-url',
|
html_url="owner2-url",
|
||||||
avatar_url='owner2-avatar-url',
|
avatar_url="owner2-avatar-url",
|
||||||
),
|
),
|
||||||
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
with app.container.github_client.override(github_client_mock):
|
with app.container.github_client.override(github_client_mock):
|
||||||
response = client.get(url_for('example.index'))
|
response = client.get(url_for("example.index"))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert b'Results found: 2' in response.data
|
assert b"Results found: 2" in response.data
|
||||||
|
|
||||||
assert b'repo1-url' in response.data
|
assert b"repo1-url" in response.data
|
||||||
assert b'repo1-name' in response.data
|
assert b"repo1-name" in response.data
|
||||||
assert b'owner1-login' in response.data
|
assert b"owner1-login" in response.data
|
||||||
assert b'owner1-url' in response.data
|
assert b"owner1-url" in response.data
|
||||||
assert b'owner1-avatar-url' in response.data
|
assert b"owner1-avatar-url" in response.data
|
||||||
|
|
||||||
assert b'repo2-url' in response.data
|
assert b"repo2-url" in response.data
|
||||||
assert b'repo2-name' in response.data
|
assert b"repo2-name" in response.data
|
||||||
assert b'owner2-login' in response.data
|
assert b"owner2-login" in response.data
|
||||||
assert b'owner2-url' in response.data
|
assert b"owner2-url" in response.data
|
||||||
assert b'owner2-avatar-url' in response.data
|
assert b"owner2-avatar-url" in response.data
|
||||||
|
|
||||||
|
|
||||||
def test_index_no_results(client, app):
|
def test_index_no_results(client, app):
|
||||||
|
@ -65,7 +65,7 @@ def test_index_no_results(client, app):
|
||||||
github_client_mock.search_repositories.return_value = []
|
github_client_mock.search_repositories.return_value = []
|
||||||
|
|
||||||
with app.container.github_client.override(github_client_mock):
|
with app.container.github_client.override(github_client_mock):
|
||||||
response = client.get(url_for('example.index'))
|
response = client.get(url_for("example.index"))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert b'Results found: 0' in response.data
|
assert b"Results found: 0" in response.data
|
||||||
|
|
|
@ -9,13 +9,13 @@ from . import views
|
||||||
|
|
||||||
def create_app() -> Flask:
|
def create_app() -> Flask:
|
||||||
container = Container()
|
container = Container()
|
||||||
container.config.from_yaml('config.yml')
|
container.config.from_yaml("config.yml")
|
||||||
container.config.github.auth_token.from_env('GITHUB_TOKEN')
|
container.config.github.auth_token.from_env("GITHUB_TOKEN")
|
||||||
container.wire(modules=[views])
|
container.wire(modules=[views])
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.container = container
|
app.container = container
|
||||||
app.add_url_rule('/', 'index', views.index)
|
app.add_url_rule("/", "index", views.index)
|
||||||
|
|
||||||
bootstrap = Bootstrap()
|
bootstrap = Bootstrap()
|
||||||
bootstrap.init_app(app)
|
bootstrap.init_app(app)
|
||||||
|
|
|
@ -15,7 +15,7 @@ class SearchService:
|
||||||
"""Search for repositories and return formatted data."""
|
"""Search for repositories and return formatted data."""
|
||||||
repositories = self._github_client.search_repositories(
|
repositories = self._github_client.search_repositories(
|
||||||
query=query,
|
query=query,
|
||||||
**{'in': 'name'},
|
**{"in": "name"},
|
||||||
)
|
)
|
||||||
return [
|
return [
|
||||||
self._format_repo(repository)
|
self._format_repo(repository)
|
||||||
|
@ -25,20 +25,20 @@ class SearchService:
|
||||||
def _format_repo(self, repository: Repository):
|
def _format_repo(self, repository: Repository):
|
||||||
commits = repository.get_commits()
|
commits = repository.get_commits()
|
||||||
return {
|
return {
|
||||||
'url': repository.html_url,
|
"url": repository.html_url,
|
||||||
'name': repository.name,
|
"name": repository.name,
|
||||||
'owner': {
|
"owner": {
|
||||||
'login': repository.owner.login,
|
"login": repository.owner.login,
|
||||||
'url': repository.owner.html_url,
|
"url": repository.owner.html_url,
|
||||||
'avatar_url': repository.owner.avatar_url,
|
"avatar_url": repository.owner.avatar_url,
|
||||||
},
|
},
|
||||||
'latest_commit': self._format_commit(commits[0]) if commits else {},
|
"latest_commit": self._format_commit(commits[0]) if commits else {},
|
||||||
}
|
}
|
||||||
|
|
||||||
def _format_commit(self, commit: Commit):
|
def _format_commit(self, commit: Commit):
|
||||||
return {
|
return {
|
||||||
'sha': commit.sha,
|
"sha": commit.sha,
|
||||||
'url': commit.html_url,
|
"url": commit.html_url,
|
||||||
'message': commit.commit.message,
|
"message": commit.commit.message,
|
||||||
'author_name': commit.commit.author.name,
|
"author_name": commit.commit.author.name,
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,44 +20,44 @@ def test_index(client, app):
|
||||||
github_client_mock = mock.Mock(spec=Github)
|
github_client_mock = mock.Mock(spec=Github)
|
||||||
github_client_mock.search_repositories.return_value = [
|
github_client_mock.search_repositories.return_value = [
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
html_url='repo1-url',
|
html_url="repo1-url",
|
||||||
name='repo1-name',
|
name="repo1-name",
|
||||||
owner=mock.Mock(
|
owner=mock.Mock(
|
||||||
login='owner1-login',
|
login="owner1-login",
|
||||||
html_url='owner1-url',
|
html_url="owner1-url",
|
||||||
avatar_url='owner1-avatar-url',
|
avatar_url="owner1-avatar-url",
|
||||||
),
|
),
|
||||||
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
||||||
),
|
),
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
html_url='repo2-url',
|
html_url="repo2-url",
|
||||||
name='repo2-name',
|
name="repo2-name",
|
||||||
owner=mock.Mock(
|
owner=mock.Mock(
|
||||||
login='owner2-login',
|
login="owner2-login",
|
||||||
html_url='owner2-url',
|
html_url="owner2-url",
|
||||||
avatar_url='owner2-avatar-url',
|
avatar_url="owner2-avatar-url",
|
||||||
),
|
),
|
||||||
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
get_commits=mock.Mock(return_value=[mock.Mock()]),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
with app.container.github_client.override(github_client_mock):
|
with app.container.github_client.override(github_client_mock):
|
||||||
response = client.get(url_for('index'))
|
response = client.get(url_for("index"))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert b'Results found: 2' in response.data
|
assert b"Results found: 2" in response.data
|
||||||
|
|
||||||
assert b'repo1-url' in response.data
|
assert b"repo1-url" in response.data
|
||||||
assert b'repo1-name' in response.data
|
assert b"repo1-name" in response.data
|
||||||
assert b'owner1-login' in response.data
|
assert b"owner1-login" in response.data
|
||||||
assert b'owner1-url' in response.data
|
assert b"owner1-url" in response.data
|
||||||
assert b'owner1-avatar-url' in response.data
|
assert b"owner1-avatar-url" in response.data
|
||||||
|
|
||||||
assert b'repo2-url' in response.data
|
assert b"repo2-url" in response.data
|
||||||
assert b'repo2-name' in response.data
|
assert b"repo2-name" in response.data
|
||||||
assert b'owner2-login' in response.data
|
assert b"owner2-login" in response.data
|
||||||
assert b'owner2-url' in response.data
|
assert b"owner2-url" in response.data
|
||||||
assert b'owner2-avatar-url' in response.data
|
assert b"owner2-avatar-url" in response.data
|
||||||
|
|
||||||
|
|
||||||
def test_index_no_results(client, app):
|
def test_index_no_results(client, app):
|
||||||
|
@ -65,7 +65,7 @@ def test_index_no_results(client, app):
|
||||||
github_client_mock.search_repositories.return_value = []
|
github_client_mock.search_repositories.return_value = []
|
||||||
|
|
||||||
with app.container.github_client.override(github_client_mock):
|
with app.container.github_client.override(github_client_mock):
|
||||||
response = client.get(url_for('index'))
|
response = client.get(url_for("index"))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert b'Results found: 0' in response.data
|
assert b"Results found: 0" in response.data
|
||||||
|
|
|
@ -13,13 +13,13 @@ def index(
|
||||||
default_query: str = Provide[Container.config.default.query],
|
default_query: str = Provide[Container.config.default.query],
|
||||||
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
||||||
):
|
):
|
||||||
query = request.args.get('query', default_query)
|
query = request.args.get("query", default_query)
|
||||||
limit = request.args.get('limit', default_limit, int)
|
limit = request.args.get("limit", default_limit, int)
|
||||||
|
|
||||||
repositories = search_service.search_repositories(query, limit)
|
repositories = search_service.search_repositories(query, limit)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'index.html',
|
"index.html",
|
||||||
query=query,
|
query=query,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
repositories=repositories,
|
repositories=repositories,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user