Openembedded Bitbake Development
 help / color / mirror / Atom feed
* [PATCH 00/11] Fixes and clean ups for toastergui unit tests
@ 2015-08-10 17:26 Michael Wood
  2015-08-10 17:27 ` [PATCH 01/11] toaster: fix test_get_json_call_returns_json test Michael Wood
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:26 UTC (permalink / raw)
  To: bitbake-devel

This patchset contains fixes and code cleanups for Toaster GUI tests.
Reviewed by Michael Wood.

The following changes since commit c75cefe8a382a63f625123c156137782db118f64:

  libpam: Fix patch broken during upgrade (2015-08-09 15:15:33 -0700)

are available in the git repository at:

  git://git.yoctoproject.org/poky-contrib michaelw/toaster/submit/ed/toaster/fix-toastergui-tests
  http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=michaelw/toaster/submit/ed/toaster/fix-toastergui-tests

Ed Bartosh (11):
  toaster: fix test_get_json_call_returns_json test
  toaster: wrap long lines
  toaster: get rid of AllProjectsViewTestCase
  toaster: put all test cases into one class
  toaster: get rid of class attributes
  toaster: remove unused import
  toaster: add header and docstings
  toaster: don't catch json.load exceptions
  toaster: fix test_get_json_call_returns_json again
  toaster: fix pylint warning 'no space allowed'
  toaster: reduced amount of instance attributes

 lib/toaster/toastergui/tests.py | 133 +++++++++++++++++++++++-----------------
 1 file changed, 78 insertions(+), 55 deletions(-)

-- 
2.1.4



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

* [PATCH 01/11] toaster: fix test_get_json_call_returns_json test
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 02/11] toaster: wrap long lines Michael Wood
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

This test case used wrong field name.
Fixed by renaming field 'lists' -> 'rows'.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 8a59af4..39586e0 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -34,13 +34,13 @@ class AllProjectsViewTestCase(ProvisionedProjectTestCase):
 
         self.assertTrue("error" in data)
         self.assertEqual(data["error"], "ok")
-        self.assertTrue("list" in data)
+        self.assertTrue("rows" in data)
 
-        self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in map(lambda x: x["name"], data["list"]))
-        self.assertTrue("id" in data["list"][0])
-        self.assertTrue("projectLayersUrl" in data["list"][0])
-        self.assertTrue("projectPageUrl" in data["list"][0])
-        self.assertTrue("projectBuildsUrl" in data["list"][0])
+        self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in map(lambda x: x["name"], data["rows"]))
+        self.assertTrue("id" in data["rows"][0])
+        self.assertTrue("projectLayersUrl" in data["rows"][0])
+        self.assertTrue("projectPageUrl" in data["rows"][0])
+        self.assertTrue("projectBuildsUrl" in data["rows"][0])
 
 class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase):
     LAYER_NAME = "base-layer"
-- 
2.1.4



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

* [PATCH 02/11] toaster: wrap long lines
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
  2015-08-10 17:27 ` [PATCH 01/11] toaster: fix test_get_json_call_returns_json test Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 03/11] toaster: get rid of AllProjectsViewTestCase Michael Wood
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Fixed pylint warning Line too long (line-too-long).

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 39586e0..a9edd54 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -1,16 +1,22 @@
 from django.test import TestCase
 from django.core.urlresolvers import reverse
 from orm.models import Project, Release, BitbakeVersion, Build
-from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Layer_Version, Recipe, Machine, ProjectLayer
+from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer
+from orm.models import Layer_Version, Recipe, Machine, ProjectLayer
 import json
 
+PROJECT_NAME = "test project"
+
 class ProvisionedProjectTestCase(TestCase):
-    TEST_PROJECT_NAME = "test project"
 
     def setUp(self):
-        self.bbv, created = BitbakeVersion.objects.get_or_create(name="test bbv", giturl="/tmp/", branch="master", dirpath="")
-        self.release, created = Release.objects.get_or_create(name="test release", bitbake_version = self.bbv)
-        self.project = Project.objects.create_project(name=AllProjectsViewTestCase.TEST_PROJECT_NAME, release=self.release)
+        self.bbv = BitbakeVersion.objects.create(\
+                       name="test bbv", giturl="/tmp/",
+                       branch="master", dirpath="")
+        self.release = Release.objects.create(\
+                           name="test release", bitbake_version=self.bbv)
+        self.project = Project.objects.create_project(name=PROJECT_NAME,
+                                                      release=self.release)
 
 
 class AllProjectsViewTestCase(ProvisionedProjectTestCase):
@@ -20,10 +26,11 @@ class AllProjectsViewTestCase(ProvisionedProjectTestCase):
         self.assertEqual(response.status_code, 200)
         self.assertTrue(response['Content-Type'].startswith('text/html'))
         self.assertTemplateUsed(response, "projects.html")
-        self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in response.content)
+        self.assertTrue(PROJECT_NAME in response.content)
 
     def test_get_json_call_returns_json(self):
-        response = self.client.get(reverse('all-projects'), {"format": "json"}, follow=True)
+        url = reverse('all-projects')
+        response = self.client.get(url, {"format": "json"}, follow=True)
         self.assertEqual(response.status_code, 200)
         self.assertTrue(response['Content-Type'].startswith('application/json'))
 
@@ -36,7 +43,7 @@ class AllProjectsViewTestCase(ProvisionedProjectTestCase):
         self.assertEqual(data["error"], "ok")
         self.assertTrue("rows" in data)
 
-        self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in map(lambda x: x["name"], data["rows"]))
+        self.assertTrue(PROJECT_NAME in [x["name"] for x in data["rows"]])
         self.assertTrue("id" in data["rows"][0])
         self.assertTrue("projectLayersUrl" in data["rows"][0])
         self.assertTrue("projectPageUrl" in data["rows"][0])
@@ -49,10 +56,17 @@ class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase):
 
     def setUp(self):
         super(ProvisionedLayersProjectTestCase, self).setUp()
-        self.layersource, created = LayerSource.objects.get_or_create(sourcetype = LayerSource.TYPE_IMPORTED)
-        self.releaselayersourcepriority, created = ReleaseLayerSourcePriority.objects.get_or_create(release = self.release, layer_source = self.layersource)
-        self.layer, created = Layer.objects.get_or_create(name=XHRDataTypeAheadTestCase.LAYER_NAME, layer_source=self.layersource, vcs_url="/tmp/")
-        self.lv, created = Layer_Version.objects.get_or_create(layer = self.layer, project = self.project, layer_source=self.layersource, commit="master")
+        self.layersrc = LayerSource.objects.create(\
+                               sourcetype=LayerSource.TYPE_IMPORTED)
+        self.priority = ReleaseLayerSourcePriority.objects.create(\
+                               release=self.release,
+                               layer_source=self.layersrc)
+        self.layer = Layer.objects.create(\
+                         name=XHRDataTypeAheadTestCase.LAYER_NAME,
+                         layer_source=self.layersrc, vcs_url="/tmp/")
+        self.lver = Layer_Version.objects.create(\
+                        layer=self.layer, project=self.project,
+                        layer_source=self.layersrc, commit="master")
 
         self.recipe, created = Recipe.objects.get_or_create(layer_source=self.layersource, name=ProvisionedLayersProjectTestCase.RECIPE_NAME, version="1.2", summary="one recipe", description="recipe", layer_version=self.lv)
 
@@ -66,7 +80,7 @@ class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):
 
     def setUp(self):
         super(XHRDataTypeAheadTestCase, self).setUp()
-        self.assertTrue(self.lv in self.project.compatible_layerversions())
+        self.assertTrue(self.lver in self.project.compatible_layerversions())
 
     def test_typeaheads(self):
         layers_url = reverse('xhr_layerstypeahead', args=(self.project.id,))
-- 
2.1.4



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

* [PATCH 03/11] toaster: get rid of AllProjectsViewTestCase
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
  2015-08-10 17:27 ` [PATCH 01/11] toaster: fix test_get_json_call_returns_json test Michael Wood
  2015-08-10 17:27 ` [PATCH 02/11] toaster: wrap long lines Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 04/11] toaster: put all test cases into one class Michael Wood
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Removed AllProjectsViewTestCase class as it had one method 'setUp'
and used as a parent for another class AllProjectsViewTestCase.

Moved setUp method to AllProjectsViewTestCase.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index a9edd54..6f3930d 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -7,7 +7,7 @@ import json
 
 PROJECT_NAME = "test project"
 
-class ProvisionedProjectTestCase(TestCase):
+class AllProjectsViewTestCase(TestCase):
 
     def setUp(self):
         self.bbv = BitbakeVersion.objects.create(\
@@ -18,9 +18,6 @@ class ProvisionedProjectTestCase(TestCase):
         self.project = Project.objects.create_project(name=PROJECT_NAME,
                                                       release=self.release)
 
-
-class AllProjectsViewTestCase(ProvisionedProjectTestCase):
-
     def test_get_base_call_returns_html(self):
         response = self.client.get(reverse('all-projects'), follow=True)
         self.assertEqual(response.status_code, 200)
-- 
2.1.4



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

* [PATCH 04/11] toaster: put all test cases into one class
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (2 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 03/11] toaster: get rid of AllProjectsViewTestCase Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 05/11] toaster: get rid of class attributes Michael Wood
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Moved all functionality (one setup method and one test case) from
ProvisionedLayersProjectTestCase and XHRDataTypeAheadTestCase to
AllProjectsViewTestCase.

Renamed AllProjectsViewTestCase -> ViewTests.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 63 +++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 34 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 6f3930d..986e6a5 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -7,7 +7,10 @@ import json
 
 PROJECT_NAME = "test project"
 
-class AllProjectsViewTestCase(TestCase):
+class ViewTests(TestCase):
+    """Tests to verify view APIs."""
+    LAYER_NAME = "base-layer"
+    RECIPE_NAME = "base-recipe"
 
     def setUp(self):
         self.bbv = BitbakeVersion.objects.create(\
@@ -17,6 +20,31 @@ class AllProjectsViewTestCase(TestCase):
                            name="test release", bitbake_version=self.bbv)
         self.project = Project.objects.create_project(name=PROJECT_NAME,
                                                       release=self.release)
+        self.layersrc = LayerSource.objects.create(\
+                               sourcetype=LayerSource.TYPE_IMPORTED)
+        self.priority = ReleaseLayerSourcePriority.objects.create(\
+                               release=self.release,
+                               layer_source=self.layersrc)
+        self.layer = Layer.objects.create(\
+                         name=self.LAYER_NAME,
+                         layer_source=self.layersrc, vcs_url="/tmp/")
+        self.lver = Layer_Version.objects.create(\
+                        layer=self.layer, project=self.project,
+                        layer_source=self.layersrc, commit="master")
+
+        self.recipe = Recipe.objects.create(\
+                          layer_source=self.layersrc, name=self.RECIPE_NAME,
+                          version="1.2", summary="one recipe",
+                          description="recipe", layer_version=self.lver)
+
+        self.machine = Machine.objects.create(\
+                          layer_version=self.lver, name="wisk",
+                          description="wisking machine")
+
+        ProjectLayer.objects.create(project=self.project,
+                                    layercommit=self.lver)
+
+        self.assertTrue(self.lver in self.project.compatible_layerversions())
 
     def test_get_base_call_returns_html(self):
         response = self.client.get(reverse('all-projects'), follow=True)
@@ -46,39 +74,6 @@ class AllProjectsViewTestCase(TestCase):
         self.assertTrue("projectPageUrl" in data["rows"][0])
         self.assertTrue("projectBuildsUrl" in data["rows"][0])
 
-class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase):
-    LAYER_NAME = "base-layer"
-    RECIPE_NAME = "base-recipe"
-
-
-    def setUp(self):
-        super(ProvisionedLayersProjectTestCase, self).setUp()
-        self.layersrc = LayerSource.objects.create(\
-                               sourcetype=LayerSource.TYPE_IMPORTED)
-        self.priority = ReleaseLayerSourcePriority.objects.create(\
-                               release=self.release,
-                               layer_source=self.layersrc)
-        self.layer = Layer.objects.create(\
-                         name=XHRDataTypeAheadTestCase.LAYER_NAME,
-                         layer_source=self.layersrc, vcs_url="/tmp/")
-        self.lver = Layer_Version.objects.create(\
-                        layer=self.layer, project=self.project,
-                        layer_source=self.layersrc, commit="master")
-
-        self.recipe, created = Recipe.objects.get_or_create(layer_source=self.layersource, name=ProvisionedLayersProjectTestCase.RECIPE_NAME, version="1.2", summary="one recipe", description="recipe", layer_version=self.lv)
-
-        self.machine, created = Machine.objects.get_or_create(layer_version=self.lv, name="wisk", description="wisking machine")
-
-        ProjectLayer.objects.get_or_create(project = self.project,
-                                           layercommit = self.lv)
-
-
-class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):
-
-    def setUp(self):
-        super(XHRDataTypeAheadTestCase, self).setUp()
-        self.assertTrue(self.lver in self.project.compatible_layerversions())
-
     def test_typeaheads(self):
         layers_url = reverse('xhr_layerstypeahead', args=(self.project.id,))
         prj_url = reverse('xhr_projectstypeahead')
-- 
2.1.4



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

* [PATCH 05/11] toaster: get rid of class attributes
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (3 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 04/11] toaster: put all test cases into one class Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 06/11] toaster: remove unused import Michael Wood
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

LAYER_NAME and RECIPE_NAME attributes don't make sense as
they're used only once.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 986e6a5..9755a88 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -9,8 +9,6 @@ PROJECT_NAME = "test project"
 
 class ViewTests(TestCase):
     """Tests to verify view APIs."""
-    LAYER_NAME = "base-layer"
-    RECIPE_NAME = "base-recipe"
 
     def setUp(self):
         self.bbv = BitbakeVersion.objects.create(\
@@ -26,14 +24,14 @@ class ViewTests(TestCase):
                                release=self.release,
                                layer_source=self.layersrc)
         self.layer = Layer.objects.create(\
-                         name=self.LAYER_NAME,
+                         name="base-layer",
                          layer_source=self.layersrc, vcs_url="/tmp/")
         self.lver = Layer_Version.objects.create(\
                         layer=self.layer, project=self.project,
                         layer_source=self.layersrc, commit="master")
 
         self.recipe = Recipe.objects.create(\
-                          layer_source=self.layersrc, name=self.RECIPE_NAME,
+                          layer_source=self.layersrc, name="base-recipe",
                           version="1.2", summary="one recipe",
                           description="recipe", layer_version=self.lver)
 
-- 
2.1.4



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

* [PATCH 06/11] toaster: remove unused import
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (4 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 05/11] toaster: get rid of class attributes Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 07/11] toaster: add header and docstings Michael Wood
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Fixed pylint warning:
    Unused Build imported from orm.models (unused-import)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 9755a88..624ab7c 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -1,6 +1,6 @@
 from django.test import TestCase
 from django.core.urlresolvers import reverse
-from orm.models import Project, Release, BitbakeVersion, Build
+from orm.models import Project, Release, BitbakeVersion
 from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer
 from orm.models import Layer_Version, Recipe, Machine, ProjectLayer
 import json
-- 
2.1.4



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

* [PATCH 07/11] toaster: add header and docstings
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (5 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 06/11] toaster: remove unused import Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 08/11] toaster: don't catch json.load exceptions Michael Wood
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Added header and docstrings to toastergui tests module.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 624ab7c..1ed83dc 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -1,3 +1,26 @@
+#! /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-2015 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.
+
+"""Test cases for Toaster GUI and ReST."""
+
 from django.test import TestCase
 from django.core.urlresolvers import reverse
 from orm.models import Project, Release, BitbakeVersion
@@ -45,6 +68,7 @@ class ViewTests(TestCase):
         self.assertTrue(self.lver in self.project.compatible_layerversions())
 
     def test_get_base_call_returns_html(self):
+        """Basic test for all-projects view"""
         response = self.client.get(reverse('all-projects'), follow=True)
         self.assertEqual(response.status_code, 200)
         self.assertTrue(response['Content-Type'].startswith('text/html'))
@@ -52,6 +76,7 @@ class ViewTests(TestCase):
         self.assertTrue(PROJECT_NAME in response.content)
 
     def test_get_json_call_returns_json(self):
+        """Test for all projects output in json format"""
         url = reverse('all-projects')
         response = self.client.get(url, {"format": "json"}, follow=True)
         self.assertEqual(response.status_code, 200)
@@ -73,6 +98,7 @@ class ViewTests(TestCase):
         self.assertTrue("projectBuildsUrl" in data["rows"][0])
 
     def test_typeaheads(self):
+        """Test typeahead ReST API"""
         layers_url = reverse('xhr_layerstypeahead', args=(self.project.id,))
         prj_url = reverse('xhr_projectstypeahead')
 
@@ -82,7 +108,8 @@ class ViewTests(TestCase):
                  reverse('xhr_machinestypeahead', args=(self.project.id,)),
                ]
 
-        def basic_reponse_check(reponse, url):
+        def basic_reponse_check(response, url):
+            """Check data structure of http response."""
             self.assertEqual(response.status_code, 200)
             self.assertTrue(response['Content-Type'].startswith('application/json'))
 
-- 
2.1.4



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

* [PATCH 08/11] toaster: don't catch json.load exceptions
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (6 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 07/11] toaster: add header and docstings Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 09/11] toaster: fix test_get_json_call_returns_json again Michael Wood
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

It doesn't make sense to catch json.load exceptions in the
testing code. If API throws traceback it's better to see
it instead of error message.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 1ed83dc..723348d 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -82,10 +82,7 @@ class ViewTests(TestCase):
         self.assertEqual(response.status_code, 200)
         self.assertTrue(response['Content-Type'].startswith('application/json'))
 
-        try:
-            data = json.loads(response.content)
-        except:
-            self.fail("Response %s is not json-loadable" % response.content)
+        data = json.loads(response.content)
 
         self.assertTrue("error" in data)
         self.assertEqual(data["error"], "ok")
@@ -113,10 +110,8 @@ class ViewTests(TestCase):
             self.assertEqual(response.status_code, 200)
             self.assertTrue(response['Content-Type'].startswith('application/json'))
 
-            try:
-                data = json.loads(response.content)
-            except:
-                self.fail("Response %s is not json-loadable" % response.content)
+            data = json.loads(response.content)
+
             self.assertTrue("error" in data)
             self.assertEqual(data["error"], "ok")
             self.assertTrue("results" in data)
-- 
2.1.4



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

* [PATCH 09/11] toaster: fix test_get_json_call_returns_json again
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (7 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 08/11] toaster: don't catch json.load exceptions Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 10/11] toaster: fix pylint warning 'no space allowed' Michael Wood
  2015-08-10 17:27 ` [PATCH 11/11] toaster: reduced amount of instance attributes Michael Wood
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Fixed this test case again after rebase. Improved it
to check for all returned keys. Previously it was checking
only 3 of them.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index 723348d..d155849 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -90,9 +90,13 @@ class ViewTests(TestCase):
 
         self.assertTrue(PROJECT_NAME in [x["name"] for x in data["rows"]])
         self.assertTrue("id" in data["rows"][0])
-        self.assertTrue("projectLayersUrl" in data["rows"][0])
-        self.assertTrue("projectPageUrl" in data["rows"][0])
-        self.assertTrue("projectBuildsUrl" in data["rows"][0])
+
+        self.assertEqual(sorted(data["rows"][0]),
+                         ['bitbake_version_id', 'created', 'id',
+                          'layersTypeAheadUrl', 'name', 'projectBuildsUrl',
+                          'projectPageUrl', 'recipesTypeAheadUrl',
+                          'release_id', 'short_description', 'updated',
+                          'user_id'])
 
     def test_typeaheads(self):
         """Test typeahead ReST API"""
-- 
2.1.4



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

* [PATCH 10/11] toaster: fix pylint warning 'no space allowed'
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (8 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 09/11] toaster: fix test_get_json_call_returns_json again Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  2015-08-10 17:27 ` [PATCH 11/11] toaster: reduced amount of instance attributes Michael Wood
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Fixed pylint warning "No space allowed before/after bracket".

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index d155849..bc10801 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -103,10 +103,10 @@ class ViewTests(TestCase):
         layers_url = reverse('xhr_layerstypeahead', args=(self.project.id,))
         prj_url = reverse('xhr_projectstypeahead')
 
-        urls = [ layers_url,
-                 prj_url,
-                 reverse('xhr_recipestypeahead', args=(self.project.id,)),
-                 reverse('xhr_machinestypeahead', args=(self.project.id,)),
+        urls = [layers_url,
+                prj_url,
+                reverse('xhr_recipestypeahead', args=(self.project.id,)),
+                reverse('xhr_machinestypeahead', args=(self.project.id,)),
                ]
 
         def basic_reponse_check(response, url):
@@ -147,7 +147,7 @@ class ViewTests(TestCase):
             results = False
 
             for typeing in list(string.ascii_letters):
-                response = self.client.get(url, { 'search' : typeing })
+                response = self.client.get(url, {'search': typeing})
                 results = basic_reponse_check(response, url)
                 if results:
                     break
-- 
2.1.4



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

* [PATCH 11/11] toaster: reduced amount of instance attributes
  2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
                   ` (9 preceding siblings ...)
  2015-08-10 17:27 ` [PATCH 10/11] toaster: fix pylint warning 'no space allowed' Michael Wood
@ 2015-08-10 17:27 ` Michael Wood
  10 siblings, 0 replies; 12+ messages in thread
From: Michael Wood @ 2015-08-10 17:27 UTC (permalink / raw)
  To: bitbake-devel

From: Ed Bartosh <ed.bartosh@linux.intel.com>

Used local variables instead of instance attributes in ViewTests.setUp

Fixed pylint warning:
    Too many instance attributes (9/7) (too-many-instance-attributes)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 lib/toaster/toastergui/tests.py | 55 ++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
index bc10801..93a85ac 100644
--- a/lib/toaster/toastergui/tests.py
+++ b/lib/toaster/toastergui/tests.py
@@ -34,38 +34,31 @@ class ViewTests(TestCase):
     """Tests to verify view APIs."""
 
     def setUp(self):
-        self.bbv = BitbakeVersion.objects.create(\
-                       name="test bbv", giturl="/tmp/",
-                       branch="master", dirpath="")
-        self.release = Release.objects.create(\
-                           name="test release", bitbake_version=self.bbv)
+        bbv = BitbakeVersion.objects.create(name="test bbv", giturl="/tmp/",
+                                            branch="master", dirpath="")
+        release = Release.objects.create(name="test release",
+                                         bitbake_version=bbv)
         self.project = Project.objects.create_project(name=PROJECT_NAME,
-                                                      release=self.release)
-        self.layersrc = LayerSource.objects.create(\
-                               sourcetype=LayerSource.TYPE_IMPORTED)
-        self.priority = ReleaseLayerSourcePriority.objects.create(\
-                               release=self.release,
-                               layer_source=self.layersrc)
-        self.layer = Layer.objects.create(\
-                         name="base-layer",
-                         layer_source=self.layersrc, vcs_url="/tmp/")
-        self.lver = Layer_Version.objects.create(\
-                        layer=self.layer, project=self.project,
-                        layer_source=self.layersrc, commit="master")
-
-        self.recipe = Recipe.objects.create(\
-                          layer_source=self.layersrc, name="base-recipe",
-                          version="1.2", summary="one recipe",
-                          description="recipe", layer_version=self.lver)
-
-        self.machine = Machine.objects.create(\
-                          layer_version=self.lver, name="wisk",
-                          description="wisking machine")
-
-        ProjectLayer.objects.create(project=self.project,
-                                    layercommit=self.lver)
-
-        self.assertTrue(self.lver in self.project.compatible_layerversions())
+                                                      release=release)
+        layersrc = LayerSource.objects.create(sourcetype=LayerSource.TYPE_IMPORTED)
+        self.priority = ReleaseLayerSourcePriority.objects.create(release=release,
+                                                                  layer_source=layersrc)
+        layer = Layer.objects.create(name="base-layer", layer_source=layersrc,
+                                     vcs_url="/tmp/")
+
+        lver = Layer_Version.objects.create(layer=layer, project=self.project,
+                                            layer_source=layersrc, commit="master")
+
+        Recipe.objects.create(layer_source=layersrc, name="base-recipe",
+                              version="1.2", summary="one recipe",
+                              description="recipe", layer_version=lver)
+
+        Machine.objects.create(layer_version=lver, name="wisk",
+                               description="wisking machine")
+
+        ProjectLayer.objects.create(project=self.project, layercommit=lver)
+
+        self.assertTrue(lver in self.project.compatible_layerversions())
 
     def test_get_base_call_returns_html(self):
         """Basic test for all-projects view"""
-- 
2.1.4



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

end of thread, other threads:[~2015-08-10 17:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-10 17:26 [PATCH 00/11] Fixes and clean ups for toastergui unit tests Michael Wood
2015-08-10 17:27 ` [PATCH 01/11] toaster: fix test_get_json_call_returns_json test Michael Wood
2015-08-10 17:27 ` [PATCH 02/11] toaster: wrap long lines Michael Wood
2015-08-10 17:27 ` [PATCH 03/11] toaster: get rid of AllProjectsViewTestCase Michael Wood
2015-08-10 17:27 ` [PATCH 04/11] toaster: put all test cases into one class Michael Wood
2015-08-10 17:27 ` [PATCH 05/11] toaster: get rid of class attributes Michael Wood
2015-08-10 17:27 ` [PATCH 06/11] toaster: remove unused import Michael Wood
2015-08-10 17:27 ` [PATCH 07/11] toaster: add header and docstings Michael Wood
2015-08-10 17:27 ` [PATCH 08/11] toaster: don't catch json.load exceptions Michael Wood
2015-08-10 17:27 ` [PATCH 09/11] toaster: fix test_get_json_call_returns_json again Michael Wood
2015-08-10 17:27 ` [PATCH 10/11] toaster: fix pylint warning 'no space allowed' Michael Wood
2015-08-10 17:27 ` [PATCH 11/11] toaster: reduced amount of instance attributes Michael Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox