Skip to contentSkip to conversation

Unique project names

PATCH In review Michael Wood 2 participants 8 messages May 9, 2016 – May 10, 2016

lore
Share & tools
lore
#0 lore raw

cover Unique project names

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
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 toaster: projectNameValidation API added

From: Sujith H <[email protected]>

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

[YOCTO #7005]

---
 .../lib/toaster/toastergui/static/js/libtoaster.js | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)
bitbake/lib/toaster/toastergui/static/js/libtoaster.js +62 -0
index 43930a2..0d1486b 100644
@@ -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,
   };
 })();
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/5 toaster: ui handles duplicate project name in new project page

In reply to Michael Wood

From: Sujith H <[email protected]>

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

[YOCTO #7005]

---
 bitbake/lib/toaster/toastergui/templates/newproject.html | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
bitbake/lib/toaster/toastergui/templates/newproject.html +10 -2
index e83b2be..8913057 100644
@@ -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') {
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/5 toaster: ui handles duplicate project name in project page

In reply to Michael Wood

From: Sujith H <[email protected]>

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]

---
 bitbake/lib/toaster/toastergui/static/js/projecttopbar.js   | 7 +++++++
 bitbake/lib/toaster/toastergui/templates/projecttopbar.html | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)
bitbake/lib/toaster/toastergui/static/js/projecttopbar.js +7 -0
index b09f974..f0cd18b 100644
@@ -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"));
+
 }
bitbake/lib/toaster/toastergui/templates/projecttopbar.html +2 -1
index 007de06..e878cab 100644
@@ -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>
 
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/5 toaster: models Add missing import sys

In reply to Michael Wood
---
 bitbake/lib/toaster/orm/models.py | 1 +
 1 file changed, 1 insertion(+)
bitbake/lib/toaster/orm/models.py +1 -0
index 6716ddf..2669606 100644
@@ -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
Signature · 1 line
2.7.4
#5 lore raw

PATCH 5/5 toaster: tests browser Add test for creating a project

In reply to Michael Wood

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

---
 .../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
bitbake/lib/toaster/tests/browser/test_new_project_page.py new file +109 -0
new file mode 100644
index 0000000..b9358ab
@@ -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")
Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH 5/5] toaster: tests browser Add test for creating a project

Looks good, but one typo (see below).

I'm happy for you to upstream it.

Elliot

Quoted 112 lines · Michael Wood

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

---
 .../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

bitbake/lib/toaster/tests/browser/test_new_project_page.py new file +74 -0
new file mode 100644
index 0000000..b9358ab
@@ -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")

bitbake/lib/toaster/tests/browser/test_new_project_page.py new file +17 -0
+
+        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)

bitbake/lib/toaster/tests/browser/test_new_project_page.py line 101

Quoted 10 lines
bitbake/lib/toaster/tests/browser/test_new_project_page.py new file +10 -0
+
+        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

Quoted 18 lines
bitbake/lib/toaster/tests/browser/test_new_project_page.py new file +2 -0
+
+        # Try and click it anyway, if it submits we'll have a new project

in

bitbake/lib/toaster/tests/browser/test_new_project_page.py new file +6 -1
+        # 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
[email protected]
https://lists.yoctoproject.org/listinfo/toaster

Signature · 3 lines
Elliot Smith
Software Engineer
Intel Open Source Technology Centre
#7 lore raw

Re: [PATCH 5/5] toaster: tests browser Add test for creating a project

Upstreamed and pushed to toaster-next with the typo corrected

Quoted 180 lines · Elliot

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 <[email protected] <mailto:[email protected]>> wrote:

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

<mailto:[email protected]>>
---
.../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
[email protected] <mailto:[email protected]>
https://lists.yoctoproject.org/listinfo/toaster

Signature · 14 lines
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.