All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Unique project names
@ 2016-05-09 15:27 Michael Wood
  2016-05-09 15:27 ` [PATCH 1/5] toaster: projectNameValidation API added Michael Wood
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Michael Wood @ 2016-05-09 15:27 UTC (permalink / raw)
  To: toaster

Patch series to add the unique project name validation.
All Sujith patches have been reviewed already, just my two that need a 
quick look over. Happy to do the upstreaming.

Michael Wood (2):
  toaster: models Add missing import sys
  toaster: tests browser Add test for creating a project

Sujith H (3):
  toaster: projectNameValidation API added
  toaster: ui handles duplicate project name in new project page
  toaster: ui handles duplicate project name in project page

 bitbake/lib/toaster/orm/models.py                  |   1 +
 .../toaster/tests/browser/test_new_project_page.py | 109 +++++++++++++++++++++
 .../lib/toaster/toastergui/static/js/libtoaster.js |  62 ++++++++++++
 .../toaster/toastergui/static/js/projecttopbar.js  |   7 ++
 .../toaster/toastergui/templates/newproject.html   |  12 ++-
 .../toastergui/templates/projecttopbar.html        |   3 +-
 6 files changed, 191 insertions(+), 3 deletions(-)
 create mode 100644 bitbake/lib/toaster/tests/browser/test_new_project_page.py

-- 
2.7.4



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] toaster: projectNameValidation API added
  2016-05-09 15:27 [PATCH 0/5] Unique project names Michael Wood
@ 2016-05-09 15:27 ` Michael Wood
  2016-05-09 15:27 ` [PATCH 2/5] toaster: ui handles duplicate project name in new project page Michael Wood
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Michael Wood @ 2016-05-09 15:27 UTC (permalink / raw)
  To: toaster

From: Sujith H <sujith.h@gmail.com>

The projectNameValidation API would help users
to validate if a project name exists or not. This
API is added to libtoaster.

[YOCTO #7005]

Signed-off-by: Sujith H <sujith.h@gmail.com>
---
 .../lib/toaster/toastergui/static/js/libtoaster.js | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
index 43930a2..0d1486b 100644
--- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
+++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
@@ -374,6 +374,67 @@ var libtoaster = (function (){
     });
   }
 
+  /* Validate project names. Use unique project names
+
+     All arguments accepted by this function are JQeury objects.
+
+     For example if the HTML element has "hint-error-project-name", then
+     it is passed to this function as $("#hint-error-project-name").
+
+     Arg1 - projectName : This is a string object. In the HTML, project name will be entered here.
+     Arg2 - hintEerror : This is a jquery object which will accept span which throws error for
+            duplicate project
+     Arg3 - ctrlGrpValidateProjectName : This object holds the div with class "control-group"
+     Arg4 - enableOrDisableBtn : This object will help the API to enable or disable the form.
+            For example in the new project the create project button will be hidden if the
+            duplicate project exist. Similarly in the projecttopbar the save button will be
+            disabled if the project name already exist.
+
+     Return - This function doesn't return anything. It sets/unsets the behavior of the elements.
+  */
+
+  function _makeProjectNameValidation(projectName, hintError,
+                ctrlGrpValidateProjectName, enableOrDisableBtn ) {
+
+     function checkProjectName(projectName){
+       $.ajax({
+            type: "GET",
+            url: libtoaster.ctx.projectsTypeAheadUrl,
+            data: { 'search' : projectName },
+            headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
+            success: function(data){
+              if (data.results.length > 0 &&
+                  data.results[0].name === projectName) {
+                // This project name exists hence show the error and disable
+                // the save button
+                ctrlGrpValidateProjectName.addClass('control-group error');
+                hintError.show();
+                enableOrDisableBtn.attr('disabled', 'disabled');
+              } else {
+                ctrlGrpValidateProjectName.removeClass('control-group error');
+                hintError.hide();
+                enableOrDisableBtn.removeAttr('disabled');
+              }
+            },
+            error: function (data) {
+              console.log(data);
+            },
+       });
+     }
+
+     /* The moment user types project name remove the error */
+     projectName.on("input", function() {
+        var projectName = $(this).val();
+        checkProjectName(projectName)
+     });
+
+     /* Validate new project name */
+     projectName.on("blur", function(){
+        var projectName = $(this).val();
+        checkProjectName(projectName)
+     });
+  }
+
 
   return {
     reload_params : reload_params,
@@ -390,6 +451,7 @@ var libtoaster = (function (){
     makeLayerAddRmAlertMsg : _makeLayerAddRmAlertMsg,
     showChangeNotification : _showChangeNotification,
     createCustomRecipe: _createCustomRecipe,
+    makeProjectNameValidation: _makeProjectNameValidation,
   };
 })();
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/5] toaster: ui handles duplicate project name in new project page
  2016-05-09 15:27 [PATCH 0/5] Unique project names Michael Wood
  2016-05-09 15:27 ` [PATCH 1/5] toaster: projectNameValidation API added Michael Wood
@ 2016-05-09 15:27 ` Michael Wood
  2016-05-09 15:27 ` [PATCH 3/5] toaster: ui handles duplicate project name in " Michael Wood
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Michael Wood @ 2016-05-09 15:27 UTC (permalink / raw)
  To: toaster

From: Sujith H <sujith.h@gmail.com>

When already existing project name is typed by user,
the ui pops up message regarding the existance of the
project name.

[YOCTO #7005]

Signed-off-by: Sujith H <sujith.h@gmail.com>
---
 bitbake/lib/toaster/toastergui/templates/newproject.html | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/bitbake/lib/toaster/toastergui/templates/newproject.html b/bitbake/lib/toaster/toastergui/templates/newproject.html
index e83b2be..8913057 100644
--- a/bitbake/lib/toaster/toastergui/templates/newproject.html
+++ b/bitbake/lib/toaster/toastergui/templates/newproject.html
@@ -19,9 +19,12 @@
         <div class="span6">
         <form method="POST">{% csrf_token %}
 
-            <fieldset>
+            <fieldset id="validate-project-name">
               <label>Project name <span class="muted">(required)</span></label>
-              <input type="text" class="input-xlarge" required id="new-project-name" name="projectname">
+              <div>
+                <input type="text" class="input-xlarge" required id="new-project-name" name="projectname">
+                <p class="help-block error" style="display: none;" id="hint-error-project-name">A project with this name exists. Project names must be unique.</p>
+              </div>
             </fieldset>
 <!--
             <fieldset>
@@ -113,6 +116,11 @@
                 $('#description-' + new_release).fadeIn();
             });
 
+            libtoaster.makeProjectNameValidation($("#new-project-name"),
+                 $("#hint-error-project-name"), $("#validate-project-name"),
+                 $(".btn-primary"));
+
+
 /*			// Hide the project release when you select an analysis project
 			function projectType() {
 				if ($("input[type='radio']:checked").val() == 'build') {
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/5] toaster: ui handles duplicate project name in project page
  2016-05-09 15:27 [PATCH 0/5] Unique project names Michael Wood
  2016-05-09 15:27 ` [PATCH 1/5] toaster: projectNameValidation API added Michael Wood
  2016-05-09 15:27 ` [PATCH 2/5] toaster: ui handles duplicate project name in new project page Michael Wood
@ 2016-05-09 15:27 ` Michael Wood
  2016-05-09 15:27 ` [PATCH 4/5] toaster: models Add missing import sys Michael Wood
  2016-05-09 15:27 ` [PATCH 5/5] toaster: tests browser Add test for creating a project Michael Wood
  4 siblings, 0 replies; 9+ messages in thread
From: Michael Wood @ 2016-05-09 15:27 UTC (permalink / raw)
  To: toaster

From: Sujith H <sujith.h@gmail.com>

When already existing project name is typed by user,
the ui pops up message regarding the existance of the
project name. When an existing project is typed the save
button will be disabled. Else user can proceed ahead by
modifying the project name.

[YOCTO #7005]

Signed-off-by: Sujith H <sujith.h@gmail.com>
---
 bitbake/lib/toaster/toastergui/static/js/projecttopbar.js   | 7 +++++++
 bitbake/lib/toaster/toastergui/templates/projecttopbar.html | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js
index b09f974..f0cd18b 100644
--- a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js
+++ b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js
@@ -25,6 +25,7 @@ function projectTopBarInit(ctx) {
     e.preventDefault();
     projectNameForm.hide();
     projectNameContainer.fadeIn();
+    $("#project-name-change-input").val(projectName.text());
   });
 
   $("#project-name-change-btn").click(function(){
@@ -87,4 +88,10 @@ function projectTopBarInit(ctx) {
         window.location.replace(libtoaster.ctx.projectBuildsUrl);
     }, null);
   });
+
+  /* Call makeProjectNameValidation function */
+  libtoaster.makeProjectNameValidation($("#project-name-change-input"),
+      $("#hint-error-project-name"), $("#validate-project-name"),
+      $("#project-name-change-btn"));
+
 }
diff --git a/bitbake/lib/toaster/toastergui/templates/projecttopbar.html b/bitbake/lib/toaster/toastergui/templates/projecttopbar.html
index 007de06..e878cab 100644
--- a/bitbake/lib/toaster/toastergui/templates/projecttopbar.html
+++ b/bitbake/lib/toaster/toastergui/templates/projecttopbar.html
@@ -33,11 +33,12 @@
     {% endif %}
   </h1>
   <form id="project-name-change-form" style="margin-bottom: 0px; display: none;">
-    <div class="input-append">
+    <div class="input-append" id="validate-project-name">
       <input class="huge input-xxlarge" type="text" id="project-name-change-input" autocomplete="off" value="{{project.name}}">
         <button id="project-name-change-btn" class="btn btn-large" type="button">Save</button>
         <a href="#" id="project-name-change-cancel" class="btn btn-large btn-link">Cancel</a>
     </div>
+    <p class="help-block error" style="display: none;margin-top: 10px;" id="hint-error-project-name">A project with this name exists. Project names must be unique.</p>
   </form>
 </div>
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/5] toaster: models Add missing import sys
  2016-05-09 15:27 [PATCH 0/5] Unique project names Michael Wood
                   ` (2 preceding siblings ...)
  2016-05-09 15:27 ` [PATCH 3/5] toaster: ui handles duplicate project name in " Michael Wood
@ 2016-05-09 15:27 ` Michael Wood
  2016-05-09 15:27 ` [PATCH 5/5] toaster: tests browser Add test for creating a project Michael Wood
  4 siblings, 0 replies; 9+ messages in thread
From: Michael Wood @ 2016-05-09 15:27 UTC (permalink / raw)
  To: toaster

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 bitbake/lib/toaster/orm/models.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index 6716ddf..2669606 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -32,6 +32,7 @@ from django.core import validators
 from django.conf import settings
 import django.db.models.signals
 
+import sys
 import os.path
 import re
 import itertools
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/5] toaster: tests browser Add test for creating a project
  2016-05-09 15:27 [PATCH 0/5] Unique project names Michael Wood
                   ` (3 preceding siblings ...)
  2016-05-09 15:27 ` [PATCH 4/5] toaster: models Add missing import sys Michael Wood
@ 2016-05-09 15:27 ` Michael Wood
  2016-05-09 16:22   ` Smith, Elliot
  4 siblings, 1 reply; 9+ messages in thread
From: Michael Wood @ 2016-05-09 15:27 UTC (permalink / raw)
  To: toaster

Add browser tests for creating a project and test validation of
duplicate project names.

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 .../toaster/tests/browser/test_new_project_page.py | 109 +++++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100644 bitbake/lib/toaster/tests/browser/test_new_project_page.py

diff --git a/bitbake/lib/toaster/tests/browser/test_new_project_page.py b/bitbake/lib/toaster/tests/browser/test_new_project_page.py
new file mode 100644
index 0000000..b9358ab
--- /dev/null
+++ b/bitbake/lib/toaster/tests/browser/test_new_project_page.py
@@ -0,0 +1,109 @@
+#! /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 tests.browser.selenium_helpers import SeleniumTestCase
+from selenium.webdriver.support.ui import Select
+
+from orm.models import Project, Release, BitbakeVersion
+
+
+class TestNewProjectPage(SeleniumTestCase):
+    """ Test project data at /project/X/ is displayed correctly """
+
+    def setUp(self):
+        bitbake, c = BitbakeVersion.objects.get_or_create(
+            name="master",
+            giturl="git://master",
+            branch="master",
+            dirpath="master")
+
+        release, c = Release.objects.get_or_create(name="msater",
+                                                   description="master"
+                                                   "release",
+                                                   branch_name="master",
+                                                   helptext="latest",
+                                                   bitbake_version=bitbake)
+
+        self.release, c = Release.objects.get_or_create(
+            name="msater2",
+            description="master2"
+            "release2",
+            branch_name="master2",
+            helptext="latest2",
+            bitbake_version=bitbake)
+
+    def test_create_new_project(self):
+        """ Test creating a project """
+
+        project_name = "masterproject"
+
+        url = reverse('newproject')
+        self.get(url)
+
+        self.enter_text('#new-project-name', project_name)
+
+        select = Select(self.find('#projectversion'))
+        select.select_by_value(str(self.release.pk))
+
+        self.click("#create-project-button")
+
+        # We should get redirected to the new project's page with the
+        # notification at the top
+        element = self.wait_until_visible('#project-created-notification')
+
+        self.assertTrue(project_name in element.text,
+                        "New project name not in new project notification")
+
+        self.assertTrue(Project.objects.filter(name=project_name).count(),
+                        "New project not found in database")
+
+    def test_new_duplicates_project_name(self):
+        """
+        Should not be able to create a new project whose name is the same
+        as an existing project
+       """
+
+        project_name = "dupproject"
+
+        Project.objects.create_project(name=project_name,
+                                       release=self.release)
+
+        url = reverse('newproject')
+        self.get(url)
+
+        self.enter_text('#new-project-name', project_name)
+
+        select = Select(self.find('#projectversion'))
+        select.select_by_value(str(self.release.pk))
+
+        element = self.wait_until_visible('#hint-error-project-name')
+
+        self.assertTrue(("Project names must be unique" in element.text),
+                        "Did not find unqiue project name error message")
+
+        # Try and click it anyway, if it submits we'll have a new project in
+        # the db and assert then
+        self.click("#create-project-button")
+
+        self.assertTrue(
+            (Project.objects.filter(name=project_name).count() == 1),
+            "New project not found in database")
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/5] toaster: tests browser Add test for creating a project
  2016-05-09 15:27 ` [PATCH 5/5] toaster: tests browser Add test for creating a project Michael Wood
@ 2016-05-09 16:22   ` Smith, Elliot
  2016-05-10 12:10     ` Michael Wood
  0 siblings, 1 reply; 9+ messages in thread
From: Smith, Elliot @ 2016-05-09 16:22 UTC (permalink / raw)
  To: Michael Wood; +Cc: toaster

[-- Attachment #1: Type: text/plain, Size: 5477 bytes --]

Looks good, but one typo (see below).

I'm happy for you to upstream it.

Elliot

On 9 May 2016 at 16:27, Michael Wood <michael.g.wood@intel.com> wrote:

> Add browser tests for creating a project and test validation of
> duplicate project names.
>
> Signed-off-by: Michael Wood <michael.g.wood@intel.com>
> ---
>  .../toaster/tests/browser/test_new_project_page.py | 109
> +++++++++++++++++++++
>  1 file changed, 109 insertions(+)
>  create mode 100644
> bitbake/lib/toaster/tests/browser/test_new_project_page.py
>
> diff --git a/bitbake/lib/toaster/tests/browser/test_new_project_page.py
> b/bitbake/lib/toaster/tests/browser/test_new_project_page.py
> new file mode 100644
> index 0000000..b9358ab
> --- /dev/null
> +++ b/bitbake/lib/toaster/tests/browser/test_new_project_page.py
> @@ -0,0 +1,109 @@
> +#! /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 tests.browser.selenium_helpers import SeleniumTestCase
> +from selenium.webdriver.support.ui import Select
> +
> +from orm.models import Project, Release, BitbakeVersion
> +
> +
> +class TestNewProjectPage(SeleniumTestCase):
> +    """ Test project data at /project/X/ is displayed correctly """
> +
> +    def setUp(self):
> +        bitbake, c = BitbakeVersion.objects.get_or_create(
> +            name="master",
> +            giturl="git://master",
> +            branch="master",
> +            dirpath="master")
> +
> +        release, c = Release.objects.get_or_create(name="msater",
> +                                                   description="master"
> +                                                   "release",
> +                                                   branch_name="master",
> +                                                   helptext="latest",
> +
>  bitbake_version=bitbake)
> +
> +        self.release, c = Release.objects.get_or_create(
> +            name="msater2",
> +            description="master2"
> +            "release2",
> +            branch_name="master2",
> +            helptext="latest2",
> +            bitbake_version=bitbake)
> +
> +    def test_create_new_project(self):
> +        """ Test creating a project """
> +
> +        project_name = "masterproject"
> +
> +        url = reverse('newproject')
> +        self.get(url)
> +
> +        self.enter_text('#new-project-name', project_name)
> +
> +        select = Select(self.find('#projectversion'))
> +        select.select_by_value(str(self.release.pk))
> +
> +        self.click("#create-project-button")
> +
> +        # We should get redirected to the new project's page with the
> +        # notification at the top
> +        element = self.wait_until_visible('#project-created-notification')
> +
> +        self.assertTrue(project_name in element.text,
> +                        "New project name not in new project
> notification")
> +
> +        self.assertTrue(Project.objects.filter(name=project_name).count(),
> +                        "New project not found in database")
> +
> +    def test_new_duplicates_project_name(self):
> +        """
> +        Should not be able to create a new project whose name is the same
> +        as an existing project
> +       """
> +
> +        project_name = "dupproject"
> +
> +        Project.objects.create_project(name=project_name,
> +                                       release=self.release)
> +
> +        url = reverse('newproject')
> +        self.get(url)
> +
> +        self.enter_text('#new-project-name', project_name)
> +
> +        select = Select(self.find('#projectversion'))
> +        select.select_by_value(str(self.release.pk))
> +
> +        element = self.wait_until_visible('#hint-error-project-name')
> +
> +        self.assertTrue(("Project names must be unique" in element.text),
> +                        "Did not find unqiue project name error message")
>

TYPO: unqiue -> unique


> +
> +        # Try and click it anyway, if it submits we'll have a new project
> in
> +        # the db and assert then
> +        self.click("#create-project-button")
> +
> +        self.assertTrue(
> +            (Project.objects.filter(name=project_name).count() == 1),
> +            "New project not found in database")
> --
> 2.7.4
>
> --
> _______________________________________________
> toaster mailing list
> toaster@yoctoproject.org
> https://lists.yoctoproject.org/listinfo/toaster
>



-- 
Elliot Smith
Software Engineer
Intel Open Source Technology Centre

[-- Attachment #2: Type: text/html, Size: 7547 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/5] toaster: tests browser Add test for creating a project
  2016-05-09 16:22   ` Smith, Elliot
@ 2016-05-10 12:10     ` Michael Wood
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Wood @ 2016-05-10 12:10 UTC (permalink / raw)
  To: Smith, Elliot; +Cc: toaster

Upstreamed and pushed to toaster-next with the typo corrected

On 09/05/16 17:22, Smith, Elliot wrote:
> Looks good, but one typo (see below).
>
> I'm happy for you to upstream it.
>
> Elliot
>
> On 9 May 2016 at 16:27, Michael Wood <michael.g.wood@intel.com 
> <mailto:michael.g.wood@intel.com>> wrote:
>
>     Add browser tests for creating a project and test validation of
>     duplicate project names.
>
>     Signed-off-by: Michael Wood <michael.g.wood@intel.com
>     <mailto:michael.g.wood@intel.com>>
>     ---
>      .../toaster/tests/browser/test_new_project_page.py | 109
>     +++++++++++++++++++++
>      1 file changed, 109 insertions(+)
>      create mode 100644
>     bitbake/lib/toaster/tests/browser/test_new_project_page.py
>
>     diff --git
>     a/bitbake/lib/toaster/tests/browser/test_new_project_page.py
>     b/bitbake/lib/toaster/tests/browser/test_new_project_page.py
>     new file mode 100644
>     index 0000000..b9358ab
>     --- /dev/null
>     +++ b/bitbake/lib/toaster/tests/browser/test_new_project_page.py
>     @@ -0,0 +1,109 @@
>     +#! /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 tests.browser.selenium_helpers import SeleniumTestCase
>     +from selenium.webdriver.support.ui import Select
>     +
>     +from orm.models import Project, Release, BitbakeVersion
>     +
>     +
>     +class TestNewProjectPage(SeleniumTestCase):
>     +    """ Test project data at /project/X/ is displayed correctly """
>     +
>     +    def setUp(self):
>     +        bitbake, c = BitbakeVersion.objects.get_or_create(
>     +            name="master",
>     +            giturl="git://master",
>     +            branch="master",
>     +            dirpath="master")
>     +
>     +        release, c = Release.objects.get_or_create(name="msater",
>     +  description="master"
>     +  "release",
>     +  branch_name="master",
>     +  helptext="latest",
>     +  bitbake_version=bitbake)
>     +
>     +        self.release, c = Release.objects.get_or_create(
>     +            name="msater2",
>     +            description="master2"
>     +            "release2",
>     +            branch_name="master2",
>     +            helptext="latest2",
>     +            bitbake_version=bitbake)
>     +
>     +    def test_create_new_project(self):
>     +        """ Test creating a project """
>     +
>     +        project_name = "masterproject"
>     +
>     +        url = reverse('newproject')
>     +        self.get(url)
>     +
>     +        self.enter_text('#new-project-name', project_name)
>     +
>     +        select = Select(self.find('#projectversion'))
>     +        select.select_by_value(str(self.release.pk
>     <http://self.release.pk>))
>     +
>     +        self.click("#create-project-button")
>     +
>     +        # We should get redirected to the new project's page with the
>     +        # notification at the top
>     +        element =
>     self.wait_until_visible('#project-created-notification')
>     +
>     +        self.assertTrue(project_name in element.text,
>     +                        "New project name not in new project
>     notification")
>     +
>     + self.assertTrue(Project.objects.filter(name=project_name).count(),
>     +                        "New project not found in database")
>     +
>     +    def test_new_duplicates_project_name(self):
>     +        """
>     +        Should not be able to create a new project whose name is
>     the same
>     +        as an existing project
>     +       """
>     +
>     +        project_name = "dupproject"
>     +
>     + Project.objects.create_project(name=project_name,
>     +  release=self.release)
>     +
>     +        url = reverse('newproject')
>     +        self.get(url)
>     +
>     +        self.enter_text('#new-project-name', project_name)
>     +
>     +        select = Select(self.find('#projectversion'))
>     +        select.select_by_value(str(self.release.pk
>     <http://self.release.pk>))
>     +
>     +        element = self.wait_until_visible('#hint-error-project-name')
>     +
>     +        self.assertTrue(("Project names must be unique" in
>     element.text),
>     +                        "Did not find unqiue project name error
>     message")
>
>
> TYPO: unqiue -> unique
>
>     +
>     +        # Try and click it anyway, if it submits we'll have a new
>     project in
>     +        # the db and assert then
>     +        self.click("#create-project-button")
>     +
>     +        self.assertTrue(
>     + (Project.objects.filter(name=project_name).count() == 1),
>     +            "New project not found in database")
>     --
>     2.7.4
>
>     --
>     _______________________________________________
>     toaster mailing list
>     toaster@yoctoproject.org <mailto:toaster@yoctoproject.org>
>     https://lists.yoctoproject.org/listinfo/toaster
>
>
>
>
> -- 
> Elliot Smith
> Software Engineer
> Intel Open Source Technology Centre
>
> ---------------------------------------------------------------------
> Intel Corporation (UK) Limited
> Registered No. 1134945 (England)
> Registered Office: Pipers Way, Swindon SN3 1RJ
> VAT No: 860 2173 47
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/5] toaster: tests browser Add test for creating a project
  2016-05-09 23:01 [PATCH 0/5] Validate unique project names Michael Wood
@ 2016-05-09 23:01 ` Michael Wood
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Wood @ 2016-05-09 23:01 UTC (permalink / raw)
  To: bitbake-devel

Add browser tests for creating a project and test validation of
duplicate project names.

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/tests/browser/test_new_project_page.py | 109 +++++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100644 lib/toaster/tests/browser/test_new_project_page.py

diff --git a/lib/toaster/tests/browser/test_new_project_page.py b/lib/toaster/tests/browser/test_new_project_page.py
new file mode 100644
index 0000000..1b038ac
--- /dev/null
+++ b/lib/toaster/tests/browser/test_new_project_page.py
@@ -0,0 +1,109 @@
+#! /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 tests.browser.selenium_helpers import SeleniumTestCase
+from selenium.webdriver.support.ui import Select
+
+from orm.models import Project, Release, BitbakeVersion
+
+
+class TestNewProjectPage(SeleniumTestCase):
+    """ Test project data at /project/X/ is displayed correctly """
+
+    def setUp(self):
+        bitbake, c = BitbakeVersion.objects.get_or_create(
+            name="master",
+            giturl="git://master",
+            branch="master",
+            dirpath="master")
+
+        release, c = Release.objects.get_or_create(name="msater",
+                                                   description="master"
+                                                   "release",
+                                                   branch_name="master",
+                                                   helptext="latest",
+                                                   bitbake_version=bitbake)
+
+        self.release, c = Release.objects.get_or_create(
+            name="msater2",
+            description="master2"
+            "release2",
+            branch_name="master2",
+            helptext="latest2",
+            bitbake_version=bitbake)
+
+    def test_create_new_project(self):
+        """ Test creating a project """
+
+        project_name = "masterproject"
+
+        url = reverse('newproject')
+        self.get(url)
+
+        self.enter_text('#new-project-name', project_name)
+
+        select = Select(self.find('#projectversion'))
+        select.select_by_value(str(self.release.pk))
+
+        self.click("#create-project-button")
+
+        # We should get redirected to the new project's page with the
+        # notification at the top
+        element = self.wait_until_visible('#project-created-notification')
+
+        self.assertTrue(project_name in element.text,
+                        "New project name not in new project notification")
+
+        self.assertTrue(Project.objects.filter(name=project_name).count(),
+                        "New project not found in database")
+
+    def test_new_duplicates_project_name(self):
+        """
+        Should not be able to create a new project whose name is the same
+        as an existing project
+       """
+
+        project_name = "dupproject"
+
+        Project.objects.create_project(name=project_name,
+                                       release=self.release)
+
+        url = reverse('newproject')
+        self.get(url)
+
+        self.enter_text('#new-project-name', project_name)
+
+        select = Select(self.find('#projectversion'))
+        select.select_by_value(str(self.release.pk))
+
+        element = self.wait_until_visible('#hint-error-project-name')
+
+        self.assertTrue(("Project names must be unique" in element.text),
+                        "Did not find unique project name error message")
+
+        # Try and click it anyway, if it submits we'll have a new project in
+        # the db and assert then
+        self.click("#create-project-button")
+
+        self.assertTrue(
+            (Project.objects.filter(name=project_name).count() == 1),
+            "New project not found in database")
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-05-10 12:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-09 15:27 [PATCH 0/5] Unique project names Michael Wood
2016-05-09 15:27 ` [PATCH 1/5] toaster: projectNameValidation API added Michael Wood
2016-05-09 15:27 ` [PATCH 2/5] toaster: ui handles duplicate project name in new project page Michael Wood
2016-05-09 15:27 ` [PATCH 3/5] toaster: ui handles duplicate project name in " Michael Wood
2016-05-09 15:27 ` [PATCH 4/5] toaster: models Add missing import sys Michael Wood
2016-05-09 15:27 ` [PATCH 5/5] toaster: tests browser Add test for creating a project Michael Wood
2016-05-09 16:22   ` Smith, Elliot
2016-05-10 12:10     ` Michael Wood
2016-05-09 23:01 [PATCH 0/5] Validate unique project names Michael Wood
2016-05-09 23:01 ` [PATCH 5/5] toaster: tests browser Add test for creating a project Michael Wood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.