diff options
author | Elliot Smith <elliot.smith@intel.com> | 2015-09-02 17:25:12 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-09-03 16:52:50 +0100 |
commit | bc6a1a23e3d1af3861288a7abdbc9d5010470204 (patch) | |
tree | 87efdb5e096458e67bd083bc276e6e73941eb2ff /bitbake | |
parent | 3b6d193cd7dc508d3285664b78b426fc5fd6e4a5 (diff) | |
download | poky-bc6a1a23e3d1af3861288a7abdbc9d5010470204.tar.gz |
bitbake: toaster: Add tests for pages which show the default project
Test that the correct landing page redirect is applied, depending
on the state of the default project.
Test that the default project is only shown on the /projects page
if it has at least one build.
[YOCTO #7932]
(Bitbake rev: 85a65d2b652c2ccc6cfb90fd8bc9048d0e72341e)
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/toaster/toastergui/tests.py | 115 |
1 files changed, 114 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 7acf4bc31d..1a8b4787dd 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py | |||
@@ -23,7 +23,8 @@ | |||
23 | 23 | ||
24 | from django.test import TestCase | 24 | from django.test import TestCase |
25 | from django.core.urlresolvers import reverse | 25 | from django.core.urlresolvers import reverse |
26 | from orm.models import Project, Release, BitbakeVersion | 26 | from django.utils import timezone |
27 | from orm.models import Project, Release, BitbakeVersion, Build | ||
27 | from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer | 28 | from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer |
28 | from orm.models import Layer_Version, Recipe, Machine, ProjectLayer | 29 | from orm.models import Layer_Version, Recipe, Machine, ProjectLayer |
29 | import json | 30 | import json |
@@ -179,3 +180,115 @@ class ViewTests(TestCase): | |||
179 | response = self.client.post(reverse('xhr_importlayer'), args) | 180 | response = self.client.post(reverse('xhr_importlayer'), args) |
180 | data = json.loads(response.content) | 181 | data = json.loads(response.content) |
181 | self.assertNotEqual(data["error"], "ok") | 182 | self.assertNotEqual(data["error"], "ok") |
183 | |||
184 | class LandingPageTests(TestCase): | ||
185 | """ Tests for redirects on the landing page """ | ||
186 | # disable bogus pylint message error: | ||
187 | # "Instance of 'WSGIRequest' has no 'url' member (no-member)" | ||
188 | # (see https://github.com/landscapeio/pylint-django/issues/42) | ||
189 | # pylint: disable=E1103 | ||
190 | |||
191 | LANDING_PAGE_TITLE = 'This is Toaster' | ||
192 | |||
193 | def setUp(self): | ||
194 | """ Add default project manually """ | ||
195 | self.project = Project.objects.create_project('foo', None) | ||
196 | self.project.is_default = True | ||
197 | self.project.save() | ||
198 | |||
199 | def test_only_default_project(self): | ||
200 | """ | ||
201 | No projects except default | ||
202 | => get the landing page | ||
203 | """ | ||
204 | response = self.client.get(reverse('landing')) | ||
205 | self.assertTrue(self.LANDING_PAGE_TITLE in response.content) | ||
206 | |||
207 | def test_default_project_has_build(self): | ||
208 | """ | ||
209 | Default project has a build, no other projects | ||
210 | => get the builds page | ||
211 | """ | ||
212 | now = timezone.now() | ||
213 | build = Build.objects.create(project=self.project, | ||
214 | started_on=now, | ||
215 | completed_on=now) | ||
216 | build.save() | ||
217 | |||
218 | response = self.client.get(reverse('landing')) | ||
219 | self.assertEqual(response.status_code, 302, | ||
220 | 'response should be a redirect') | ||
221 | self.assertTrue('/builds' in response.url, | ||
222 | 'should redirect to builds') | ||
223 | |||
224 | def test_user_project_exists(self): | ||
225 | """ | ||
226 | User has added a project (without builds) | ||
227 | => get the projects page | ||
228 | """ | ||
229 | user_project = Project.objects.create_project('foo', None) | ||
230 | user_project.save() | ||
231 | |||
232 | response = self.client.get(reverse('landing')) | ||
233 | self.assertEqual(response.status_code, 302, | ||
234 | 'response should be a redirect') | ||
235 | self.assertTrue('/projects' in response.url, | ||
236 | 'should redirect to projects') | ||
237 | |||
238 | def test_user_project_has_build(self): | ||
239 | """ | ||
240 | User has added a project (with builds) | ||
241 | => get the builds page | ||
242 | """ | ||
243 | user_project = Project.objects.create_project('foo', None) | ||
244 | user_project.save() | ||
245 | |||
246 | now = timezone.now() | ||
247 | build = Build.objects.create(project=user_project, | ||
248 | started_on=now, | ||
249 | completed_on=now) | ||
250 | build.save() | ||
251 | |||
252 | response = self.client.get(reverse('landing')) | ||
253 | self.assertEqual(response.status_code, 302, | ||
254 | 'response should be a redirect') | ||
255 | self.assertTrue('/builds' in response.url, | ||
256 | 'should redirect to builds') | ||
257 | |||
258 | class ProjectsPageTests(TestCase): | ||
259 | """ Tests for projects page """ | ||
260 | |||
261 | PROJECT_NAME = 'cli builds' | ||
262 | |||
263 | def setUp(self): | ||
264 | """ Add default project manually """ | ||
265 | project = Project.objects.create_project(self.PROJECT_NAME, None) | ||
266 | self.default_project = project | ||
267 | self.default_project.is_default = True | ||
268 | self.default_project.save() | ||
269 | |||
270 | def test_default_project_hidden(self): | ||
271 | """ The default project should be hidden if it has no builds """ | ||
272 | params = {"count": 10, "orderby": "updated:-", "page": 1} | ||
273 | response = self.client.get(reverse('all-projects'), params) | ||
274 | |||
275 | self.assertTrue(not('tr class="data"' in response.content), | ||
276 | 'should be no project rows in the page') | ||
277 | self.assertTrue(not(self.PROJECT_NAME in response.content), | ||
278 | 'default project "cli builds" should not be in page') | ||
279 | |||
280 | def test_default_project_has_build(self): | ||
281 | """ The default project should be shown if it has builds """ | ||
282 | now = timezone.now() | ||
283 | build = Build.objects.create(project=self.default_project, | ||
284 | started_on=now, | ||
285 | completed_on=now) | ||
286 | build.save() | ||
287 | |||
288 | params = {"count": 10, "orderby": "updated:-", "page": 1} | ||
289 | response = self.client.get(reverse('all-projects'), params) | ||
290 | |||
291 | self.assertTrue('tr class="data"' in response.content, | ||
292 | 'should be a project row in the page') | ||
293 | self.assertTrue(self.PROJECT_NAME in response.content, | ||
294 | 'default project "cli builds" should be in page') | ||