]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bitbake: toastergui: tests for the all-projects API point
authorAlexandru DAMIAN <alexandru.damian@intel.com>
Tue, 19 May 2015 16:22:46 +0000 (17:22 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 29 May 2015 10:59:46 +0000 (11:59 +0100)
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>
bitbake/lib/toaster/toastergui/tests.py [new file with mode: 0644]

diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
new file mode 100644 (file)
index 0000000..8a78a41
--- /dev/null
@@ -0,0 +1,36 @@
+from django.test import TestCase
+from django.core.urlresolvers import reverse
+from orm.models import Project, Release, BitbakeVersion, Build
+
+class AllProjectsViewTestCase(TestCase):
+    TEST_PROJECT_NAME = "test project"
+
+    def setUp(self):
+        bbv, created = BitbakeVersion.objects.get_or_create(name="test bbv", giturl="/tmp/", branch="master", dirpath="")
+        release, created = Release.objects.get_or_create(name="test release", bitbake_version = bbv)
+        Project.objects.create_project(name=AllProjectsViewTestCase.TEST_PROJECT_NAME, release=release)
+
+    def test_get_base_call_returns_html(self):
+        response = self.client.get(reverse('all-projects'), follow=True)
+        self.assertEqual(response.status_code, 200)
+        self.assertTrue(response['Content-Type'].startswith('text/html'))
+        self.assertTemplateUsed(response, "projects.html")
+        self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in response.content)
+
+    def test_get_json_call_returns_json(self):
+        response = self.client.get(reverse('all-projects'), {"format": "json"}, follow=True)
+        self.assertEqual(response.status_code, 200)
+        self.assertTrue(response['Content-Type'].startswith('application/json'))
+        try:
+            import json
+            data = json.loads(response.content)
+        except:
+            self.fail("Response %s is not json-loadable" % response.content)
+
+        self.assertTrue("list" in data)
+        self.assertTrue(AllProjectsViewTestCase.TEST_PROJECT_NAME in map(lambda x: x["name"], data["list"]))
+        self.assertTrue("id" in data["list"][0])
+        self.assertTrue("xhrProjectDataTypeaheadUrl" in data["list"][0])
+        self.assertTrue("projectPageUrl" in data["list"][0])
+        self.assertTrue("xhrProjectEditUrl" in data["list"][0])
+        self.assertTrue("projectBuildUrl" in data["list"][0])