Skip to content

Commit

Permalink
add history method for testresult
Browse files Browse the repository at this point in the history
  • Loading branch information
ira committed Jan 21, 2016
1 parent 017b6b6 commit 956d65b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
23 changes: 23 additions & 0 deletions cdws_api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,29 @@ def test_not_clean_actual_results(self):
cleanup_database()
self.assertEqual(len(self._get_testresults()['results']), 2)

def test_history(self):
project = Project.objects.get(name='DummyTestProject')
testplan1 = self.test_plan
testplan2 = TestPlan.objects.create(name='DummyTestPlan2',
project=project)

launches_tp1 = [self.launch,
Launch.objects.create(test_plan=testplan1,
started_by='http://2gis.local/')]

launch_tp2 = Launch.objects.create(test_plan=testplan2,
started_by='http://2gis.local/')

data11 = self._get_testresult_data(launches_tp1[0].id)
data12 = self._get_testresult_data(launches_tp1[1].id)
data21 = self._get_testresult_data(launch_tp2.id)
self._create_testresult(data11)
self._create_testresult(data12)
self._create_testresult(data21)

response = self._get_testresults('history=1')
self.assertEqual(2, response['count'])


class CommentsApiTestCase(AbstractEntityApiTestCase):
comment = 'Dummy comment text'
Expand Down
15 changes: 15 additions & 0 deletions cdws_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,21 @@ def custom_list(self, request, *args, **kwargs):
if 'state__in' in request.GET and request.GET['state__in'] != '':
self.queryset = self.queryset.filter(
state__in=request.GET['state__in'].split(','))
if 'history' in request.GET and request.GET['history'] != '':
result = TestResult.objects.get(id=request.GET['history'])
launch = Launch.objects.get(id=result.launch_id)
delta = datetime.datetime.today() - datetime.timedelta(days=100)
launches = Launch.objects.filter(
test_plan_id=launch.test_plan_id, created__gt=delta)

ids = []
for l in launches:
ids.append(l.id)

self.queryset = self.queryset.\
filter(launch_id__in=ids).\
filter(name=result.name, suite=result.suite).\
order_by('-launch')
return self.list(request, *args, **kwargs)


Expand Down
20 changes: 20 additions & 0 deletions testreport/migrations/0039_auto_20160120_1606.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('testreport', '0038_testplan_show_in_twodays'),
]

operations = [
migrations.AlterField(
model_name='testresult',
name='name',
field=models.CharField(db_index=True, max_length=128, verbose_name='Name'),
preserve_default=True,
),
]
2 changes: 1 addition & 1 deletion testreport/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __str__(self):

class TestResult(models.Model):
launch = models.ForeignKey(Launch)
name = models.CharField(_('Name'), max_length=128)
name = models.CharField(_('Name'), max_length=128, db_index=True)
suite = models.CharField(_('TestSuite'), max_length=256)
state = models.IntegerField(_('State'), default=BLOCKED)
failure_reason = models.TextField(_('Failure Reason'), default=None,
Expand Down

0 comments on commit 956d65b

Please sign in to comment.