Skip to contentSkip to conversation

toaster: tests Migrate to Selenium for UI tests

PATCH New Michael Wood 1 participant 5 messages Mar 31, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 toaster: tests Migrate to Selenium for UI tests

From: Elliot Smith <[email protected]>

Create a new folder for Selenium tests.

Add a new base Selenium testcase class and a helper which instantiates a webdriver for a given browser.

Add a sample Selenium test case which can be used as a template for creating new tests.

---
 lib/toaster/tests/__init__.py                    |   0
 lib/toaster/tests/browser/README                 |  41 +++++
 lib/toaster/tests/browser/__init__.py            |   0
 lib/toaster/tests/browser/selenium_helpers.py    | 200 +++++++++++++++++++++++
 lib/toaster/tests/browser/test_sample.py         |  41 +++++
 lib/toaster/tests/toaster-tests-requirements.txt |   1 +
 6 files changed, 283 insertions(+)
 create mode 100644 lib/toaster/tests/__init__.py
 create mode 100644 lib/toaster/tests/browser/README
 create mode 100644 lib/toaster/tests/browser/__init__.py
 create mode 100644 lib/toaster/tests/browser/selenium_helpers.py
 create mode 100644 lib/toaster/tests/browser/test_sample.py
 create mode 100644 lib/toaster/tests/toaster-tests-requirements.txt
lib/toaster/tests/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
lib/toaster/tests/browser/README new file +41 -0

41 lines not on this page · raw message

lib/toaster/tests/browser/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
lib/toaster/tests/browser/selenium_helpers.py new file +200 -0

200 lines not on this page · raw message

lib/toaster/tests/browser/test_sample.py new file +41 -0

41 lines not on this page · raw message

lib/toaster/tests/toaster-tests-requirements.txt new file +1 -0
new file mode 100644
index 0000000..4f9fcc4
@@ -0,0 +1 @@
+selenium==2.49.2
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/5 toaster: tests Migrate all builds page and project page tests to Selenium

From: Elliot Smith <[email protected]>

---
 lib/toaster/tests/browser/test_all_builds_page.py | 143 ++++++++++++++++++++++
 lib/toaster/tests/browser/test_project_page.py    |  59 +++++++++
 lib/toaster/toastergui/tests.py                   | 140 ---------------------
 3 files changed, 202 insertions(+), 140 deletions(-)
 create mode 100644 lib/toaster/tests/browser/test_all_builds_page.py
 create mode 100644 lib/toaster/tests/browser/test_project_page.py
lib/toaster/tests/browser/test_all_builds_page.py new file +143 -0
new file mode 100644
index 0000000..e4223f4
@@ -0,0 +1,143 @@
+#! /usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# BitBake Toaster Implementation
+#
+# Copyright (C) 2013-2016 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import re
+
+from django.core.urlresolvers import reverse
+from django.utils import timezone
+from tests.browser.selenium_helpers import SeleniumTestCase
+
+from orm.models import BitbakeVersion, Release, Project, Build, Target
+
+class TestAllBuildsPage(SeleniumTestCase):
+    """ Tests for all builds page /builds/ """
+
+    PROJECT_NAME = 'test project'
+    CLI_BUILDS_PROJECT_NAME = 'command line builds'
+
+    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=self.PROJECT_NAME,
+                                                       release=release)
+        self.default_project = Project.objects.create_project(
+            name=self.CLI_BUILDS_PROJECT_NAME,
+            release=release
+        )
+        self.default_project.is_default = True
+        self.default_project.save()
+
+        # 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.default_project_build_success = {
+            'project': self.default_project,
+            'started_on': now,
+            'completed_on': now,
+            'outcome': Build.SUCCEEDED
+        }
+
+    def test_show_tasks_with_suffix(self):
+        """ Task should be shown as suffix on build name """
+        build = Build.objects.create(**self.project1_build_success)
+        target = 'bash'
+        task = 'clean'
+        Target.objects.create(build=build, target=target, task=task)
+
+        url = reverse('all-builds')
+        self.get(url)
+        self.wait_until_present('td[class="target"]')
+
+        cell = self.find('td[class="target"]')
+        content = cell.get_attribute('innerHTML')
+        expected_text = '%s:%s' % (target, task)
+
+        self.assertTrue(re.search(expected_text, content),
+                        '"target" cell should contain text %s' % expected_text)
+
+    def test_rebuild_buttons(self):
+        """
+        Test 'Rebuild' buttons in recent builds section
+
+        'Rebuild' button should not be shown for command-line builds,
+        but should be shown for other builds
+        """
+        build1 = Build.objects.create(**self.project1_build_success)
+        default_build = Build.objects.create(**self.default_project_build_success)
+
+        url = reverse('all-builds')
+        self.get(url)
+
+        # shouldn't see a run again button for command-line builds
+        selector = 'div[data-latest-build-result="%s"] button' % default_build.id
+        run_again_button = self.find_all(selector)
+        self.assertEqual(len(run_again_button), 0,
+                         'should not see a run again button for cli builds')
+
+        # should see a run again button for non-command-line builds
+        selector = 'div[data-latest-build-result="%s"] button' % build1.id
+        run_again_button = self.find_all(selector)
+        self.assertEqual(len(run_again_button), 1,
+                         'should see a run again button for non-cli builds')
+
+    def test_tooltips_on_project_name(self):
+        """
+        Test tooltips shown next to project name in the main table
+
+        A tooltip should be present next to the command line
+        builds project name in the all builds page, but not for
+        other projects
+        """
+        Build.objects.create(**self.project1_build_success)
+        Build.objects.create(**self.default_project_build_success)
+
+        url = reverse('all-builds')
+        self.get(url)
+
+        # get the project name cells from the table
+        cells = self.find_all('#allbuildstable td[class="project"]')
+
+        selector = 'i.get-help'
+
+        for cell in cells:
+            content = cell.get_attribute('innerHTML')
+            help_icons = cell.find_elements_by_css_selector(selector)
+
+            if re.search(self.PROJECT_NAME, content):
+                # no help icon next to non-cli project name
+                msg = 'should not be a help icon for non-cli builds name'
+                self.assertEqual(len(help_icons), 0, msg)
+            elif re.search(self.CLI_BUILDS_PROJECT_NAME, content):
+                # help icon next to cli project name
+                msg = 'should be a help icon for cli builds name'
+                self.assertEqual(len(help_icons), 1, msg)
+            else:
+                msg = 'found unexpected project name cell in all builds table'
+                self.fail(msg)
lib/toaster/tests/browser/test_project_page.py new file +59 -0

59 lines not on this page · raw message

lib/toaster/toastergui/tests.py +0 -140

146 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw

PATCH 3/5 toaster: tests Migrate project builds page tests to Selenium

In reply to Michael Wood

From: Elliot Smith <[email protected]>

---
 .../tests/browser/test_project_builds_page.py      | 168 +++++++++++++++++++++
 lib/toaster/toastergui/tests.py                    | 133 ----------------
 2 files changed, 168 insertions(+), 133 deletions(-)
 create mode 100644 lib/toaster/tests/browser/test_project_builds_page.py
lib/toaster/tests/browser/test_project_builds_page.py new file +168 -0
new file mode 100644
index 0000000..9fe91ab
@@ -0,0 +1,168 @@
+#! /usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# BitBake Toaster Implementation
+#
+# Copyright (C) 2013-2016 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import re
+
+from django.core.urlresolvers import reverse
+from django.utils import timezone
+from tests.browser.selenium_helpers import SeleniumTestCase
+
+from orm.models import BitbakeVersion, Release, Project, Build, Target
+
+class TestProjectBuildsPage(SeleniumTestCase):
+    """ Test data at /project/X/builds is displayed correctly """
+
+    PROJECT_NAME = 'test project'
+    CLI_BUILDS_PROJECT_NAME = 'command line builds'
+
+    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=self.PROJECT_NAME,
+                                                       release=release)
+        self.project1.save()
+
+        self.project2 = Project.objects.create_project(name=self.PROJECT_NAME,
+                                                       release=release)
+        self.project2.save()
+
+        self.default_project = Project.objects.create_project(
+            name=self.CLI_BUILDS_PROJECT_NAME,
+            release=release
+        )
+        self.default_project.is_default = True
+        self.default_project.save()
+
+        # 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):
+        """
+        Helper to retrieve HTML rows for a project's builds,
+        as shown in the main table of the page
+        """
+        url = reverse('projectbuilds', args=(project_id,))
+        self.get(url)
+        self.wait_until_present('#projectbuildstable tbody tr')
+        return self.find_all('#projectbuildstable tbody tr')
+
+    def test_show_builds_for_project(self):
+        """ Builds for a project should be displayed in the main table """
+        Build.objects.create(**self.project1_build_success)
+        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_project_only(self):
+        """ Builds for other projects should be excluded """
+        Build.objects.create(**self.project1_build_success)
+        Build.objects.create(**self.project1_build_success)
+        Build.objects.create(**self.project1_build_success)
+
+        # shouldn't see these two
+        Build.objects.create(**self.project2_build_success)
+        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_builds_exclude_in_progress(self):
+        """ "in progress" builds should not be shown in main table """
+        Build.objects.create(**self.project1_build_success)
+        Build.objects.create(**self.project1_build_success)
+
+        # shouldn't see this one
+        Build.objects.create(**self.project1_build_in_progress)
+
+        # shouldn't see these two either, as they belong to a different project
+        Build.objects.create(**self.project2_build_success)
+        Build.objects.create(**self.project2_build_in_progress)
+
+        build_rows = self._get_rows_for_project(self.project1.id)
+        self.assertEqual(len(build_rows), 2)
+
+    def test_show_tasks_with_suffix(self):
+        """ Task should be shown as suffixes on build names """
+        build = Build.objects.create(**self.project1_build_success)
+        target = 'bash'
+        task = 'clean'
+        Target.objects.create(build=build, target=target, task=task)
+
+        url = reverse('projectbuilds', args=(self.project1.id,))
+        self.get(url)
+        self.wait_until_present('td[class="target"]')
+
+        cell = self.find('td[class="target"]')
+        content = cell.get_attribute('innerHTML')
+        expected_text = '%s:%s' % (target, task)
+
+        self.assertTrue(re.search(expected_text, content),
+                        '"target" cell should contain text %s' % expected_text)
+
+    def test_cli_builds_hides_tabs(self):
+        """
+        Display for command line builds should hide tabs
+        """
+        url = reverse('projectbuilds', args=(self.default_project.id,))
+        self.get(url)
+        tabs = self.find_all('#project-topbar')
+        self.assertEqual(len(tabs), 0,
+                         'should be no top bar shown for command line builds')
+
+    def test_non_cli_builds_has_tabs(self):
+        """
+        Non-command-line builds projects should show the tabs
+        """
+        url = reverse('projectbuilds', args=(self.project1.id,))
+        self.get(url)
+        tabs = self.find_all('#project-topbar')
+        self.assertEqual(len(tabs), 1,
+                         'should be a top bar shown for non-command-line builds')
lib/toaster/toastergui/tests.py +0 -133

139 lines not on this page · raw message

Signature · 1 line
2.1.4
#3 lore raw

PATCH 4/5 toaster: tests Migrate all projects page tests to Selenium

In reply to Michael Wood

From: Elliot Smith <[email protected]>

---
 .../tests/browser/test_all_projects_page.py        | 214 +++++++++++++++++++++
 lib/toaster/toastergui/tests.py                    | 197 -------------------
 2 files changed, 214 insertions(+), 197 deletions(-)
 create mode 100644 lib/toaster/tests/browser/test_all_projects_page.py
lib/toaster/tests/browser/test_all_projects_page.py new file +214 -0
new file mode 100644
index 0000000..ed8e620
@@ -0,0 +1,214 @@
+#! /usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# BitBake Toaster Implementation
+#
+# Copyright (C) 2013-2016 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import re
+
+from django.core.urlresolvers import reverse
+from django.utils import timezone
+from tests.browser.selenium_helpers import SeleniumTestCase
+
+from orm.models import BitbakeVersion, Release, Project, Build
+from orm.models import ProjectVariable
+
+class TestAllProjectsPage(SeleniumTestCase):
+    """ Browser tests for projects page /projects/ """
+
+    PROJECT_NAME = 'test project'
+    CLI_BUILDS_PROJECT_NAME = 'command line builds'
+    MACHINE_NAME = 'delorean'
+
+    def setUp(self):
+        """ Add default project manually """
+        project = Project.objects.create_project(self.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
+
+        self.release = None
+
+    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(self.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 _get_row_for_project(self, project_name):
+        """ Get the HTML row for a project, or None if not found """
+        self.wait_until_present('#projectstable tbody tr')
+        rows = self.find_all('#projectstable tbody tr')
+
+        # find the row with a project name matching the one supplied
+        found_row = None
+        for row in rows:
+            if re.search(project_name, row.get_attribute('innerHTML')):
+                found_row = row
+                break
+
+        return found_row
+
+    def test_default_project_hidden(self):
+        """
+        The default project should be hidden if it has no builds
+        and we should see the "no results" area
+        """
+        url = reverse('all-projects')
+        self.get(url)
+        self.wait_until_visible('#no-results-projectstable')
+
+        rows = self.find_all('#projectstable tbody tr')
+        self.assertEqual(len(rows), 0, 'should be no projects displayed')
+
+    def test_default_project_has_build(self):
+        """ The default project should be shown if it has builds """
+        self._add_build_to_default_project()
+
+        url = reverse('all-projects')
+        self.get(url)
+
+        default_project_row = self._get_row_for_project(self.default_project.name)
+
+        self.assertNotEqual(default_project_row, None,
+                            '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()
+
+        self.get(reverse('all-projects'))
+
+        # find the row for the default project
+        default_project_row = self._get_row_for_project(self.default_project.name)
+
+        # check the release text for the default project
+        selector = 'span[data-project-field="release"] span.muted'
+        element = default_project_row.find_element_by_css_selector(selector)
+        text = element.text.strip()
+        self.assertEqual(text, 'Not applicable',
+                         'release should be "not applicable" for default project')
+
+        # find the row for the default project
+        other_project_row = self._get_row_for_project(self.project.name)
+
+        # check the link in the release cell for the other project
+        selector = 'span[data-project-field="release"] a'
+        element = other_project_row.find_element_by_css_selector(selector)
+        text = element.text.strip()
+        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()
+
+        self.get(reverse('all-projects'))
+
+        # find the row for the default project
+        default_project_row = self._get_row_for_project(self.default_project.name)
+
+        # check the machine cell for the default project
+        selector = 'span[data-project-field="machine"] span.muted'
+        element = default_project_row.find_element_by_css_selector(selector)
+        text = element.text.strip()
+        self.assertEqual(text, 'Not applicable',
+                         'machine should be not applicable for default project')
+
+        # find the row for the default project
+        other_project_row = self._get_row_for_project(self.project.name)
+
+        # check the link in the machine cell for the other project
+        selector = 'span[data-project-field="machine"] a'
+        element = other_project_row.find_element_by_css_selector(selector)
+        text = element.text.strip()
+        self.assertEqual(text, self.MACHINE_NAME,
+                         'machine name should be shown for non-default project')
+
+    def test_project_page_links(self):
+        """
+        Test that links for the default project point to the builds
+        page /projects/X/builds for that project, and that links for
+        other projects point to their configuration pages /projects/X/
+        """
+
+        # need a build, otherwise project doesn't display at all
+        self._add_build_to_default_project()
+
+        # another project to test
+        self._add_non_default_project()
+
+        self.get(reverse('all-projects'))
+
+        # find the row for the default project
+        default_project_row = self._get_row_for_project(self.default_project.name)
+
+        # check the link on the name field
+        selector = 'span[data-project-field="name"] a'
+        element = default_project_row.find_element_by_css_selector(selector)
+        link_url = element.get_attribute('href').strip()
+        expected_url = reverse('projectbuilds', args=(self.default_project.id,))
+        msg = 'link on default project name should point to builds but was %s' % link_url
+        self.assertTrue(link_url.endswith(expected_url), msg)
+
+        # find the row for the other project
+        other_project_row = self._get_row_for_project(self.project.name)
+
+        # check the link for the other project
+        selector = 'span[data-project-field="name"] a'
+        element = other_project_row.find_element_by_css_selector(selector)
+        link_url = element.get_attribute('href').strip()
+        expected_url = reverse('project', args=(self.project.id,))
+        msg = 'link on project name should point to configuration but was %s' % link_url
+        self.assertTrue(link_url.endswith(expected_url), msg)
lib/toaster/toastergui/tests.py +0 -197

209 lines not on this page · raw message

Signature · 1 line
2.1.4
#4 lore raw

PATCH 5/5 toaster: tests Migrate landing page tests to Selenium

In reply to Michael Wood

From: Elliot Smith <[email protected]>

---
 lib/toaster/tests/browser/test_landing_page.py | 108 +++++++++++++++++++++++++
 lib/toaster/toastergui/tests.py                |  74 -----------------
 2 files changed, 108 insertions(+), 74 deletions(-)
 create mode 100644 lib/toaster/tests/browser/test_landing_page.py
lib/toaster/tests/browser/test_landing_page.py new file +108 -0
new file mode 100644
index 0000000..4d4cd66
@@ -0,0 +1,108 @@
+#! /usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# BitBake Toaster Implementation
+#
+# Copyright (C) 2013-2016 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+from django.core.urlresolvers import reverse
+from django.utils import timezone
+from tests.browser.selenium_helpers import SeleniumTestCase
+
+from orm.models import Project, Build
+
+class TestLandingPage(SeleniumTestCase):
+    """ Tests for redirects on the landing page """
+
+    PROJECT_NAME = 'test project'
+    LANDING_PAGE_TITLE = 'This is Toaster'
+    CLI_BUILDS_PROJECT_NAME = 'command line builds'
+
+    def setUp(self):
+        """ Add default project manually """
+        self.project = Project.objects.create_project(
+            self.CLI_BUILDS_PROJECT_NAME,
+            None
+        )
+        self.project.is_default = True
+        self.project.save()
+
+    def test_only_default_project(self):
+        """
+        No projects except default
+        => should see the landing page
+        """
+        self.get(reverse('landing'))
+        self.assertTrue(self.LANDING_PAGE_TITLE in self.get_page_source())
+
+    def test_default_project_has_build(self):
+        """
+        Default project has a build, no other projects
+        => should see the builds page
+        """
+        now = timezone.now()
+        build = Build.objects.create(project=self.project,
+                                     started_on=now,
+                                     completed_on=now)
+        build.save()
+
+        self.get(reverse('landing'))
+
+        elements = self.find_all('#allbuildstable')
+        self.assertEqual(len(elements), 1, 'should redirect to builds')
+        content = self.get_page_source()
+        self.assertFalse(self.PROJECT_NAME in content,
+                         'should not show builds for project %s' % self.PROJECT_NAME)
+        self.assertTrue(self.CLI_BUILDS_PROJECT_NAME in content,
+                        'should show builds for cli project')
+
+    def test_user_project_exists(self):
+        """
+        User has added a project (without builds)
+        => should see the projects page
+        """
+        user_project = Project.objects.create_project('foo', None)
+        user_project.save()
+
+        self.get(reverse('landing'))
+
+        elements = self.find_all('#projectstable')
+        self.assertEqual(len(elements), 1, 'should redirect to projects')
+
+    def test_user_project_has_build(self):
+        """
+        User has added a project (with builds), command line builds doesn't
+        => should see the builds page
+        """
+        user_project = Project.objects.create_project(self.PROJECT_NAME, None)
+        user_project.save()
+
+        now = timezone.now()
+        build = Build.objects.create(project=user_project,
+                                     started_on=now,
+                                     completed_on=now)
+        build.save()
+
+        self.get(reverse('landing'))
+
+        elements = self.find_all('#allbuildstable')
+        self.assertEqual(len(elements), 1, 'should redirect to builds')
+        content = self.get_page_source()
+        self.assertTrue(self.PROJECT_NAME in content,
+                        'should show builds for project %s' % self.PROJECT_NAME)
+        self.assertFalse(self.CLI_BUILDS_PROJECT_NAME in content,
+                         'should not show builds for cli project')
lib/toaster/toastergui/tests.py +0 -74

80 lines not on this page · raw message

Signature · 1 line
2.1.4