summaryrefslogtreecommitdiff
path: root/lib/toaster
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-07-24 16:05:20 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-19 11:31:25 +0100
commit771c08b9be1f7875e0216e381ab0a81ef0d26256 (patch)
treeed710864694d569e9a64788faf00b9f0696bca2f /lib/toaster
parentf3ee534cb0560dbb5f88a0ffe01e9305bae102e1 (diff)
downloadbitbake-771c08b9be1f7875e0216e381ab0a81ef0d26256.zip
toaster: hide irrelevant builds in the project builds view
This patch fixes the project builds view so it doesn't show "in progress" builds or builds for other projects. Note that this also modifies the "all builds" view to use the same queryset filtering as the project builds. This is to avoid excluding "in progress" builds more than once, which is what was happening before. The patch also has a minor change to ensure that when displaying the project builds page, only builds for that project are in the results. The queryset filtering is now split over several lines so you can see what's going on. [YOCTO #8236] [YOCTO #8187] Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/toaster')
-rw-r--r--lib/toaster/toastergui/tests.py91
-rwxr-xr-xlib/toaster/toastergui/views.py5
2 files changed, 90 insertions, 6 deletions
diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 1a8b4787..4d1549b0 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -24,10 +24,11 @@
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.utils import timezone
-from orm.models import Project, Release, BitbakeVersion, Build
-from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer
+from orm.models import Project, Release, BitbakeVersion, ProjectTarget
+from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Build
from orm.models import Layer_Version, Recipe, Machine, ProjectLayer
import json
+from bs4 import BeautifulSoup
PROJECT_NAME = "test project"
@@ -41,7 +42,6 @@ class ViewTests(TestCase):
bitbake_version=bbv)
self.project = Project.objects.create_project(name=PROJECT_NAME,
release=release)
-
layersrc = LayerSource.objects.create(sourcetype=LayerSource.TYPE_IMPORTED)
self.priority = ReleaseLayerSourcePriority.objects.create(release=release,
layer_source=layersrc)
@@ -292,3 +292,88 @@ class ProjectsPageTests(TestCase):
'should be a project row in the page')
self.assertTrue(self.PROJECT_NAME in response.content,
'default project "cli builds" should be in page')
+
+class ProjectBuildsDisplayTest(TestCase):
+ """ Test data at /project/X/builds is displayed correctly """
+
+ def setUp(self):
+ bbv = BitbakeVersion.objects.create(name="bbv1", giturl="/tmp/",
+ branch="master", dirpath="")
+ release = Release.objects.create(name="release1",
+ bitbake_version=bbv)
+ self.project1 = Project.objects.create_project(name=PROJECT_NAME,
+ release=release)
+ self.project2 = Project.objects.create_project(name=PROJECT_NAME,
+ release=release)
+
+ # parameters for builds to associate with the projects
+ now = timezone.now()
+
+ self.project1_build_success = {
+ "project": self.project1,
+ "started_on": now,
+ "completed_on": now,
+ "outcome": Build.SUCCEEDED
+ }
+
+ self.project1_build_in_progress = {
+ "project": self.project1,
+ "started_on": now,
+ "completed_on": now,
+ "outcome": Build.IN_PROGRESS
+ }
+
+ self.project2_build_success = {
+ "project": self.project2,
+ "started_on": now,
+ "completed_on": now,
+ "outcome": Build.SUCCEEDED
+ }
+
+ self.project2_build_in_progress = {
+ "project": self.project2,
+ "started_on": now,
+ "completed_on": now,
+ "outcome": Build.IN_PROGRESS
+ }
+
+ def _get_rows_for_project(self, project_id):
+ url = reverse("projectbuilds", args=(project_id,))
+ response = self.client.get(url, follow=True)
+ soup = BeautifulSoup(response.content)
+ return soup.select('tr[class="data"]')
+
+ def test_show_builds_for_project(self):
+ """ Builds for a project should be displayed """
+ build1a = Build.objects.create(**self.project1_build_success)
+ build1b = Build.objects.create(**self.project1_build_success)
+ build_rows = self._get_rows_for_project(self.project1.id)
+ self.assertEqual(len(build_rows), 2)
+
+ def test_show_builds_for_project_only(self):
+ """ Builds for other projects should be excluded """
+ build1a = Build.objects.create(**self.project1_build_success)
+ build1b = Build.objects.create(**self.project1_build_success)
+ build1c = Build.objects.create(**self.project1_build_success)
+
+ # shouldn't see these two
+ build2a = Build.objects.create(**self.project2_build_success)
+ build2b = Build.objects.create(**self.project2_build_in_progress)
+
+ build_rows = self._get_rows_for_project(self.project1.id)
+ self.assertEqual(len(build_rows), 3)
+
+ def test_show_builds_exclude_in_progress(self):
+ """ "in progress" builds should not be shown """
+ build1a = Build.objects.create(**self.project1_build_success)
+ build1b = Build.objects.create(**self.project1_build_success)
+
+ # shouldn't see this one
+ build1c = Build.objects.create(**self.project1_build_in_progress)
+
+ # shouldn't see these two either, as they belong to a different project
+ build2a = Build.objects.create(**self.project2_build_success)
+ build2b = Build.objects.create(**self.project2_build_in_progress)
+
+ build_rows = self._get_rows_for_project(self.project1.id)
+ self.assertEqual(len(build_rows), 2) \ No newline at end of file
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index d9802f01..8689a125 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -40,7 +40,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.utils import timezone
from django.utils.html import escape
-from datetime import timedelta, datetime, date
+from datetime import timedelta, datetime
from django.utils import formats
from toastergui.templatetags.projecttags import json as jsonfilter
import json
@@ -442,8 +442,7 @@ def _modify_date_range_filter(filter_string):
def _add_daterange_context(queryset_all, request, daterange_list):
# calculate the exact begining of local today and yesterday
today_begin = timezone.localtime(timezone.now())
- today_begin = date(today_begin.year,today_begin.month,today_begin.day)
- yesterday_begin = today_begin-timedelta(days=1)
+ yesterday_begin = today_begin - timedelta(days=1)
# add daterange persistent
context_date = {}
context_date['last_date_from'] = request.GET.get('last_date_from',timezone.localtime(timezone.now()).strftime("%d/%m/%Y"))