Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #! /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 | |
| 22 | from django.core.urlresolvers import reverse |
| 23 | from tests.browser.selenium_helpers import SeleniumTestCase |
| 24 | from selenium.webdriver.support.ui import Select |
| 25 | from selenium.common.exceptions import InvalidElementStateException |
| 26 | |
| 27 | from orm.models import Project, Release, BitbakeVersion |
| 28 | |
| 29 | |
| 30 | class TestNewProjectPage(SeleniumTestCase): |
| 31 | """ Test project data at /project/X/ is displayed correctly """ |
| 32 | |
| 33 | def setUp(self): |
| 34 | bitbake, c = BitbakeVersion.objects.get_or_create( |
| 35 | name="master", |
| 36 | giturl="git://master", |
| 37 | branch="master", |
| 38 | dirpath="master") |
| 39 | |
| 40 | release, c = Release.objects.get_or_create(name="msater", |
| 41 | description="master" |
| 42 | "release", |
| 43 | branch_name="master", |
| 44 | helptext="latest", |
| 45 | bitbake_version=bitbake) |
| 46 | |
| 47 | self.release, c = Release.objects.get_or_create( |
| 48 | name="msater2", |
| 49 | description="master2" |
| 50 | "release2", |
| 51 | branch_name="master2", |
| 52 | helptext="latest2", |
| 53 | bitbake_version=bitbake) |
| 54 | |
| 55 | def test_create_new_project(self): |
| 56 | """ Test creating a project """ |
| 57 | |
| 58 | project_name = "masterproject" |
| 59 | |
| 60 | url = reverse('newproject') |
| 61 | self.get(url) |
| 62 | |
| 63 | self.enter_text('#new-project-name', project_name) |
| 64 | |
| 65 | select = Select(self.find('#projectversion')) |
| 66 | select.select_by_value(str(self.release.pk)) |
| 67 | |
| 68 | self.click("#create-project-button") |
| 69 | |
| 70 | # We should get redirected to the new project's page with the |
| 71 | # notification at the top |
| 72 | element = self.wait_until_visible('#project-created-notification') |
| 73 | |
| 74 | self.assertTrue(project_name in element.text, |
| 75 | "New project name not in new project notification") |
| 76 | |
| 77 | self.assertTrue(Project.objects.filter(name=project_name).count(), |
| 78 | "New project not found in database") |
| 79 | |
| 80 | def test_new_duplicates_project_name(self): |
| 81 | """ |
| 82 | Should not be able to create a new project whose name is the same |
| 83 | as an existing project |
| 84 | """ |
| 85 | |
| 86 | project_name = "dupproject" |
| 87 | |
| 88 | Project.objects.create_project(name=project_name, |
| 89 | release=self.release) |
| 90 | |
| 91 | url = reverse('newproject') |
| 92 | self.get(url) |
| 93 | |
| 94 | self.enter_text('#new-project-name', project_name) |
| 95 | |
| 96 | select = Select(self.find('#projectversion')) |
| 97 | select.select_by_value(str(self.release.pk)) |
| 98 | |
| 99 | element = self.wait_until_visible('#hint-error-project-name') |
| 100 | |
| 101 | self.assertTrue(("Project names must be unique" in element.text), |
| 102 | "Did not find unique project name error message") |
| 103 | |
| 104 | # Try and click it anyway, if it submits we'll have a new project in |
| 105 | # the db and assert then |
| 106 | try: |
| 107 | self.click("#create-project-button") |
| 108 | except InvalidElementStateException: |
| 109 | pass |
| 110 | |
| 111 | self.assertTrue( |
| 112 | (Project.objects.filter(name=project_name).count() == 1), |
| 113 | "New project not found in database") |