Use run_name field to save display name of the run, and testrun_pattern as a pattern to filter testruns in testrail api
PRODX-35953
Change-Id: I3222313d3f9accae345b36f4a261c80911b29afb
diff --git a/testrail_bot/control/celery_tasks/test_rail_api.py b/testrail_bot/control/celery_tasks/test_rail_api.py
index cc3bfdb..00d4dc6 100644
--- a/testrail_bot/control/celery_tasks/test_rail_api.py
+++ b/testrail_bot/control/celery_tasks/test_rail_api.py
@@ -70,10 +70,11 @@
status_id: int = None,
project_name: str = "Mirantis Cloud Platform",
plan_name: str = None,
- run_name: str = None,
created_after: str = None,
created_before: str = None,
- created_by: int = None, **kwargs) -> \
+ created_by: int = None,
+ testrun_pattern: str = None,
+ **kwargs) -> \
Iterator[List[dict]]:
limit_step = 100
suite_id = api.cases.get_case(case_id=case_id)["suite_id"]
@@ -92,7 +93,7 @@
entries = get_entries(plan["id"])
for entry in entries:
for run in entry["runs"]:
- if run_name and run_name not in run["name"]:
+ if testrun_pattern and testrun_pattern not in run["name"]:
continue
if suite_id and run["suite_id"] != suite_id:
continue
diff --git a/testrail_bot/control/celery_tasks/testrail_pipeline.py b/testrail_bot/control/celery_tasks/testrail_pipeline.py
index d9e8c44..67d5e18 100644
--- a/testrail_bot/control/celery_tasks/testrail_pipeline.py
+++ b/testrail_bot/control/celery_tasks/testrail_pipeline.py
@@ -91,11 +91,10 @@
case_id: int,
last_comment: str,
plan_name: str,
- test_pattern: str,
+ testrun_pattern: str,
created_by_id: int,
created_after: int,
created_before: int,
- run_name: str,
text_filters: dict,
) -> Iterator[Tuple[Optional[dict], float, int]]:
"""
@@ -106,7 +105,7 @@
being searched
:param last_comment: The last comment associated with the failed test
:param plan_name: The name of the test plan to search within
- :param test_pattern: A pattern for filtering test runs
+ :param testrun_pattern: A pattern for filtering test runs
:param created_by_id: The ID of the user who created the test plan
:param created_after: The date (created_after) after which the test
plan was created
@@ -129,13 +128,13 @@
"created_before": int(dt.timestamp(end_lookup_date)),
"created_after": int(dt.timestamp(start_lookup_date)),
"plan_name": plan_name,
- "run_name": run_name,
"status_id": [StatusEnum.test_failed,
StatusEnum.failed,
StatusEnum.blocked,
StatusEnum.product_failed,
StatusEnum.wont_fix,
StatusEnum.retest],
+ "testrun_pattern": testrun_pattern
}
for n, results in enumerate(test_rail_api.get_result_history_for_case(
diff --git a/testrail_bot/control/forms.py b/testrail_bot/control/forms.py
index 76379ee..7a45622 100644
--- a/testrail_bot/control/forms.py
+++ b/testrail_bot/control/forms.py
@@ -18,7 +18,7 @@
"project_name": "Name of the project",
"plan_name": "Pattern for name of the Test Plan",
"run_name": "Name of the run",
- "test_pattern": "Pattern for name of the Test Run",
+ "testrun_pattern": "Pattern for name of the Test Run",
"run_id": "ID of the run/plan",
"created_by_id": "ID of the user that created Test Plan",
"filter_func": "Custom filter function",
diff --git a/testrail_bot/control/migrations/0008_rename_test_pattern_testrailtestrun_testrun_pattern.py b/testrail_bot/control/migrations/0008_rename_test_pattern_testrailtestrun_testrun_pattern.py
new file mode 100644
index 0000000..ec350ca
--- /dev/null
+++ b/testrail_bot/control/migrations/0008_rename_test_pattern_testrailtestrun_testrun_pattern.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.7 on 2024-02-06 19:04
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('control', '0007_testrailtestrun_caching_tests_enabled'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='testrailtestrun',
+ old_name='test_pattern',
+ new_name='testrun_pattern',
+ ),
+ ]
diff --git a/testrail_bot/control/models.py b/testrail_bot/control/models.py
index 71fd861..46c5049 100644
--- a/testrail_bot/control/models.py
+++ b/testrail_bot/control/models.py
@@ -34,7 +34,7 @@
default="Mirantis Cloud Platform")
plan_name = models.CharField(max_length=300, default="[MCP2.0]OSCORE")
run_name = models.CharField(max_length=300, blank=True)
- test_pattern = models.CharField(max_length=300, blank=True)
+ testrun_pattern = models.CharField(max_length=300, blank=True)
run_id = models.CharField(max_length=300)
checked_tests = IntegerListField(default=list())
caching_tests_enabled = models.BooleanField(default=False)
@@ -61,9 +61,8 @@
"created_by_id": self.created_by_id,
"created_after": self.created_after,
"created_before": self.created_before,
- "run_name": self.run_name,
+ "testrun_pattern": self.testrun_pattern,
"plan_name": self.plan_name,
- "test_pattern": self.test_pattern,
}
diff --git a/testrail_bot/control/template_tags/custom_tags.py b/testrail_bot/control/template_tags/custom_tags.py
index 92e203a..cef6606 100644
--- a/testrail_bot/control/template_tags/custom_tags.py
+++ b/testrail_bot/control/template_tags/custom_tags.py
@@ -8,3 +8,8 @@
return True
except ValueError:
return False
+
+
+@register.filter
+def split(string: str, sep=None):
+ return string.split(sep)
diff --git a/testrail_bot/control/templates/control/index.html b/testrail_bot/control/templates/control/index.html
index 64e3e99..8736ef9 100644
--- a/testrail_bot/control/templates/control/index.html
+++ b/testrail_bot/control/templates/control/index.html
@@ -6,7 +6,21 @@
<div class="list-group">
{% for run in runs %}
<a href="{% url 'single_run' run.id %}" class="list-group-item list-group-item-success">
- Run <b>{{run.run_id}}</b> from <b>{{run.plan_name}}</b> plan in <b>{{run.project_name}}</b> project
+ <div class="px-3 mx-2 fw-bold rounded-pill float-sm-start
+ text-white bg-dark">
+ {{run.run_id}}
+ </div>
+ {% if run.run_name %}
+ {% for part in run.run_name|split %}
+ {% if part in 'Run Plan from' %}
+ {{ part }}
+ {% else %}
+ <b>{{ part }}</b>
+ {% endif %}
+ {% endfor %}
+ {% else %}
+ Run from {{run.plan_name}} plan in {{run.project_name}} project
+ {% endif %}
</a>
{% endfor %}
</div>
diff --git a/testrail_bot/control/templates/control/update_run.html b/testrail_bot/control/templates/control/update_run.html
index 1ca8930..b11fbbf 100644
--- a/testrail_bot/control/templates/control/update_run.html
+++ b/testrail_bot/control/templates/control/update_run.html
@@ -57,7 +57,7 @@
{% bootstrap_field form.plan_name size='sm' %}</div>
<div class="col-xs-8">
- {% bootstrap_field form.test_pattern size='sm' %}</div>
+ {% bootstrap_field form.testrun_pattern size='sm' %}</div>
<div class="col-xs-8">
{% bootstrap_field form.created_by_id size='sm' %}</div>
@@ -77,7 +77,6 @@
<a href="https://mirantis.testrail.com/index.php?/tests/view/{{ test_id }}">{{ test_id }}</a>
{% endfor %}
</div>
-
</div>
<div class="p-3 mt-5 bg-light bg-gradient">
<h5>Text filters</h5>
diff --git a/testrail_bot/control/views.py b/testrail_bot/control/views.py
index 7a34327..bff73e0 100644
--- a/testrail_bot/control/views.py
+++ b/testrail_bot/control/views.py
@@ -84,18 +84,25 @@
def submit_run(request, run_id):
run = models.TestRailTestRun.objects.get(pk=run_id)
is_testplan = test_rail_api.is_testplan(run.run_id)
-
if is_testplan:
testrail_run = test_rail_api.get_plan_by_id(run.run_id)
else:
testrail_run = test_rail_api.get_run_by_id(run.run_id)
- run_name = 'Plan-' if is_testplan else "Run-"
if not run.run_name:
- run_name += testrail_run['name']
- if run.test_pattern:
- run_name += "-" + run.test_pattern
+ if is_testplan:
+ _name = f"Plan {testrail_run['name']}"
+ else:
+ parent_plan_id = testrail_run["plan_id"]
+ parent_plan_name = \
+ test_rail_api.get_plan_by_id(parent_plan_id)["name"]
+ _name = f"Run {testrail_run['name']} from {parent_plan_name}"
+ run.run_name = _name
+ run.save()
+
report_name = "{}-run_id-{}-date-{}".format(
- run_name, run.run_id, datetime.datetime.isoformat(datetime.datetime.now()))
+ run.run_name,
+ run.run_id,
+ datetime.datetime.isoformat(datetime.datetime.now()))
path = os.path.join(models.fs.location, report_name)
with open(path, "w"):
pass
diff --git a/testrail_bot/testrail_bot/settings.py b/testrail_bot/testrail_bot/settings.py
index 240f9df..bc49975 100644
--- a/testrail_bot/testrail_bot/settings.py
+++ b/testrail_bot/testrail_bot/settings.py
@@ -162,4 +162,3 @@
JIRA_PASSWORD = os.environ.get("JIRA_PASSWORD")
JIRA_SERVER = os.environ.get("JIRA_SERVER",
default="https://mirantis.jira.com")
-