Skip to content

Commit 309c4c2

Browse files
Add last_passed_on and description in regression_test table (#853)
Co-authored-by: Shivam Kumar Jha <code@thealphadollar.me>
1 parent d30129e commit 309c4c2

File tree

10 files changed

+86
-7
lines changed

10 files changed

+86
-7
lines changed

migrations/versions/b3ed927671bd_.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Add last_passed_on and description fields in regression_test
2+
3+
Revision ID: b3ed927671bd
4+
Revises: a5183973c3e9
5+
Create Date: 2023-08-17 00:41:01.237549
6+
7+
"""
8+
import sqlalchemy as sa
9+
from alembic import op
10+
from sqlalchemy.dialects import mysql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'b3ed927671bd'
14+
down_revision = 'a5183973c3e9'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
with op.batch_alter_table('regression_test', schema=None) as batch_op:
22+
batch_op.add_column(sa.Column('last_passed_on', sa.Integer(), nullable=True))
23+
batch_op.create_foreign_key('regression_test_ibfk_2', 'test', ['last_passed_on'], ['id'], onupdate='CASCADE', ondelete='SET NULL')
24+
batch_op.add_column(sa.Column('description', sa.String(length=1024), nullable=True))
25+
# ### end Alembic commands ###
26+
27+
28+
def downgrade():
29+
# ### commands auto generated by Alembic - please adjust! ###
30+
with op.batch_alter_table('regression_test', schema=None) as batch_op:
31+
batch_op.drop_constraint('regression_test_ibfk_2', type_='foreignkey')
32+
batch_op.drop_column('last_passed_on')
33+
batch_op.drop_column('description')
34+
# ### end Alembic commands ###

mod_ci/controllers.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from markdown2 import markdown
2323
from pymysql.err import IntegrityError
2424
from sqlalchemy import and_, func, or_
25+
from sqlalchemy.orm.query import Query
2526
from sqlalchemy.sql import label
2627
from sqlalchemy.sql.functions import count
2728
from werkzeug.utils import secure_filename
@@ -1130,6 +1131,12 @@ def update_build_badge(status, test) -> None:
11301131
shutil.copyfile(original_location, build_status_location)
11311132
g.log.info('Build badge updated successfully!')
11321133

1134+
regression_testid_passed = get_query_regression_testid_passed(test.id)
1135+
test_ids_to_update = [result[0] for result in regression_testid_passed]
1136+
g.db.query(RegressionTest).filter(RegressionTest.id.in_(test_ids_to_update)
1137+
).update({"last_passed_on": test.id}, synchronize_session=False)
1138+
g.db.commit()
1139+
11331140

11341141
@mod_ci.route('/progress-reporter/<test_id>/<token>', methods=['POST'])
11351142
def progress_reporter(test_id, token):
@@ -1541,8 +1548,14 @@ def set_avg_time(platform, process_type: str, time_taken: int) -> None:
15411548
g.db.commit()
15421549

15431550

1544-
def get_info_for_pr_comment(test_id: int) -> PrCommentInfo:
1545-
"""Return info about the given test id for use in a PR comment."""
1551+
def get_query_regression_testid_passed(test_id: int) -> Query:
1552+
"""Get sqlalchemy query to fetch all regression tests which passed on given test id.
1553+
1554+
:param test_id: test id of the test whose query is required
1555+
:type test_id: int
1556+
:return: Query object for passed regression tests
1557+
:rtype: sqlalchemy.orm.query.Query
1558+
"""
15461559
regression_testid_passed = g.db.query(TestResult.regression_test_id).outerjoin(
15471560
TestResultFile, TestResult.test_id == TestResultFile.test_id).filter(
15481561
TestResult.test_id == test_id,
@@ -1567,6 +1580,13 @@ def get_info_for_pr_comment(test_id: int) -> PrCommentInfo:
15671580
)))
15681581
)).distinct().union(g.db.query(regression_testid_passed.c.regression_test_id))
15691582

1583+
return regression_testid_passed
1584+
1585+
1586+
def get_info_for_pr_comment(test_id: int) -> PrCommentInfo:
1587+
"""Return info about the given test id for use in a PR comment."""
1588+
regression_testid_passed = get_query_regression_testid_passed(test_id)
1589+
15701590
passed = g.db.query(label('category_id', Category.id), label(
15711591
'success', count(regressionTestLinkTable.c.regression_id))).filter(
15721592
regressionTestLinkTable.c.regression_id.in_(regression_testid_passed),

mod_regression/controllers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def test_edit(regression_id):
159159
test.expected_rc = form.expected_rc.data
160160
test.input_type = InputType.from_string(form.input_type.data)
161161
test.output_type = OutputType.from_string(form.output_type.data)
162+
test.description = form.description.data
162163

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

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

@@ -241,7 +243,8 @@ def test_add():
241243
category_id=form.category_id.data,
242244
expected_rc=form.expected_rc.data,
243245
input_type=InputType.from_string(form.input_type.data),
244-
output_type=OutputType.from_string(form.output_type.data)
246+
output_type=OutputType.from_string(form.output_type.data),
247+
description=form.description.data,
245248
)
246249
g.db.add(new_test)
247250
category = Category.query.filter(Category.id == form.category_id.data).first()

mod_regression/forms.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from flask_wtf import FlaskForm
44
from wtforms import (HiddenField, IntegerField, SelectField, StringField,
5-
SubmitField)
6-
from wtforms.validators import DataRequired, InputRequired
5+
SubmitField, TextAreaField)
6+
from wtforms.validators import DataRequired, InputRequired, Length
77

88
from mod_regression.models import InputType, OutputType
99

@@ -21,6 +21,7 @@ class CommonTestForm(FlaskForm):
2121

2222
sample_id = SelectField("Sample", coerce=int)
2323
command = StringField("Command")
24+
description = TextAreaField("Description", validators=[Length(max=1024)])
2425
input_type = SelectField(
2526
"Input Type",
2627
[DataRequired(message="Input Type is not selected")],

mod_regression/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ class RegressionTest(Base):
9494
output_files = relationship('RegressionTestOutput', back_populates='regression_test')
9595
expected_rc = Column(Integer)
9696
active = Column(Boolean(), default=True)
97+
last_passed_on = Column(Integer, ForeignKey('test.id', onupdate="CASCADE", ondelete="SET NULL"))
98+
description = Column(String(length=1024))
9799

98-
def __init__(self, sample_id, command, input_type, output_type, category_id, expected_rc, active=True) -> None:
100+
def __init__(self, sample_id, command, input_type, output_type, category_id, expected_rc,
101+
active=True, description="") -> None:
99102
"""
100103
Parametrized constructor for the RegressionTest model.
101104
@@ -122,6 +125,7 @@ def __init__(self, sample_id, command, input_type, output_type, category_id, exp
122125
self.category_id = category_id
123126
self.expected_rc = expected_rc
124127
self.active = active
128+
self.description = description
125129

126130
def __repr__(self) -> str:
127131
"""

templates/ci/pr_comment.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ It seems that not all tests were passed completely. This is an indication that t
2323
Your PR breaks these cases:
2424
<ul>
2525
{% for test in failed_tests %}
26-
<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>
26+
<li> ccextractor {{ test.command }} <a href="{{ url_for('sample.sample_by_id', sample_id=test.sample.id, _external=True) }}">{{ test.sample.sha[:10] }}...</a>, Last passed: {% if test.last_passed_on %}<a href="{{ url_for('test.by_id', test_id=test.last_passed_on, _external=True) }}">Test {{ test.last_passed_on }}</a>{% else %}<span>Never</span>{% endif %}</li>
2727
{% endfor %}
2828
</ul>
2929
{% else %}

templates/regression/test_add.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ <h5>Regression Test Add</h5>
3838
<div class="medium-12 columns">
3939
{{ macros.render_field(form.sample_id) }}
4040
</div>
41+
<div class="medium-12 columns">
42+
{{ macros.render_field(form.description) }}
43+
</div>
4144
<div class="medium-12 columns">
4245
{{ macros.render_field(form.command) }}
4346
</div>

templates/regression/test_edit.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ <h1>Regression Test Edit</h1>
3939
<div class="medium-12 columns">
4040
{{ macros.render_field(form.command) }}
4141
</div>
42+
<div class="medium-12 columns">
43+
{{ macros.render_field(form.description) }}
44+
</div>
4245
<div class="medium-12 columns">
4346
{{ macros.render_field(form.input_type) }}
4447
</div>

templates/regression/test_view.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ <h1>Regression test {{ test.id }}</h1>
1111
<p>Command: {{ test.command }}</p>
1212
<p>Input type: {{ test.input_type.description }}</p>
1313
<p>Output type: {{ test.output_type.description }}</p>
14+
<p>Description: {{ test.description or "No description" }}</p>
1415
<p>Output files:</p>
1516
<ul>
1617
{% for i in range(test.output_files|length) %}

tests/test_regression/test_controllers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ def test_category_delete(self):
256256
))
257257
self.assertEqual(response.status_code, 302)
258258

259+
def test_edit_test_get_request(self):
260+
"""Test editing of regression test with a GET request."""
261+
self.create_user_with_role(self.user.name, self.user.email, self.user.password, Role.admin)
262+
263+
with self.app.test_client() as c:
264+
c.post('/account/login', data=self.create_login_form_data(self.user.email, self.user.password))
265+
response = c.get('/regression/test/2/edit')
266+
self.assertEqual(response.status_code, 200)
267+
self.assertIn('Editing regression test with id 2', str(response.data))
268+
259269
def test_edit_test(self):
260270
"""Check it will edit a regression test."""
261271
self.create_user_with_role(self.user.name, self.user.email, self.user.password, Role.admin)

0 commit comments

Comments
 (0)