summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-05-19 17:22:46 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-29 11:59:46 +0100
commit65c805eb6a3415698fe29a5c726a6d4277bcbb11 (patch)
tree8afc84132c67c7af0e228b73325277b64af6300f /bitbake/lib/toaster/toastergui
parentfea4a82a2b9fdbbccd0a09a76208cebbefdd8b20 (diff)
downloadpoky-65c805eb6a3415698fe29a5c726a6d4277bcbb11.tar.gz
bitbake: toastergui: tests for the all-projects API point
This patch adds Django tests that verify that the 'all-projects' page returns a valid HTML page when invoked normally, containing the project name; and valid JSON containing API-needed fields if the GET parameter `format` is set to "json" (Bitbake rev: 9edd61fe7afaf273ed31d214af9251462182ad4f) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
new file mode 100644
index 0000000000..8a78a41caa
--- /dev/null
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -0,0 +1,36 @@
1from django.test import TestCase
2from django.core.urlresolvers import reverse
3from orm.models import Project, Release, BitbakeVersion, Build
4
5class AllProjectsViewTestCase(TestCase):
6 TEST_PROJECT_NAME = "test project"
7
8 def setUp(self):
9 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 Project.objects.create_project(name=AllProjectsViewTestCase.TEST_PROJECT_NAME, release=release)
12
13 def test_get_base_call_returns_html(self):
14 response = self.client.get(reverse('all-projects'), follow=True)
15 self.assertEqual(response.status_code, 200)
16 self.assertTrue(response['Content-Type'].startswith('text/html'))
17 self.assertTemplateUsed(response, "projects.html")
18 self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in response.content)
19
20 def test_get_json_call_returns_json(self):
21 response = self.client.get(reverse('all-projects'), {"format": "json"}, follow=True)
22 self.assertEqual(response.status_code, 200)
23 self.assertTrue(response['Content-Type'].startswith('application/json'))
24 try:
25 import json
26 data = json.loads(response.content)
27 except:
28 self.fail("Response %s is not json-loadable" % response.content)
29
30 self.assertTrue("list" in data)
31 self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in map(lambda x: x["name"], data["list"]))
32 self.assertTrue("id" in data["list"][0])
33 self.assertTrue("xhrProjectDataTypeaheadUrl" in data["list"][0])
34 self.assertTrue("projectPageUrl" in data["list"][0])
35 self.assertTrue("xhrProjectEditUrl" in data["list"][0])
36 self.assertTrue("projectBuildUrl" in data["list"][0])