aboutsummaryrefslogtreecommitdiffstats
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:58:25 +0100
commit9edd61fe7afaf273ed31d214af9251462182ad4f (patch)
treeedbea7b057a6427e11dd2aa22256c173853aa661
parent125d0e05805247450be0675e281a21bd6146d108 (diff)
downloadbitbake-9edd61fe7afaf273ed31d214af9251462182ad4f.tar.gz
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" Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
-rw-r--r--lib/toaster/toastergui/tests.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/toaster/toastergui/tests.py b/lib/toaster/toastergui/tests.py
new file mode 100644
index 000000000..8a78a41ca
--- /dev/null
+++ b/lib/toaster/toastergui/tests.py
@@ -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])