summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/tests.py
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2015-09-28 21:45:25 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-29 14:11:37 +0100
commite68f63a1bdc0538a7e88bc78ec9c8a3f0abee70d (patch)
tree053eacf036a093946d6117e3097f8aa8c62be75f /bitbake/lib/toaster/toastergui/tests.py
parentd98c771a9aa047a71a30b570aba544c043d05447 (diff)
downloadpoky-e68f63a1bdc0538a7e88bc78ec9c8a3f0abee70d.tar.gz
bitbake: toaster: Add test cases for new Image customisation features
- Adds tests for new ToasterTables - Adds tests for new ReST API co-author: Elliot Smith <elliot.smith@intel.com> Michael Wood <michael.g.wood@intel.com> (Bitbake rev: 69f4ece18d70825d620f1d360749d587ea16f2a0) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: brian avery <avery.brian@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/tests.py')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py187
1 files changed, 182 insertions, 5 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index 53012b43cd..5d15ac9478 100644
--- a/bitbake/lib/toaster/toastergui/tests.py
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -24,13 +24,21 @@
24import re 24import re
25 25
26from django.test import TestCase 26from django.test import TestCase
27from django.test.client import RequestFactory
27from django.core.urlresolvers import reverse 28from django.core.urlresolvers import reverse
28from django.utils import timezone 29from django.utils import timezone
29from orm.models import Project, Release, BitbakeVersion, ProjectTarget 30
31from orm.models import Project, Release, BitbakeVersion, Build, Package
30from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Build 32from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Build
31from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target 33from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target
34from orm.models import CustomImageRecipe
35from orm.models import Branch
36
37from toastergui.tables import SoftwareRecipesTable
38from django.utils import timezone
32import json 39import json
33from bs4 import BeautifulSoup 40from bs4 import BeautifulSoup
41import re
34 42
35PROJECT_NAME = "test project" 43PROJECT_NAME = "test project"
36 44
@@ -41,27 +49,58 @@ class ViewTests(TestCase):
41 bbv = BitbakeVersion.objects.create(name="test bbv", giturl="/tmp/", 49 bbv = BitbakeVersion.objects.create(name="test bbv", giturl="/tmp/",
42 branch="master", dirpath="") 50 branch="master", dirpath="")
43 release = Release.objects.create(name="test release", 51 release = Release.objects.create(name="test release",
52 branch_name="master",
44 bitbake_version=bbv) 53 bitbake_version=bbv)
45 self.project = Project.objects.create_project(name=PROJECT_NAME, 54 self.project = Project.objects.create_project(name=PROJECT_NAME,
46 release=release) 55 release=release)
56 now = timezone.now()
57
58 build = Build.objects.create(project=self.project,
59 started_on=now,
60 completed_on=now)
61
47 layersrc = LayerSource.objects.create(sourcetype=LayerSource.TYPE_IMPORTED) 62 layersrc = LayerSource.objects.create(sourcetype=LayerSource.TYPE_IMPORTED)
48 self.priority = ReleaseLayerSourcePriority.objects.create(release=release, 63 self.priority = ReleaseLayerSourcePriority.objects.create(release=release,
49 layer_source=layersrc) 64 layer_source=layersrc)
50 layer = Layer.objects.create(name="base-layer", layer_source=layersrc, 65 layer = Layer.objects.create(name="base-layer", layer_source=layersrc,
51 vcs_url="/tmp/") 66 vcs_url="/tmp/")
52 67
68 branch = Branch.objects.create(name="master", layer_source=layersrc)
69
53 lver = Layer_Version.objects.create(layer=layer, project=self.project, 70 lver = Layer_Version.objects.create(layer=layer, project=self.project,
54 layer_source=layersrc, commit="master") 71 layer_source=layersrc, commit="master",
72 up_branch=branch)
55 73
56 Recipe.objects.create(layer_source=layersrc, name="base-recipe", 74 self.recipe1 = Recipe.objects.create(layer_source=layersrc,
57 version="1.2", summary="one recipe", 75 name="base-recipe",
58 description="recipe", layer_version=lver) 76 version="1.2",
77 summary="one recipe",
78 description="recipe",
79 layer_version=lver)
59 80
60 Machine.objects.create(layer_version=lver, name="wisk", 81 Machine.objects.create(layer_version=lver, name="wisk",
61 description="wisking machine") 82 description="wisking machine")
62 83
63 ProjectLayer.objects.create(project=self.project, layercommit=lver) 84 ProjectLayer.objects.create(project=self.project, layercommit=lver)
64 85
86
87 self.customr = CustomImageRecipe.objects.create(\
88 name="custom recipe", project=self.project,
89 base_recipe=self.recipe1)
90
91 self.package = Package.objects.create(name='pkg1', recipe=self.recipe1,
92 build=build)
93
94
95 # recipe with project for testing AvailableRecipe table
96 self.recipe2 = Recipe.objects.create(layer_source=layersrc,
97 name="fancy-recipe",
98 version="1.4",
99 summary="a fancy recipe",
100 description="fancy recipe",
101 layer_version=lver,
102 file_path='/home/foo')
103
65 self.assertTrue(lver in self.project.compatible_layerversions()) 104 self.assertTrue(lver in self.project.compatible_layerversions())
66 105
67 def test_get_base_call_returns_html(self): 106 def test_get_base_call_returns_html(self):
@@ -183,6 +222,144 @@ class ViewTests(TestCase):
183 data = json.loads(response.content) 222 data = json.loads(response.content)
184 self.assertNotEqual(data["error"], "ok") 223 self.assertNotEqual(data["error"], "ok")
185 224
225 def test_custom_ok(self):
226 """Test successful return from ReST API xhr_customrecipe"""
227 url = reverse('xhr_customrecipe')
228 params = {'name': 'custom', 'project': self.project.id,
229 'base': self.recipe1.id}
230 response = self.client.post(url, params)
231 self.assertEqual(response.status_code, 200)
232 data = json.loads(response.content)
233 self.assertEqual(data['error'], 'ok')
234 self.assertTrue('url' in data)
235 # get recipe from the database
236 recipe = CustomImageRecipe.objects.get(project=self.project,
237 name=params['name'])
238 args = (self.project.id, recipe.id,)
239 self.assertEqual(reverse('customrecipe', args=args), data['url'])
240
241 def test_custom_incomplete_params(self):
242 """Test not passing all required parameters to xhr_customrecipe"""
243 url = reverse('xhr_customrecipe')
244 for params in [{}, {'name': 'custom'},
245 {'name': 'custom', 'project': self.project.id}]:
246 response = self.client.post(url, params)
247 self.assertEqual(response.status_code, 200)
248 data = json.loads(response.content)
249 self.assertNotEqual(data["error"], "ok")
250
251 def test_xhr_custom_wrong_project(self):
252 """Test passing wrong project id to xhr_customrecipe"""
253 url = reverse('xhr_customrecipe')
254 params = {'name': 'custom', 'project': 0, "base": self.recipe1.id}
255 response = self.client.post(url, params)
256 self.assertEqual(response.status_code, 200)
257 data = json.loads(response.content)
258 self.assertNotEqual(data["error"], "ok")
259
260 def test_xhr_custom_wrong_base(self):
261 """Test passing wrong base recipe id to xhr_customrecipe"""
262 url = reverse('xhr_customrecipe')
263 params = {'name': 'custom', 'project': self.project.id, "base": 0}
264 response = self.client.post(url, params)
265 self.assertEqual(response.status_code, 200)
266 data = json.loads(response.content)
267 self.assertNotEqual(data["error"], "ok")
268
269 def test_xhr_custom_details(self):
270 """Test getting custom recipe details"""
271 name = "custom recipe"
272 url = reverse('xhr_customrecipe_id', args=(self.customr.id,))
273 response = self.client.get(url)
274 self.assertEqual(response.status_code, 200)
275 expected = {"error": "ok",
276 "info": {'id': self.customr.id,
277 'name': name,
278 'base_recipe_id': self.recipe1.id,
279 'project_id': self.project.id,
280 }
281 }
282 self.assertEqual(json.loads(response.content), expected)
283
284 def test_xhr_custom_del(self):
285 """Test deleting custom recipe"""
286 name = "to be deleted"
287 recipe = CustomImageRecipe.objects.create(\
288 name=name, project=self.project,
289 base_recipe=self.recipe1)
290 url = reverse('xhr_customrecipe_id', args=(recipe.id,))
291 response = self.client.delete(url)
292 self.assertEqual(response.status_code, 200)
293 self.assertEqual(json.loads(response.content), {"error": "ok"})
294 # try to delete not-existent recipe
295 url = reverse('xhr_customrecipe_id', args=(recipe.id,))
296 response = self.client.delete(url)
297 self.assertEqual(response.status_code, 200)
298 self.assertNotEqual(json.loads(response.content)["error"], "ok")
299
300 def test_xhr_custom_packages(self):
301 """Test adding and deleting package to a custom recipe"""
302 url = reverse('xhr_customrecipe_packages',
303 args=(self.customr.id, self.package.id))
304 # add self.package1 to recipe
305 response = self.client.put(url)
306 self.assertEqual(response.status_code, 200)
307 self.assertEqual(json.loads(response.content), {"error": "ok"})
308 self.assertEqual(self.customr.packages.all()[0].id, self.package.id)
309 # delete it
310 response = self.client.delete(url)
311 self.assertEqual(response.status_code, 200)
312 self.assertEqual(json.loads(response.content), {"error": "ok"})
313 self.assertFalse(self.customr.packages.all())
314 # delete it again to test error condition
315 response = self.client.delete(url)
316 self.assertEqual(response.status_code, 200)
317 self.assertNotEqual(json.loads(response.content)["error"], "ok")
318
319 def test_xhr_custom_packages_err(self):
320 """Test error conditions of xhr_customrecipe_packages"""
321 # test calls with wrong recipe id and wrong package id
322 for args in [(0, self.package.id), (self.customr.id, 0)]:
323 url = reverse('xhr_customrecipe_packages', args=args)
324 # test put and delete methods
325 for method in (self.client.put, self.client.delete):
326 response = method(url)
327 self.assertEqual(response.status_code, 200)
328 self.assertNotEqual(json.loads(response.content),
329 {"error": "ok"})
330
331 def test_software_recipes_table(self):
332 """Test structure returned for Software RecipesTable"""
333 table = SoftwareRecipesTable()
334 request = RequestFactory().get('/foo/', {'format': 'json'})
335 response = table.get(request, pid=self.project.id)
336 data = json.loads(response.content)
337
338 rows = data['rows']
339 row1 = next(x for x in rows if x['name'] == self.recipe1.name)
340 row1_btns = row1['static:add-del-layers']
341 row1_btns_data = row1['add-del-layers']
342 row2 = next(x for x in rows if x['name'] == self.recipe2.name)
343 row2_btns = row2['static:add-del-layers']
344 row2_btns_data = row2['add-del-layers']
345
346 self.assertEqual(response.status_code, 200, 'should be 200 OK status')
347 self.assertEqual(len(rows), 2, 'should be 2 recipes')
348
349 # check other columns have been populated correctly
350 self.assertEqual(row1['name'], self.recipe1.name)
351 self.assertEqual(row1['version'], self.recipe1.version)
352 self.assertEqual(row1['get_description_or_summary'],
353 self.recipe1.description)
354 self.assertEqual(row1['layer_version__layer__name'],
355 self.recipe1.layer_version.layer.name)
356 self.assertEqual(row2['name'], self.recipe2.name)
357 self.assertEqual(row2['version'], self.recipe2.version)
358 self.assertEqual(row2['get_description_or_summary'],
359 self.recipe2.description)
360 self.assertEqual(row2['layer_version__layer__name'],
361 self.recipe2.layer_version.layer.name)
362
186class LandingPageTests(TestCase): 363class LandingPageTests(TestCase):
187 """ Tests for redirects on the landing page """ 364 """ Tests for redirects on the landing page """
188 # disable bogus pylint message error: 365 # disable bogus pylint message error: