Skip to contentSkip to conversation

toastergui: Add tests for xhr_importlayer

PATCH Superseded Sujith H 2 participants 4 messages Aug 10, 2015 – Aug 11, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sujith H

author
#0 lore raw

PATCH v2 1/1 toastergui: Add tests for xhr_importlayer

Inorder to make sure if layer name which we import is already available in toaster database, a test case has been included. This would help user to identify if layer name which has been provided in the import layer web page already exists or not.

---
 bitbake/lib/toaster/toastergui/tests.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
bitbake/lib/toaster/toastergui/tests.py +32 -0
index 93a85ac..2986e57 100644
@@ -148,3 +148,35 @@ class ViewTests(TestCase):
             # After "typeing" the alpabet we should have result true
             # from each of the urls
             self.assertTrue(results)
+
+class XHRImportLayerTestCase(ViewTests):
+    """ Tests to verify xhr_importlayer API"""
+    def setUp(self):
+        super(XHRImportLayerTestCase, self).setUp()
+
+    def test_import(self):
+        """Tests to verify import layer already exist, if the imported layer is ok, response
+        for empty data, response for html tag in data"""
+        #Test for importing an already existing layer
+        data = {'vcs_url' : "git://git.example.com/test",
+                'name' : "base-layer", 'git_ref': "c12b9596afd236116b25ce26dbe0d793de9dc7ce",
+                'project_id': 1, 'dir_path' : "/path/in/repository"}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertEqual(result.status_code, 200)
+        self.assertTrue("hint-layer-exists-with-different-url" in result.content)
+
+        #Test to verify import of a layer successful
+        data['name'] = "meta-oe"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "ok"' in result.content)
+
+        #Test for html tag in the data
+        data['<'] = "testing html tag"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Invalid character <"' in result.content)
+
+        #Empty data passed
+        data = {}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Missing parameters; requires vcs_url, \
+                        name, git_ref and project_id"' in result.content)
Signature · 1 line
1.9.1
author
#1 lore raw

Hi Ed,

I have rebased the patch on branch d/toaster/fix-toastergui-tests.

I ran : pylint --load-plugins pylint_django toastergui/tests.py; and got a score of 10.

Let me know if more changes are required.

Thanks,
Sujith H

Quoted 61 lines · Sujith H

Inorder to make sure if layer name which we import is already available in toaster database, a test case has been included. This would help user to identify if layer name which has been provided in the import layer web page already exists or not.

---
 bitbake/lib/toaster/toastergui/tests.py | 32
++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
bitbake/lib/toaster/toastergui/tests.py +8 -0
index 93a85ac..2986e57 100644
@@ -148,3 +148,35 @@ class ViewTests(TestCase):
             # After "typeing" the alpabet we should have result true
             # from each of the urls
             self.assertTrue(results)
+
+class XHRImportLayerTestCase(ViewTests):
+    """ Tests to verify xhr_importlayer API"""
+    def setUp(self):
+        super(XHRImportLayerTestCase, self).setUp()
+
+    def test_import(self):
+        """Tests to verify import layer already exist, if the imported

layer is ok, response

bitbake/lib/toaster/toastergui/tests.py +4 -0
+        for empty data, response for html tag in data"""
+        #Test for importing an already existing layer
+        data = {'vcs_url' : "git://git.example.com/test",
+                'name' : "base-layer", 'git_ref':

"c12b9596afd236116b25ce26dbe0d793de9dc7ce",

bitbake/lib/toaster/toastergui/tests.py +4 -0
+                'project_id': 1, 'dir_path' : "/path/in/repository"}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertEqual(result.status_code, 200)
+        self.assertTrue("hint-layer-exists-with-different-url" in

result.content)

bitbake/lib/toaster/toastergui/tests.py +10 -0
+
+        #Test to verify import of a layer successful
+        data['name'] = "meta-oe"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "ok"' in result.content)
+
+        #Test for html tag in the data
+        data['<'] = "testing html tag"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Invalid character <"' in

result.content)

bitbake/lib/toaster/toastergui/tests.py +6 -1
+
+        #Empty data passed
+        data = {}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Missing parameters; requires vcs_url, \
+                        name, git_ref and project_id"' in result.content)
--

1.9.1

Signature · 5 lines
സുജിത് ഹരിദാസന്
Bangalore
<Project>Contributor to KDE project
http://fci.wikia.com/wiki/Anti-DRM-Campaign
<Blog> http://sujithh.info
#2 lore raw
In reply to Sujith H

Hi Sujith,

Thank you for updating your patch.

My comments are below.

Quoted 16 lines · Sujith H

Inorder to make sure if layer name which we import is already available in toaster database, a test case has been included. This would help user to identify if layer name which has been provided in the import layer web page already exists or not.

---
 bitbake/lib/toaster/toastergui/tests.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
bitbake/lib/toaster/toastergui/tests.py +0 -0
index 93a85ac..2986e57 100644

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 155

Quoted 8 lines
bitbake/lib/toaster/toastergui/tests.py +5 -0
@@ -148,3 +148,35 @@ class ViewTests(TestCase):
             # After "typeing" the alpabet we should have result true
             # from each of the urls
             self.assertTrue(results)
+
+class XHRImportLayerTestCase(ViewTests):
+    """ Tests to verify xhr_importlayer API"""
+    def setUp(self):
+        super(XHRImportLayerTestCase, self).setUp()

Do you really need a new class for your test case? If you add it to ViewTests you don't need above 4 lines.

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 159

Quoted 4 lines
bitbake/lib/toaster/toastergui/tests.py +4 -0
+
+    def test_import(self):
+        """Tests to verify import layer already exist, if the imported layer is ok, response
+        for empty data, response for html tag in data"""

Please, split dosctring to subject line and the body to make output of ./manage.py test -v2 toastergui meaningful.

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 161

Quoted 2 lines
bitbake/lib/toaster/toastergui/tests.py +2 -0
+        #Test for importing an already existing layer
+        data = {'vcs_url' : "git://git.example.com/test",

I'd suggest to rename data->args.

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 166

Quoted 5 lines
bitbake/lib/toaster/toastergui/tests.py +5 -0
+                'name' : "base-layer", 'git_ref': "c12b9596afd236116b25ce26dbe0d793de9dc7ce",
+                'project_id': 1, 'dir_path' : "/path/in/repository"}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertEqual(result.status_code, 200)
+        self.assertTrue("hint-layer-exists-with-different-url" in result.content)

It would be better to convert result from json using json.load as it's done in other test cases, i.e.
data = json.loads(response.content) self.assertNotEqual(data["error"], "ok")

Quoted 5 lines
bitbake/lib/toaster/toastergui/tests.py +5 -0
+        #Test to verify import of a layer successful
+        data['name'] = "meta-oe"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "ok"' in result.content)
+

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 182

Quoted 10 lines
bitbake/lib/toaster/toastergui/tests.py +10 -0
+        #Test for html tag in the data
+        data['<'] = "testing html tag"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Invalid character <"' in result.content)
+
+        #Empty data passed
+        data = {}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Missing parameters; requires vcs_url, \
+                        name, git_ref and project_id"' in result.content)

Would it be enough to check that error is not 'ok'? If you change a message you will not have to change test code.

Please, make your code similar to the existing code. Use the same vairable names, checks, etc. It would make test code look and behave in a consistent way.

--
Regards,
Ed

author
#3 lore raw
Quoted 75 lines · Ed Bartosh

Hi Sujith,

Thank you for updating your patch.

My comments are below.

Quoted 9 lines · Sujith H

Inorder to make sure if layer name which we import is already available in toaster database, a test case has been included. This would help user to identify if layer name which has been provided in the import layer web page already exists or not.

---
 bitbake/lib/toaster/toastergui/tests.py | 32

++++++++++++++++++++++++++++++++

Review

Quoted 3 lines
 1 file changed, 32 insertions(+)
(quoted diff) +0 -0

b/bitbake/lib/toaster/toastergui/tests.py

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 155

Quoted 12 lines

index 93a85ac..2986e57 100644

bitbake/lib/toaster/toastergui/tests.py +5 -0
@@ -148,3 +148,35 @@ class ViewTests(TestCase):
             # After "typeing" the alpabet we should have result true
             # from each of the urls
             self.assertTrue(results)
+
+class XHRImportLayerTestCase(ViewTests):
+    """ Tests to verify xhr_importlayer API"""
+    def setUp(self):
+        super(XHRImportLayerTestCase, self).setUp()

Do you really need a new class for your test case? If you add it to ViewTests you don't need above 4 lines.

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase):

Quoted 3 lines
bitbake/lib/toaster/toastergui/tests.py +3 -0
+
+    def test_import(self):
+        """Tests to verify import layer already exist, if the imported

layer is ok, response

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 159

Quoted 1 line
bitbake/lib/toaster/toastergui/tests.py +1 -0
+        for empty data, response for html tag in data"""

Please, split dosctring to subject line and the body to make output of ./manage.py test -v2 toastergui meaningful.

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 161

Quoted 2 lines
bitbake/lib/toaster/toastergui/tests.py +2 -0
+        #Test for importing an already existing layer
+        data = {'vcs_url' : "git://git.example.com/test",

I'd suggest to rename data->args.

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 162

Quoted 1 line
bitbake/lib/toaster/toastergui/tests.py +1 -0
+                'name' : "base-layer", 'git_ref':

"c12b9596afd236116b25ce26dbe0d793de9dc7ce",

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase):

Quoted 4 lines
bitbake/lib/toaster/toastergui/tests.py +4 -0
+                'project_id': 1, 'dir_path' : "/path/in/repository"}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertEqual(result.status_code, 200)
+        self.assertTrue("hint-layer-exists-with-different-url" in

result.content)
It would be better to convert result from json using json.load as it's done in other test cases, i.e.
data = json.loads(response.content) self.assertNotEqual(data["error"], "ok")

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase):

Quoted 9 lines
bitbake/lib/toaster/toastergui/tests.py +9 -0
+        #Test to verify import of a layer successful
+        data['name'] = "meta-oe"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "ok"' in result.content)
+
+        #Test for html tag in the data
+        data['<'] = "testing html tag"
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Invalid character <"' in

result.content)

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase):

Quoted 5 lines
bitbake/lib/toaster/toastergui/tests.py +5 -0
+
+        #Empty data passed
+        data = {}
+        result = self.client.post(reverse('xhr_importlayer'), data)
+        self.assertTrue('"error": "Missing parameters; requires

vcs_url, \

Quoted 9 lines

bitbake/lib/toaster/toastergui/tests.py class ViewTests(TestCase): · line 181

Quoted 1 line
bitbake/lib/toaster/toastergui/tests.py +1 -0
+                        name, git_ref and project_id"' in

result.content)
Would it be enough to check that error is not 'ok'? If you change a message you will not have to change test code.

Please, make your code similar to the existing code. Use the same vairable names, checks, etc. It would make test code look and behave in a consistent way.

Thanks for detailed feed back. I will make modifications accordingly and re-submit the patch.

Thanks,
Sujith H

Signature · 5 lines
സുജിത് ഹരിദാസന്
Bangalore
<Project>Contributor to KDE project
http://fci.wikia.com/wiki/Anti-DRM-Campaign
<Blog> http://sujithh.info