Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Предлагать перезапускать упавшие тесты #30

Merged
merged 11 commits into from
Jan 12, 2024
6 changes: 6 additions & 0 deletions overhave/admin/templates/test_run.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
.success-btn:hover {
background-color: #33cc33;
}
.restart-btn {
border: 2px solid #fbbc04
}
.restart-btn:hover {
background-color: #fbbc04;
}
form {
display: inline-block;
}
Expand Down
11 changes: 10 additions & 1 deletion overhave/admin/templates/test_run_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
{{ render_allure_button(model) }}
{% endif %}
{% else %}
<meta http-equiv="refresh" content="5">
<meta http-equiv="refresh" content="5" xmlns="http://www.w3.org/1999/html">
{% endif %}
{% if model.status == 'SUCCESS' %}
{{ render_pr_button(model) }}
{% endif %}
{% if model.status == 'FAILED' %}
{{ render_restart_button(model) }}
{% endif %}
{% endblock %}

{% macro render_edit_button(model) %}
Expand All @@ -42,3 +45,9 @@
<button class="button request-btn" type="submit">Create pull-request</button>
</form>
{% endmacro %}

{% macro render_restart_button(model) %}
<form action="{{ url_for('testrun.details_view', id=model.scenario.feature_id) }}" method="POST">
<button type="submit" class="button restart-btn" name="restart">Restart test</button>
</form>
{% endmacro %}
1 change: 1 addition & 0 deletions overhave/admin/views/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def edit_view(self) -> werkzeug.Response:
return rendered

data = flask.request.form

logger.debug("Request data:\n%s", json.dumps(data))
run_scenario_action = data.get("run")
if not run_scenario_action:
Expand Down
39 changes: 39 additions & 0 deletions overhave/admin/views/scenario_test_run.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import logging
from typing import cast

import flask
import werkzeug
from flask_admin import expose
from flask_admin.model.helpers import get_mdict_item_or_list
from flask_login import current_user
from wtforms import Form, ValidationError

from overhave import db
from overhave.admin.views.base import ModelViewConfigured
from overhave.factory import get_admin_factory, get_test_execution_factory
from overhave.pytest_plugin import get_proxy_manager
from overhave.transport import TestRunData, TestRunTask

logger = logging.getLogger(__name__)


class TestRunView(ModelViewConfigured):
Expand Down Expand Up @@ -61,6 +69,37 @@ def on_model_delete(self, model: db.TestRun) -> None:
if not (current_user.login == model.executed_by or current_user.role == db.Role.admin):
raise ValidationError("Only test run initiator could delete test run result!")

@staticmethod
def _run_test(rendered: werkzeug.Response) -> werkzeug.Response:
current_test_run_id = get_mdict_item_or_list(flask.request.args, "id")
factory = get_admin_factory()

with db.create_session() as session:
scenario_id = (
session.query(db.TestRun.scenario_id).filter(db.TestRun.id == current_test_run_id).one().scenario_id
)

test_run_id = factory.test_run_storage.create_testrun(scenario_id=scenario_id, executed_by=current_user.login)

if not factory.context.admin_settings.consumer_based:
proxy_manager = get_proxy_manager()
test_execution_factory = get_test_execution_factory()
proxy_manager.clear_factory()
proxy_manager.set_factory(test_execution_factory)
factory.threadpool.apply_async(get_test_execution_factory().test_executor.execute_test, args=(test_run_id,))
if factory.context.admin_settings.consumer_based and not factory.redis_producer.add_task(
TestRunTask(data=TestRunData(test_run_id=test_run_id))
):
flask.flash("Problems with Redis service! TestRunTask has not been sent.", category="error")
return rendered
logger.debug("Redirect to TestRun details view with test_run_id='%s'...", test_run_id)
return flask.redirect(flask.url_for("testrun.details_view", id=test_run_id))

@expose("/details/", methods=("GET", "POST"))
def details_view(self) -> werkzeug.Response:
rendered: werkzeug.Response = super().details_view()

if flask.request.method == "POST":
return self._run_test(rendered)

return cast(werkzeug.Response, super().details_view())
Loading