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

Add last_passed_on and description in regression_test table #853

Merged
Merged
34 changes: 34 additions & 0 deletions migrations/versions/b3ed927671bd_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add last_passed_on and description fields in regression_test

Revision ID: b3ed927671bd
Revises: a5183973c3e9
Create Date: 2023-08-17 00:41:01.237549

"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import mysql
thealphadollar marked this conversation as resolved.
Show resolved Hide resolved

# revision identifiers, used by Alembic.
revision = 'b3ed927671bd'
down_revision = 'a5183973c3e9'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('regression_test', schema=None) as batch_op:
batch_op.add_column(sa.Column('last_passed_on', sa.Integer(), nullable=True))
batch_op.create_foreign_key('regression_test_ibfk_2', 'test', ['last_passed_on'], ['id'], onupdate='CASCADE', ondelete='SET NULL')
batch_op.add_column(sa.Column('description', sa.String(length=1024), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('regression_test', schema=None) as batch_op:
batch_op.drop_constraint('regression_test_ibfk_2', type_='foreignkey')
batch_op.drop_column('last_passed_on')
batch_op.drop_column('description')
# ### end Alembic commands ###
24 changes: 22 additions & 2 deletions mod_ci/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from markdown2 import markdown
from pymysql.err import IntegrityError
from sqlalchemy import and_, func, or_
from sqlalchemy.orm.query import Query
from sqlalchemy.sql import label
from sqlalchemy.sql.functions import count
from werkzeug.utils import secure_filename
Expand Down Expand Up @@ -1135,6 +1136,12 @@ def update_build_badge(status, test) -> None:
shutil.copyfile(original_location, build_status_location)
g.log.info('Build badge updated successfully!')

regression_testid_passed = get_query_regression_testid_passed(test.id)
test_ids_to_update = [result[0] for result in regression_testid_passed]
g.db.query(RegressionTest).filter(RegressionTest.id.in_(test_ids_to_update)
).update({"last_passed_on": test.id}, synchronize_session=False)
g.db.commit()


@mod_ci.route('/progress-reporter/<test_id>/<token>', methods=['POST'])
def progress_reporter(test_id, token):
Expand Down Expand Up @@ -1546,8 +1553,14 @@ def set_avg_time(platform, process_type: str, time_taken: int) -> None:
g.db.commit()


def get_info_for_pr_comment(test_id: int) -> PrCommentInfo:
"""Return info about the given test id for use in a PR comment."""
def get_query_regression_testid_passed(test_id: int) -> Query:
"""Get sqlalchemy query to fetch all regression tests which passed on given test id.

:param test_id: test id of the test whose query is required
:type test_id: int
:return: Query object for passed regression tests
:rtype: sqlalchemy.orm.query.Query
"""
regression_testid_passed = g.db.query(TestResult.regression_test_id).outerjoin(
TestResultFile, TestResult.test_id == TestResultFile.test_id).filter(
TestResult.test_id == test_id,
Expand All @@ -1572,6 +1585,13 @@ def get_info_for_pr_comment(test_id: int) -> PrCommentInfo:
)))
)).distinct().union(g.db.query(regression_testid_passed.c.regression_test_id))

return regression_testid_passed


def get_info_for_pr_comment(test_id: int) -> PrCommentInfo:
"""Return info about the given test id for use in a PR comment."""
regression_testid_passed = get_query_regression_testid_passed(test_id)

passed = g.db.query(label('category_id', Category.id), label(
'success', count(regressionTestLinkTable.c.regression_id))).filter(
regressionTestLinkTable.c.regression_id.in_(regression_testid_passed),
Expand Down
5 changes: 4 additions & 1 deletion mod_regression/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def test_edit(regression_id):
test.expected_rc = form.expected_rc.data
test.input_type = InputType.from_string(form.input_type.data)
test.output_type = OutputType.from_string(form.output_type.data)
test.description = form.description.data

g.db.commit()
g.log.info(f'regression test with id: {regression_id} updated!')
Expand All @@ -172,6 +173,7 @@ def test_edit(regression_id):
form.expected_rc.data = test.expected_rc
form.input_type.data = test.input_type.value
form.output_type.data = test.output_type.value
form.description.data = test.description

return {'form': form, 'regression_id': regression_id}

Expand Down Expand Up @@ -241,7 +243,8 @@ def test_add():
category_id=form.category_id.data,
expected_rc=form.expected_rc.data,
input_type=InputType.from_string(form.input_type.data),
output_type=OutputType.from_string(form.output_type.data)
output_type=OutputType.from_string(form.output_type.data),
description=form.description.data,
)
g.db.add(new_test)
category = Category.query.filter(Category.id == form.category_id.data).first()
Expand Down
3 changes: 2 additions & 1 deletion mod_regression/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask_wtf import FlaskForm
from wtforms import (HiddenField, IntegerField, SelectField, StringField,
SubmitField)
SubmitField, TextAreaField)
from wtforms.validators import DataRequired, InputRequired

from mod_regression.models import InputType, OutputType
Expand All @@ -21,6 +21,7 @@ class CommonTestForm(FlaskForm):

sample_id = SelectField("Sample", coerce=int)
command = StringField("Command")
description = TextAreaField("Description")
thealphadollar marked this conversation as resolved.
Show resolved Hide resolved
input_type = SelectField(
"Input Type",
[DataRequired(message="Input Type is not selected")],
Expand Down
6 changes: 5 additions & 1 deletion mod_regression/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ class RegressionTest(Base):
output_files = relationship('RegressionTestOutput', back_populates='regression_test')
expected_rc = Column(Integer)
active = Column(Boolean(), default=True)
last_passed_on = Column(Integer, ForeignKey('test.id', onupdate="CASCADE", ondelete="SET NULL"))
description = Column(String(length=1024))

def __init__(self, sample_id, command, input_type, output_type, category_id, expected_rc, active=True) -> None:
def __init__(self, sample_id, command, input_type, output_type, category_id, expected_rc,
active=True, description="") -> None:
"""
Parametrized constructor for the RegressionTest model.

Expand All @@ -122,6 +125,7 @@ def __init__(self, sample_id, command, input_type, output_type, category_id, exp
self.category_id = category_id
self.expected_rc = expected_rc
self.active = active
self.description = description

def __repr__(self) -> str:
"""
Expand Down
51 changes: 30 additions & 21 deletions templates/ci/pr_comment.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
<b>CCExtractor CI platform</b> finished running the test files on <b>{{platform}}</b>. Below is a summary of the test results:
thealphadollar marked this conversation as resolved.
Show resolved Hide resolved
<b>CCExtractor CI platform</b> finished running the test files on <b>{{platform}}</b>. Below is a summary of the test
results:
<table>
<thead>
<td> Report Name </td>
<td> Tests Passed </td>
</thead>
{% for test in tests%}
<tr>
<td> {{test.category}} </td>
{% if test.success==None %}
<td> <b> 0/{{test.total}} </b> </td>
{% elif test.success == test.total %}
<td> {{test.success}}/{{test.total}} </td>
{% else %}
<td> <b> {{test.success}}/{{test.total}} </b> </td>
{% endif %}
</tr>
{% endfor %}
<thead>
<td> Report Name </td>
<td> Tests Passed </td>
</thead>
{% for test in tests%}
<tr>
<td> {{test.category}} </td>
{% if test.success==None %}
<td> <b> 0/{{test.total}} </b> </td>
{% elif test.success == test.total %}
<td> {{test.success}}/{{test.total}} </td>
{% else %}
<td> <b> {{test.success}}/{{test.total}} </b> </td>
{% endif %}
</tr>
{% endfor %}
</table>
{% if state == "failure" %}
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).
It seems that not all tests were passed completely. This is an indication that the output of some files is not as
expected (but might be according to you).

Your PR breaks these cases:
<ul>
{% for test in failed_tests %}
<li> ccextractor {{ test.command }} <a href="{{ url_for('sample.sample_by_id', sample_id=test.sample.id, _external=True) }}">{{ test.sample.sha[:10] }}...</a> </li>
{% endfor %}
{% for test in failed_tests %}
<li> ccextractor {{ test.command }}
<a href="{{ url_for('sample.sample_by_id', sample_id=test.sample.id, _external=True) }}">
{{ test.sample.sha[:10] }}...
</a>
{% if test.last_passed_on %}
thealphadollar marked this conversation as resolved.
Show resolved Hide resolved
, Last passed: <a href="{{ url_for('test.by_id', test_id=test.last_passed_on, _external=True) }}">Test {{ test.last_passed_on }}</a>
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
All tests were passed completely.
Expand Down
3 changes: 3 additions & 0 deletions templates/regression/test_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ <h5>Regression Test Add</h5>
<div class="medium-12 columns">
{{ macros.render_field(form.sample_id) }}
</div>
<div class="medium-12 columns">
{{ macros.render_field(form.description) }}
</div>
<div class="medium-12 columns">
{{ macros.render_field(form.command) }}
</div>
Expand Down
3 changes: 3 additions & 0 deletions templates/regression/test_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ <h1>Regression Test Edit</h1>
<div class="medium-12 columns">
{{ macros.render_field(form.command) }}
</div>
<div class="medium-12 columns">
{{ macros.render_field(form.description) }}
</div>
<div class="medium-12 columns">
{{ macros.render_field(form.input_type) }}
</div>
Expand Down
1 change: 1 addition & 0 deletions templates/regression/test_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>Regression test {{ test.id }}</h1>
<p>Command: {{ test.command }}</p>
<p>Input type: {{ test.input_type.description }}</p>
<p>Output type: {{ test.output_type.description }}</p>
<p>Description: {{ test.description or "No description" }}</p>
<p>Output files:</p>
<ul>
{% for i in range(test.output_files|length) %}
Expand Down