summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2015-08-04 22:46:38 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-06 16:04:47 -0500
commit0494a2769b72c3aa47461cf66c475c7677d1636c (patch)
treeeae32d7a97f7a60c2321550d51704fedb389bdd2 /bitbake/lib
parent4d7944d6adda400af9f8188a7d3de526a2a94384 (diff)
downloadpoky-0494a2769b72c3aa47461cf66c475c7677d1636c.tar.gz
bitbake: toastergui: tests Fix and more comprehensive typeahead unittest
Fix the currently broken unit test for typeaheads and add some additional fields to check for in layers, projects, recipes and machines typeaheads. (Bitbake rev: 5700cd269e3a4fd517e16a3a19e61a23091df465) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py88
1 files changed, 69 insertions, 19 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index 77e80fe3a9..8a59af46ef 100644
--- a/bitbake/lib/toaster/toastergui/tests.py
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -1,7 +1,8 @@
1from django.test import TestCase 1from django.test import TestCase
2from django.core.urlresolvers import reverse 2from django.core.urlresolvers import reverse
3from orm.models import Project, Release, BitbakeVersion, Build 3from orm.models import Project, Release, BitbakeVersion, Build
4from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Layer_Version 4from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Layer_Version, Recipe, Machine, ProjectLayer
5import json
5 6
6class ProvisionedProjectTestCase(TestCase): 7class ProvisionedProjectTestCase(TestCase):
7 TEST_PROJECT_NAME = "test project" 8 TEST_PROJECT_NAME = "test project"
@@ -27,7 +28,6 @@ class AllProjectsViewTestCase(ProvisionedProjectTestCase):
27 self.assertTrue(response['Content-Type'].startswith('application/json')) 28 self.assertTrue(response['Content-Type'].startswith('application/json'))
28 29
29 try: 30 try:
30 import json
31 data = json.loads(response.content) 31 data = json.loads(response.content)
32 except: 32 except:
33 self.fail("Response %s is not json-loadable" % response.content) 33 self.fail("Response %s is not json-loadable" % response.content)
@@ -44,6 +44,9 @@ class AllProjectsViewTestCase(ProvisionedProjectTestCase):
44 44
45class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase): 45class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase):
46 LAYER_NAME = "base-layer" 46 LAYER_NAME = "base-layer"
47 RECIPE_NAME = "base-recipe"
48
49
47 def setUp(self): 50 def setUp(self):
48 super(ProvisionedLayersProjectTestCase, self).setUp() 51 super(ProvisionedLayersProjectTestCase, self).setUp()
49 self.layersource, created = LayerSource.objects.get_or_create(sourcetype = LayerSource.TYPE_IMPORTED) 52 self.layersource, created = LayerSource.objects.get_or_create(sourcetype = LayerSource.TYPE_IMPORTED)
@@ -51,6 +54,13 @@ class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase):
51 self.layer, created = Layer.objects.get_or_create(name=XHRDataTypeAheadTestCase.LAYER_NAME, layer_source=self.layersource, vcs_url="/tmp/") 54 self.layer, created = Layer.objects.get_or_create(name=XHRDataTypeAheadTestCase.LAYER_NAME, layer_source=self.layersource, vcs_url="/tmp/")
52 self.lv, created = Layer_Version.objects.get_or_create(layer = self.layer, project = self.project, layer_source=self.layersource, commit="master") 55 self.lv, created = Layer_Version.objects.get_or_create(layer = self.layer, project = self.project, layer_source=self.layersource, commit="master")
53 56
57 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)
58
59 self.machine, created = Machine.objects.get_or_create(layer_version=self.lv, name="wisk", description="wisking machine")
60
61 ProjectLayer.objects.get_or_create(project = self.project,
62 layercommit = self.lv)
63
54 64
55class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase): 65class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):
56 66
@@ -58,20 +68,60 @@ class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):
58 super(XHRDataTypeAheadTestCase, self).setUp() 68 super(XHRDataTypeAheadTestCase, self).setUp()
59 self.assertTrue(self.lv in self.project.compatible_layerversions()) 69 self.assertTrue(self.lv in self.project.compatible_layerversions())
60 70
61 def test_xhr_datatypeahead_layer(self): 71 def test_typeaheads(self):
62 response = self.client.get(reverse('xhr_datatypeahead', args=(self.project.id,)), {"type": "layerdeps"}) 72 layers_url = reverse('xhr_layerstypeahead', args=(self.project.id,))
63 self.assertEqual(response.status_code, 200) 73 prj_url = reverse('xhr_projectstypeahead')
64 self.assertTrue(response['Content-Type'].startswith('application/json')) 74
65 75 urls = [ layers_url,
66 try: 76 prj_url,
67 import json 77 reverse('xhr_recipestypeahead', args=(self.project.id,)),
68 data = json.loads(response.content) 78 reverse('xhr_machinestypeahead', args=(self.project.id,)),
69 except: 79 ]
70 self.fail("Response %s is not json-loadable" % response.content) 80
71 81 def basic_reponse_check(reponse, url):
72 self.assertTrue("error" in data) 82 self.assertEqual(response.status_code, 200)
73 self.assertEqual(data["error"], "ok") 83 self.assertTrue(response['Content-Type'].startswith('application/json'))
74 self.assertTrue("list" in data) 84
75 self.assertTrue(len(data["list"]) > 0) 85 try:
76 86 data = json.loads(response.content)
77 self.assertTrue(XHRDataTypeAheadTestCase.LAYER_NAME in map(lambda x: x["name"], data["list"])) 87 except:
88 self.fail("Response %s is not json-loadable" % response.content)
89 self.assertTrue("error" in data)
90 self.assertEqual(data["error"], "ok")
91 self.assertTrue("results" in data)
92
93 # We got a result so now check the fields
94 if len(data['results']) > 0:
95 result = data['results'][0]
96
97 self.assertTrue(len(result['name']) > 0)
98 self.assertTrue("detail" in result)
99 self.assertTrue(result['id'] > 0)
100
101 # Special check for the layers typeahead's extra fields
102 if url == layers_url:
103 self.assertTrue(len(result['layerdetailurl']) > 0)
104 self.assertTrue(len(result['vcs_url']) > 0)
105 self.assertTrue(len(result['vcs_reference']) > 0)
106 # Special check for project typeahead extra fields
107 elif url == prj_url:
108 self.assertTrue(len(result['projectPageUrl']) > 0)
109
110 return True
111
112 return False
113
114 import string
115
116 for url in urls:
117 results = False
118
119 for typeing in list(string.ascii_letters):
120 response = self.client.get(url, { 'search' : typeing })
121 results = basic_reponse_check(response, url)
122 if results:
123 break
124
125 # After "typeing" the alpabet we should have result true
126 # from each of the urls
127 self.assertTrue(results)