summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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])