Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 1 | #! /usr/bin/env python3 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2 | # |
| 3 | # BitBake Toaster Implementation |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
| 6 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7 | # Copyright (C) 2013-2016 Intel Corporation |
| 8 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9 | |
| 10 | from django.core.urlresolvers import reverse |
| 11 | from django.utils import timezone |
| 12 | from tests.browser.selenium_helpers import SeleniumTestCase |
| 13 | |
| 14 | from orm.models import Project, Build |
| 15 | |
| 16 | class TestLandingPage(SeleniumTestCase): |
| 17 | """ Tests for redirects on the landing page """ |
| 18 | |
| 19 | PROJECT_NAME = 'test project' |
| 20 | LANDING_PAGE_TITLE = 'This is Toaster' |
| 21 | CLI_BUILDS_PROJECT_NAME = 'command line builds' |
| 22 | |
| 23 | def setUp(self): |
| 24 | """ Add default project manually """ |
| 25 | self.project = Project.objects.create_project( |
| 26 | self.CLI_BUILDS_PROJECT_NAME, |
| 27 | None |
| 28 | ) |
| 29 | self.project.is_default = True |
| 30 | self.project.save() |
| 31 | |
| 32 | def test_only_default_project(self): |
| 33 | """ |
| 34 | No projects except default |
| 35 | => should see the landing page |
| 36 | """ |
| 37 | self.get(reverse('landing')) |
| 38 | self.assertTrue(self.LANDING_PAGE_TITLE in self.get_page_source()) |
| 39 | |
| 40 | def test_default_project_has_build(self): |
| 41 | """ |
| 42 | Default project has a build, no other projects |
| 43 | => should see the builds page |
| 44 | """ |
| 45 | now = timezone.now() |
| 46 | build = Build.objects.create(project=self.project, |
| 47 | started_on=now, |
| 48 | completed_on=now) |
| 49 | build.save() |
| 50 | |
| 51 | self.get(reverse('landing')) |
| 52 | |
| 53 | elements = self.find_all('#allbuildstable') |
| 54 | self.assertEqual(len(elements), 1, 'should redirect to builds') |
| 55 | content = self.get_page_source() |
| 56 | self.assertFalse(self.PROJECT_NAME in content, |
| 57 | 'should not show builds for project %s' % self.PROJECT_NAME) |
| 58 | self.assertTrue(self.CLI_BUILDS_PROJECT_NAME in content, |
| 59 | 'should show builds for cli project') |
| 60 | |
| 61 | def test_user_project_exists(self): |
| 62 | """ |
| 63 | User has added a project (without builds) |
| 64 | => should see the projects page |
| 65 | """ |
| 66 | user_project = Project.objects.create_project('foo', None) |
| 67 | user_project.save() |
| 68 | |
| 69 | self.get(reverse('landing')) |
| 70 | |
| 71 | elements = self.find_all('#projectstable') |
| 72 | self.assertEqual(len(elements), 1, 'should redirect to projects') |
| 73 | |
| 74 | def test_user_project_has_build(self): |
| 75 | """ |
| 76 | User has added a project (with builds), command line builds doesn't |
| 77 | => should see the builds page |
| 78 | """ |
| 79 | user_project = Project.objects.create_project(self.PROJECT_NAME, None) |
| 80 | user_project.save() |
| 81 | |
| 82 | now = timezone.now() |
| 83 | build = Build.objects.create(project=user_project, |
| 84 | started_on=now, |
| 85 | completed_on=now) |
| 86 | build.save() |
| 87 | |
| 88 | self.get(reverse('landing')) |
| 89 | |
| 90 | elements = self.find_all('#allbuildstable') |
| 91 | self.assertEqual(len(elements), 1, 'should redirect to builds') |
| 92 | content = self.get_page_source() |
| 93 | self.assertTrue(self.PROJECT_NAME in content, |
| 94 | 'should show builds for project %s' % self.PROJECT_NAME) |
| 95 | self.assertFalse(self.CLI_BUILDS_PROJECT_NAME in content, |
| 96 | 'should not show builds for cli project') |