From b5624c77ed91d20f1ab4737a921baa908cf00646 Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Wed, 14 Oct 2015 13:29:11 -0700 Subject: bitbake: toaster: Show 'not applicable' for default project machine and release The machine and release for the default project should show as 'not applicable' on the all projects page, as that information isn't available for command-line builds. Modify the templates with some conditionals to check for the default project row, plus some data-* attributes to mark where that data is to make testing possible. Add some tests for the all projects page to ensure that the correct machine/release are still shown for non-default projects, and 'not applicable' for the default project. [YOCTO #8231] (Bitbake rev: ce27b3fd728f0373aa1adc0d47baace264529b45) Signed-off-by: Elliot Smith Signed-off-by: Ed Bartosh Signed-off-by: brian avery Signed-off-by: Richard Purdie --- .../lib/toaster/toastergui/templates/projects.html | 16 ++- bitbake/lib/toaster/toastergui/tests.py | 108 +++++++++++++++++++-- 2 files changed, 111 insertions(+), 13 deletions(-) (limited to 'bitbake') diff --git a/bitbake/lib/toaster/toastergui/templates/projects.html b/bitbake/lib/toaster/toastergui/templates/projects.html index c2d77b5a37..a7192c2d72 100644 --- a/bitbake/lib/toaster/toastergui/templates/projects.html +++ b/bitbake/lib/toaster/toastergui/templates/projects.html @@ -36,17 +36,27 @@ {% else %} {# We have builds to display #} {% include "basetable_top.html" %} {% for o in objects %} - + {{o.name}} {{o.updated|date:"d/m/y H:i"}} - + {% if o.release %} {{o.release.name}} + {% elif o.is_default %} + Not applicable + {% else %} No release available {% endif %} - {{o.get_current_machine_name}} + + {% if o.is_default %} + Not applicable + + {% else %} + {{o.get_current_machine_name}} + {% endif %} + {% if o.get_number_of_builds == 0 %} {{o.get_number_of_builds}} diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 9156cc8952..d278d63aa1 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py @@ -29,7 +29,7 @@ from django.utils import timezone from orm.models import Project, Release, BitbakeVersion, Package from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Build from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target -from orm.models import CustomImageRecipe +from orm.models import CustomImageRecipe, ProjectVariable from orm.models import Branch from toastergui.tables import SoftwareRecipesTable @@ -430,15 +430,43 @@ class LandingPageTests(TestCase): class ProjectsPageTests(TestCase): """ Tests for projects page """ - PROJECT_NAME = 'cli builds' + MACHINE_NAME = 'delorean' + + def _add_build_to_default_project(self): + """ Add a build to the default project (not used in all tests) """ + now = timezone.now() + build = Build.objects.create(project=self.default_project, + started_on=now, + completed_on=now) + build.save() + + def _add_non_default_project(self): + """ Add another project """ + bbv = BitbakeVersion.objects.create(name="test bbv", giturl="/tmp/", + branch="master", dirpath="") + self.release = Release.objects.create(name="test release", + branch_name="master", + bitbake_version=bbv) + self.project = Project.objects.create_project(PROJECT_NAME, self.release) + self.project.is_default = False + self.project.save() + + # fake the MACHINE variable + project_var = ProjectVariable.objects.create(project=self.project, + name='MACHINE', + value=self.MACHINE_NAME) + project_var.save() def setUp(self): """ Add default project manually """ - project = Project.objects.create_project(self.PROJECT_NAME, None) + project = Project.objects.create_project(CLI_BUILDS_PROJECT_NAME, None) self.default_project = project self.default_project.is_default = True self.default_project.save() + # this project is only set for some of the tests + self.project = None + def test_default_project_hidden(self): """ The default project should be hidden if it has no builds """ params = {"count": 10, "orderby": "updated:-", "page": 1} @@ -446,25 +474,85 @@ class ProjectsPageTests(TestCase): self.assertTrue(not('tr class="data"' in response.content), 'should be no project rows in the page') - self.assertTrue(not(self.PROJECT_NAME in response.content), + self.assertTrue(not(CLI_BUILDS_PROJECT_NAME in response.content), 'default project "cli builds" should not be in page') def test_default_project_has_build(self): """ The default project should be shown if it has builds """ - now = timezone.now() - build = Build.objects.create(project=self.default_project, - started_on=now, - completed_on=now) - build.save() + self._add_build_to_default_project() params = {"count": 10, "orderby": "updated:-", "page": 1} response = self.client.get(reverse('all-projects'), params) self.assertTrue('tr class="data"' in response.content, 'should be a project row in the page') - self.assertTrue(self.PROJECT_NAME in response.content, + self.assertTrue(CLI_BUILDS_PROJECT_NAME in response.content, 'default project "cli builds" should be in page') + def test_default_project_release(self): + """ + The release for the default project should display as + 'Not applicable' + """ + # need a build, otherwise project doesn't display at all + self._add_build_to_default_project() + + # another project to test, which should show release + self._add_non_default_project() + + response = self.client.get(reverse('all-projects'), follow=True) + soup = BeautifulSoup(response.content) + + # check the release cell for the default project + attrs = {'data-project': str(self.default_project.id)} + rows = soup.find_all('tr', attrs=attrs) + self.assertEqual(len(rows), 1, 'should be one row for default project') + cells = rows[0].find_all('td', attrs={'data-project-field': 'release'}) + self.assertEqual(len(cells), 1, 'should be one release cell') + text = cells[0].select('span.muted')[0].text + self.assertEqual(text, 'Not applicable', + 'release should be not applicable for default project') + + # check the link in the release cell for the other project + attrs = {'data-project': str(self.project.id)} + rows = soup.find_all('tr', attrs=attrs) + cells = rows[0].find_all('td', attrs={'data-project-field': 'release'}) + text = cells[0].select('a')[0].text + self.assertEqual(text, self.release.name, + 'release name should be shown for non-default project') + + def test_default_project_machine(self): + """ + The machine for the default project should display as + 'Not applicable' + """ + # need a build, otherwise project doesn't display at all + self._add_build_to_default_project() + + # another project to test, which should show machine + self._add_non_default_project() + + response = self.client.get(reverse('all-projects'), follow=True) + soup = BeautifulSoup(response.content) + + # check the machine cell for the default project + attrs = {'data-project': str(self.default_project.id)} + rows = soup.find_all('tr', attrs=attrs) + self.assertEqual(len(rows), 1, 'should be one row for default project') + cells = rows[0].find_all('td', attrs={'data-project-field': 'machine'}) + self.assertEqual(len(cells), 1, 'should be one machine cell') + text = cells[0].select('span.muted')[0].text + self.assertEqual(text, 'Not applicable', + 'machine should be not applicable for default project') + + # check the link in the machine cell for the other project + attrs = {'data-project': str(self.project.id)} + rows = soup.find_all('tr', attrs=attrs) + cells = rows[0].find_all('td', attrs={'data-project-field': 'machine'}) + text = cells[0].select('a')[0].text + self.assertEqual(text, self.MACHINE_NAME, + 'machine name should be shown for non-default project') + class ProjectBuildsPageTests(TestCase): """ Test data at /project/X/builds is displayed correctly """ -- cgit v1.2.3-54-g00ecf