aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/tests.py
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2015-09-02 17:25:12 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-03 16:52:50 +0100
commitbc6a1a23e3d1af3861288a7abdbc9d5010470204 (patch)
tree87efdb5e096458e67bd083bc276e6e73941eb2ff /bitbake/lib/toaster/toastergui/tests.py
parent3b6d193cd7dc508d3285664b78b426fc5fd6e4a5 (diff)
downloadopenembedded-core-contrib-bc6a1a23e3d1af3861288a7abdbc9d5010470204.tar.gz
bitbake: toaster: Add tests for pages which show the default project
Test that the correct landing page redirect is applied, depending on the state of the default project. Test that the default project is only shown on the /projects page if it has at least one build. [YOCTO #7932] (Bitbake rev: 85a65d2b652c2ccc6cfb90fd8bc9048d0e72341e) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: brian avery <avery.brian@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/tests.py')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py115
1 files changed, 114 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index 7acf4bc31d..1a8b4787dd 100644
--- a/bitbake/lib/toaster/toastergui/tests.py
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -23,7 +23,8 @@
from django.test import TestCase
from django.core.urlresolvers import reverse
-from orm.models import Project, Release, BitbakeVersion
+from django.utils import timezone
+from orm.models import Project, Release, BitbakeVersion, Build
from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer
from orm.models import Layer_Version, Recipe, Machine, ProjectLayer
import json
@@ -179,3 +180,115 @@ class ViewTests(TestCase):
response = self.client.post(reverse('xhr_importlayer'), args)
data = json.loads(response.content)
self.assertNotEqual(data["error"], "ok")
+
+class LandingPageTests(TestCase):
+ """ Tests for redirects on the landing page """
+ # disable bogus pylint message error:
+ # "Instance of 'WSGIRequest' has no 'url' member (no-member)"
+ # (see https://github.com/landscapeio/pylint-django/issues/42)
+ # pylint: disable=E1103
+
+ LANDING_PAGE_TITLE = 'This is Toaster'
+
+ def setUp(self):
+ """ Add default project manually """
+ self.project = Project.objects.create_project('foo', None)
+ self.project.is_default = True
+ self.project.save()
+
+ def test_only_default_project(self):
+ """
+ No projects except default
+ => get the landing page
+ """
+ response = self.client.get(reverse('landing'))
+ self.assertTrue(self.LANDING_PAGE_TITLE in response.content)
+
+ def test_default_project_has_build(self):
+ """
+ Default project has a build, no other projects
+ => get the builds page
+ """
+ now = timezone.now()
+ build = Build.objects.create(project=self.project,
+ started_on=now,
+ completed_on=now)
+ build.save()
+
+ response = self.client.get(reverse('landing'))
+ self.assertEqual(response.status_code, 302,
+ 'response should be a redirect')
+ self.assertTrue('/builds' in response.url,
+ 'should redirect to builds')
+
+ def test_user_project_exists(self):
+ """
+ User has added a project (without builds)
+ => get the projects page
+ """
+ user_project = Project.objects.create_project('foo', None)
+ user_project.save()
+
+ response = self.client.get(reverse('landing'))
+ self.assertEqual(response.status_code, 302,
+ 'response should be a redirect')
+ self.assertTrue('/projects' in response.url,
+ 'should redirect to projects')
+
+ def test_user_project_has_build(self):
+ """
+ User has added a project (with builds)
+ => get the builds page
+ """
+ user_project = Project.objects.create_project('foo', None)
+ user_project.save()
+
+ now = timezone.now()
+ build = Build.objects.create(project=user_project,
+ started_on=now,
+ completed_on=now)
+ build.save()
+
+ response = self.client.get(reverse('landing'))
+ self.assertEqual(response.status_code, 302,
+ 'response should be a redirect')
+ self.assertTrue('/builds' in response.url,
+ 'should redirect to builds')
+
+class ProjectsPageTests(TestCase):
+ """ Tests for projects page """
+
+ PROJECT_NAME = 'cli builds'
+
+ def setUp(self):
+ """ Add default project manually """
+ project = Project.objects.create_project(self.PROJECT_NAME, None)
+ self.default_project = project
+ self.default_project.is_default = True
+ self.default_project.save()
+
+ def test_default_project_hidden(self):
+ """ The default project should be hidden if it has no builds """
+ params = {"count": 10, "orderby": "updated:-", "page": 1}
+ response = self.client.get(reverse('all-projects'), params)
+
+ 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),
+ '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()
+
+ 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,
+ 'default project "cli builds" should be in page')