Skip to contentSkip to conversation

toastergui: Add tests for xhr_importlayer

PATCH Superseded Sujith H 2 participants 3 messages Aug 5, 2015 – Aug 6, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sujith H

author
#0 lore raw

PATCH 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 | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
bitbake/lib/toaster/toastergui/tests.py +18 -0
index 77e80fe..c4db145 100644
@@ -75,3 +75,21 @@ class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):
         self.assertTrue(len(data["list"]) > 0)
 
         self.assertTrue(XHRDataTypeAheadTestCase.LAYER_NAME in map(lambda x: x["name"], data["list"]))
+
+
+class XHRImportLayerTestCase(ProvisionedLayersProjectTestCase):
+
+    def setUp(self):
+        super(XHRImportLayerTestCase, self).setUp()
+        self.assertTrue(self.lv in self.project.compatible_layerversions())
+
+    def test_import(self):
+        data = {'vcs_url' : "/home/sujith/MEL/toaster_work/meta-oe" ,
+                'name' : "base-layer", 'git_ref': "c12b9596afd236116b25ce26dbe0d793de9dc7ce",
+                'project_id': 1, 'dir_path' : "/home/sujith/MEL/toaster_work/meta-oe/meta-oe"}
+        result  = self.client.post(reverse('xhr_importlayer'), data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+        self.assertEqual(result.status_code,200)
+        self.assertTrue("hint-layer-exists-with-different-url" in result.content)
+        data['name'] = "meta-oe"
+        result  = self.client.post(reverse('xhr_importlayer'), data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+        self.assertTrue('"error": "ok"' in result.content)
Signature · 1 line
1.9.1
#1 lore raw

Couple of comments inline:

Quoted 19 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 | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
bitbake/lib/toaster/toastergui/tests.py +0 -0
index 77e80fe..c4db145 100644
@@ -75,3 +75,21 @@ class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):
          self.assertTrue(len(data["list"]) > 0)
 
          self.assertTrue(XHRDataTypeAheadTestCase.LAYER_NAME in map(lambda x: x["name"], data["list"]))

bitbake/lib/toaster/toastergui/tests.py class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase): · line 87

Quoted 10 lines
bitbake/lib/toaster/toastergui/tests.py +10 -0
+
+
+class XHRImportLayerTestCase(ProvisionedLayersProjectTestCase):
+
+    def setUp(self):
+        super(XHRImportLayerTestCase, self).setUp()
+        self.assertTrue(self.lv in self.project.compatible_layerversions())
+
+    def test_import(self):
+        data = {'vcs_url' : "/home/sujith/MEL/toaster_work/meta-oe" ,

Could you use a faked vcs_url value, e.g. "git://git.example.com/test"

bitbake/lib/toaster/toastergui/tests.py class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase): · line 89

Quoted 2 lines
bitbake/lib/toaster/toastergui/tests.py +2 -0
+                'name' : "base-layer", 'git_ref': "c12b9596afd236116b25ce26dbe0d793de9dc7ce",
+                'project_id': 1, 'dir_path' : "/home/sujith/MEL/toaster_work/meta-oe/meta-oe"}

Same with this one, dir_path can be "/path/in/repository"

bitbake/lib/toaster/toastergui/tests.py class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase): · line 90

Quoted 1 line
bitbake/lib/toaster/toastergui/tests.py +1 -0
+        result  = self.client.post(reverse('xhr_importlayer'), data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')

I don't think HTTP_X_REQUESTED_WITH really needs setting, the default should be fine.

bitbake/lib/toaster/toastergui/tests.py class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase): · line 95

Quoted 5 lines
bitbake/lib/toaster/toastergui/tests.py +5 -0
+        self.assertEqual(result.status_code,200)
+        self.assertTrue("hint-layer-exists-with-different-url" in result.content)
+        data['name'] = "meta-oe"
+        result  = self.client.post(reverse('xhr_importlayer'), data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+        self.assertTrue('"error": "ok"' in result.content)

Some new lines between the logical parts in the test would be good.

It would be great to cover these two conditions as well:

{"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"} {"error": "Invalid character <"}

Thanks,

Michael

author
#2 lore raw
Quoted 45 lines · Michael Wood

Couple of comments inline:

Quoted 30 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 | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
bitbake/lib/toaster/toastergui/tests.py +0 -0
index 77e80fe..c4db145 100644
@@ -75,3 +75,21 @@ class

XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):

          self.assertTrue(len(data["list"]) > 0)
            self.assertTrue(XHRDataTypeAheadTestCase.LAYER_NAME in

map(lambda x: x["name"], data["list"]))

bitbake/lib/toaster/toastergui/tests.py +7 -0
+
+
+class XHRImportLayerTestCase(ProvisionedLayersProjectTestCase):
+
+    def setUp(self):
+        super(XHRImportLayerTestCase, self).setUp()
+        self.assertTrue(self.lv in

self.project.compatible_layerversions())

bitbake/lib/toaster/toastergui/tests.py class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase): · line 87

Quoted 3 lines
bitbake/lib/toaster/toastergui/tests.py +3 -0
+
+    def test_import(self):
+        data = {'vcs_url' : "/home/sujith/MEL/toaster_work/meta-oe" ,

Could you use a faked vcs_url value, e.g. "git://git.example.com/test"

+ 'name' : "base-layer", 'git_ref':

Quoted 4 lines

"c12b9596afd236116b25ce26dbe0d793de9dc7ce",
+ 'project_id': 1, 'dir_path' :
"/home/sujith/MEL/toaster_work/meta-oe/meta-oe"}

Quoted 8 lines

Same with this one, dir_path can be "/path/in/repository"

Quoted 3 lines

+ result = self.client.post(reverse('xhr_importlayer'), data,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')

I don't think HTTP_X_REQUESTED_WITH really needs setting, the default should be fine.

So if I understand correctly I can remove HTTP_X_REQUESTED_WITH from the argument list, right?

Quoted 8 lines

+ self.assertEqual(result.status_code,200)

Quoted 7 lines

+ self.assertTrue("hint-layer-exists-with-different-url" in
result.content)

bitbake/lib/toaster/toastergui/tests.py +2 -0
+        data['name'] = "meta-oe"
+        result  = self.client.post(reverse('xhr_importlayer'), data,

HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+ self.assertTrue('"error": "ok"' in result.content)

Quoted 8 lines

Some new lines between the logical parts in the test would be good.

It would be great to cover these two conditions as well:

{"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"}
{"error": "Invalid character <"}

Sure will incorporate the changes mentioned. Thanks for the feed back.

Quoted 10 lines

Thanks,

Michael
--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster

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