blob: 4d4cd660fbbd42712444ad19b292e6ea5a6416b0 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001#! /usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# BitBake Toaster Implementation
6#
7# Copyright (C) 2013-2016 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22from django.core.urlresolvers import reverse
23from django.utils import timezone
24from tests.browser.selenium_helpers import SeleniumTestCase
25
26from orm.models import Project, Build
27
28class TestLandingPage(SeleniumTestCase):
29 """ Tests for redirects on the landing page """
30
31 PROJECT_NAME = 'test project'
32 LANDING_PAGE_TITLE = 'This is Toaster'
33 CLI_BUILDS_PROJECT_NAME = 'command line builds'
34
35 def setUp(self):
36 """ Add default project manually """
37 self.project = Project.objects.create_project(
38 self.CLI_BUILDS_PROJECT_NAME,
39 None
40 )
41 self.project.is_default = True
42 self.project.save()
43
44 def test_only_default_project(self):
45 """
46 No projects except default
47 => should see the landing page
48 """
49 self.get(reverse('landing'))
50 self.assertTrue(self.LANDING_PAGE_TITLE in self.get_page_source())
51
52 def test_default_project_has_build(self):
53 """
54 Default project has a build, no other projects
55 => should see the builds page
56 """
57 now = timezone.now()
58 build = Build.objects.create(project=self.project,
59 started_on=now,
60 completed_on=now)
61 build.save()
62
63 self.get(reverse('landing'))
64
65 elements = self.find_all('#allbuildstable')
66 self.assertEqual(len(elements), 1, 'should redirect to builds')
67 content = self.get_page_source()
68 self.assertFalse(self.PROJECT_NAME in content,
69 'should not show builds for project %s' % self.PROJECT_NAME)
70 self.assertTrue(self.CLI_BUILDS_PROJECT_NAME in content,
71 'should show builds for cli project')
72
73 def test_user_project_exists(self):
74 """
75 User has added a project (without builds)
76 => should see the projects page
77 """
78 user_project = Project.objects.create_project('foo', None)
79 user_project.save()
80
81 self.get(reverse('landing'))
82
83 elements = self.find_all('#projectstable')
84 self.assertEqual(len(elements), 1, 'should redirect to projects')
85
86 def test_user_project_has_build(self):
87 """
88 User has added a project (with builds), command line builds doesn't
89 => should see the builds page
90 """
91 user_project = Project.objects.create_project(self.PROJECT_NAME, None)
92 user_project.save()
93
94 now = timezone.now()
95 build = Build.objects.create(project=user_project,
96 started_on=now,
97 completed_on=now)
98 build.save()
99
100 self.get(reverse('landing'))
101
102 elements = self.find_all('#allbuildstable')
103 self.assertEqual(len(elements), 1, 'should redirect to builds')
104 content = self.get_page_source()
105 self.assertTrue(self.PROJECT_NAME in content,
106 'should show builds for project %s' % self.PROJECT_NAME)
107 self.assertFalse(self.CLI_BUILDS_PROJECT_NAME in content,
108 'should not show builds for cli project')