summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Oliveira <charles.oliveira@linaro.org>2020-04-13 10:58:11 -0300
committerCharles Oliveira <charles.oliveira@linaro.org>2020-04-14 17:48:56 -0300
commit3d5b536f3ccb4fc7d5a228d5c64ef49bc2fa0078 (patch)
treeb3833d3850f440fb081f63ca07fd00910389c4de
parent0b192f78a8516680bee031f41421b014f0751aa7 (diff)
core: models: use testrun status endpoint
-rw-r--r--squad_client/core/models.py31
-rw-r--r--tests/fixtures.py3
-rw-r--r--tests/test_models.py4
3 files changed, 24 insertions, 14 deletions
diff --git a/squad_client/core/models.py b/squad_client/core/models.py
index cd8e6a6..13b3d2d 100644
--- a/squad_client/core/models.py
+++ b/squad_client/core/models.py
@@ -307,6 +307,12 @@ class Metric(SquadObject):
pass
+class TestRunStatus(SquadObject):
+ attrs = ['id', 'tests_pass', 'tests_fail', 'tests_xfail',
+ 'tests_skip', 'metrics_summary', 'has_metrics',
+ 'suite', 'suite_version']
+
+
class TestRun(SquadObject):
endpoint = '/api/testruns/'
@@ -315,10 +321,6 @@ class TestRun(SquadObject):
'job_id', 'job_status', 'job_url', 'resubmit_url',
'data_processed', 'status_recorded', 'build',
'environment']
- total_fail = 0
- total_pass = 0
- total_skip = 0
- total_xfail = 0
metadata = None
attachments = None
log = None
@@ -367,19 +369,9 @@ class TestRun(SquadObject):
test_suite = Suite()
test_suite.name = suite_name
self.test_suites.append(test_suite)
-
for test in tests:
test_suite.add_test(test)
- if test.status == 'pass':
- self.total_pass += 1
- elif test.status == 'fail':
- self.total_fail += 1
- elif test.status == 'skip':
- self.total_skip += 1
- else:
- self.total_xfail += 1
-
all_metrics = self.metrics()
if len(all_metrics):
self.metric_suites = []
@@ -402,6 +394,17 @@ class TestRun(SquadObject):
log=self.log,
attachments=self.attachments)
+ __summary__ = None
+
+ def summary(self):
+ if self.__summary__ is None:
+ self.__summary__ = first(self.statuses(suite__isnull=True))
+ return self.__summary__
+
+ def statuses(self, count=ALL, **filters):
+ TestRunStatus.endpoint = '%s%d/status' % (self.endpoint, self.id)
+ return self.__fetch__(TestRunStatus, filters, count)
+
class Test(SquadObject):
diff --git a/tests/fixtures.py b/tests/fixtures.py
index d795d50..2e2ed1b 100644
--- a/tests/fixtures.py
+++ b/tests/fixtures.py
@@ -6,6 +6,7 @@
#
from squad.core import models as m
+from squad.core.tasks import RecordTestRunStatus
from squad.ci import models as mci
from rest_framework.authtoken.models import Token
@@ -35,6 +36,8 @@ failed_test = testrun.tests.create(suite=suite, result=False, name='my_failed_te
xfailed_test = testrun.tests.create(suite=suite, result=True, name='my_xfailed_test', has_known_issues=True)
skipped_test = testrun.tests.create(suite=suite, result=None, name='my_skipped_test')
+RecordTestRunStatus()(testrun)
+
backend = mci.Backend.objects.create()
testjob = testrun.test_jobs.create(backend=backend, target=project, target_build=build)
diff --git a/tests/test_models.py b/tests/test_models.py
index 25bd597..26fcc3e 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -118,3 +118,7 @@ class TestRunTest(unittest.TestCase):
def test_testrun_environment(self):
environment = self.testrun.environment
self.assertTrue(environment.__id__ != '')
+
+ def test_testrun_status(self):
+ status = self.testrun.summary()
+ self.assertEqual(1, status.tests_fail)