summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-05-19 18:02:21 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-29 11:59:46 +0100
commit22a0d8aab2db31a4276bd523f484936efe3f0410 (patch)
tree3cc83b8b6254b61313a925bee4289d7cfc93b172 /bitbake
parent65c805eb6a3415698fe29a5c726a6d4277bcbb11 (diff)
downloadpoky-22a0d8aab2db31a4276bd523f484936efe3f0410.tar.gz
bitbake: toastergui: add tests for xhr_datatypeahead calls
In order to make sure we replace the xhr_datatypeahead calls with similar APIs, we add tests that validate the data returned by the xhr_datatypeahead. A copy of these tests will be enabled for each type of datatypeahead that will be replaced. (Bitbake rev: 9a3197fba46b38e5863e7ded11e4bf9530cfcc9b) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py50
1 files changed, 46 insertions, 4 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index 8a78a41caa..0f10020940 100644
--- a/bitbake/lib/toaster/toastergui/tests.py
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -1,14 +1,18 @@
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
4 5
5class AllProjectsViewTestCase(TestCase): 6class ProvisionedProjectTestCase(TestCase):
6 TEST_PROJECT_NAME = "test project" 7 TEST_PROJECT_NAME = "test project"
7 8
8 def setUp(self): 9 def setUp(self):
9 bbv, created = BitbakeVersion.objects.get_or_create(name="test bbv", giturl="/tmp/", branch="master", dirpath="") 10 self.bbv, created = BitbakeVersion.objects.get_or_create(name="test bbv", giturl="/tmp/", branch="master", dirpath="")
10 release, created = Release.objects.get_or_create(name="test release", bitbake_version = bbv) 11 self.release, created = Release.objects.get_or_create(name="test release", bitbake_version = self.bbv)
11 Project.objects.create_project(name=AllProjectsViewTestCase.TEST_PROJECT_NAME, release=release) 12 self.project = Project.objects.create_project(name=AllProjectsViewTestCase.TEST_PROJECT_NAME, release=self.release)
13
14
15class AllProjectsViewTestCase(ProvisionedProjectTestCase):
12 16
13 def test_get_base_call_returns_html(self): 17 def test_get_base_call_returns_html(self):
14 response = self.client.get(reverse('all-projects'), follow=True) 18 response = self.client.get(reverse('all-projects'), follow=True)
@@ -21,16 +25,54 @@ class AllProjectsViewTestCase(TestCase):
21 response = self.client.get(reverse('all-projects'), {"format": "json"}, follow=True) 25 response = self.client.get(reverse('all-projects'), {"format": "json"}, follow=True)
22 self.assertEqual(response.status_code, 200) 26 self.assertEqual(response.status_code, 200)
23 self.assertTrue(response['Content-Type'].startswith('application/json')) 27 self.assertTrue(response['Content-Type'].startswith('application/json'))
28
24 try: 29 try:
25 import json 30 import json
26 data = json.loads(response.content) 31 data = json.loads(response.content)
27 except: 32 except:
28 self.fail("Response %s is not json-loadable" % response.content) 33 self.fail("Response %s is not json-loadable" % response.content)
29 34
35 self.assertTrue("error" in data)
36 self.assertEqual(data["error"], "ok")
30 self.assertTrue("list" in data) 37 self.assertTrue("list" in data)
38
31 self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in map(lambda x: x["name"], data["list"])) 39 self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in map(lambda x: x["name"], data["list"]))
32 self.assertTrue("id" in data["list"][0]) 40 self.assertTrue("id" in data["list"][0])
33 self.assertTrue("xhrProjectDataTypeaheadUrl" in data["list"][0]) 41 self.assertTrue("xhrProjectDataTypeaheadUrl" in data["list"][0])
34 self.assertTrue("projectPageUrl" in data["list"][0]) 42 self.assertTrue("projectPageUrl" in data["list"][0])
35 self.assertTrue("xhrProjectEditUrl" in data["list"][0]) 43 self.assertTrue("xhrProjectEditUrl" in data["list"][0])
36 self.assertTrue("projectBuildUrl" in data["list"][0]) 44 self.assertTrue("projectBuildUrl" in data["list"][0])
45
46class ProvisionedLayersProjectTestCase(ProvisionedProjectTestCase):
47 LAYER_NAME = "base-layer"
48 def setUp(self):
49 super(ProvisionedLayersProjectTestCase, self).setUp()
50 self.layersource, created = LayerSource.objects.get_or_create(sourcetype = LayerSource.TYPE_IMPORTED)
51 self.releaselayersourcepriority, created = ReleaseLayerSourcePriority.objects.get_or_create(release = self.release, layer_source = self.layersource)
52 self.layer, created = Layer.objects.get_or_create(name=XHRDataTypeAheadTestCase.LAYER_NAME, layer_source=self.layersource, vcs_url="/tmp/")
53 self.lv, created = Layer_Version.objects.get_or_create(layer = self.layer, project = self.project, layer_source=self.layersource, commit="master")
54
55
56class XHRDataTypeAheadTestCase(ProvisionedLayersProjectTestCase):
57
58 def setUp(self):
59 super(XHRDataTypeAheadTestCase, self).setUp()
60 self.assertTrue(self.lv in self.project.compatible_layerversions())
61
62 def test_xhr_datatypeahead_layer(self):
63 response = self.client.get(reverse('xhr_datatypeahead', args=(self.project.id,)), {"type": "layers"})
64 self.assertEqual(response.status_code, 200)
65 self.assertTrue(response['Content-Type'].startswith('application/json'))
66
67 try:
68 import json
69 data = json.loads(response.content)
70 except:
71 self.fail("Response %s is not json-loadable" % response.content)
72
73 self.assertTrue("error" in data)
74 self.assertEqual(data["error"], "ok")
75 self.assertTrue("list" in data)
76 self.assertTrue(len(data["list"]) > 0)
77
78 self.assertTrue(XHRDataTypeAheadTestCase.LAYER_NAME in map(lambda x: x["name"], data["list"]))