diff options
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') | ||