summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-10-28 18:48:42 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-11-04 12:50:55 +0000
commitd350276a86089a89c149e10d1e50e44ec6cb24d0 (patch)
tree1fad1d386f90f73ead9dc12631a08009cff91153 /bitbake/lib/toaster
parent7abab61cf4ef9c3b7f5b8085e96ac5187a10549c (diff)
downloadpoky-d350276a86089a89c149e10d1e50e44ec6cb24d0.tar.gz
bitbake: toaster: views Tests fix all pyflake identified issues
(Bitbake rev: f407acefcea5619c76fd7b413d6356efc93e63e8) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py95
1 files changed, 47 insertions, 48 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index 2b5894f743..c20b3fe0b6 100644
--- a/bitbake/lib/toaster/toastergui/tests.py
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -24,31 +24,26 @@
24from django.test import TestCase 24from django.test import TestCase
25from django.test.client import RequestFactory 25from django.test.client import RequestFactory
26from django.core.urlresolvers import reverse 26from django.core.urlresolvers import reverse
27from django.utils import timezone
28from django.db.models import Q 27from django.db.models import Q
29 28
30from orm.models import Project, Release, BitbakeVersion, Package, LogMessage 29from orm.models import Project, Package
31from orm.models import LayerSource, Layer, Build 30from orm.models import Layer_Version, Recipe
32from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target 31from orm.models import CustomImageRecipe
33from orm.models import CustomImageRecipe, ProjectVariable
34from orm.models import CustomImagePackage 32from orm.models import CustomImagePackage
35 33
36import toastermain
37import inspect 34import inspect
38import toastergui 35import toastergui
39 36
40from toastergui.tables import SoftwareRecipesTable 37from toastergui.tables import SoftwareRecipesTable
41import json 38import json
42from datetime import timedelta
43from bs4 import BeautifulSoup 39from bs4 import BeautifulSoup
44import re
45import string 40import string
46import json
47 41
48PROJECT_NAME = "test project" 42PROJECT_NAME = "test project"
49PROJECT_NAME2 = "test project 2" 43PROJECT_NAME2 = "test project 2"
50CLI_BUILDS_PROJECT_NAME = 'Command line builds' 44CLI_BUILDS_PROJECT_NAME = 'Command line builds'
51 45
46
52class ViewTests(TestCase): 47class ViewTests(TestCase):
53 """Tests to verify view APIs.""" 48 """Tests to verify view APIs."""
54 49
@@ -75,7 +70,8 @@ class ViewTests(TestCase):
75 url = reverse('all-projects') 70 url = reverse('all-projects')
76 response = self.client.get(url, {"format": "json"}, follow=True) 71 response = self.client.get(url, {"format": "json"}, follow=True)
77 self.assertEqual(response.status_code, 200) 72 self.assertEqual(response.status_code, 200)
78 self.assertTrue(response['Content-Type'].startswith('application/json')) 73 self.assertTrue(response['Content-Type'].startswith(
74 'application/json'))
79 75
80 data = json.loads(response.content.decode('utf-8')) 76 data = json.loads(response.content.decode('utf-8'))
81 77
@@ -98,13 +94,13 @@ class ViewTests(TestCase):
98 urls = [layers_url, 94 urls = [layers_url,
99 prj_url, 95 prj_url,
100 reverse('xhr_recipestypeahead', args=(self.project.id,)), 96 reverse('xhr_recipestypeahead', args=(self.project.id,)),
101 reverse('xhr_machinestypeahead', args=(self.project.id,)), 97 reverse('xhr_machinestypeahead', args=(self.project.id,))]
102 ]
103 98
104 def basic_reponse_check(response, url): 99 def basic_reponse_check(response, url):
105 """Check data structure of http response.""" 100 """Check data structure of http response."""
106 self.assertEqual(response.status_code, 200) 101 self.assertEqual(response.status_code, 200)
107 self.assertTrue(response['Content-Type'].startswith('application/json')) 102 self.assertTrue(response['Content-Type'].startswith(
103 'application/json'))
108 104
109 data = json.loads(response.content.decode('utf-8')) 105 data = json.loads(response.content.decode('utf-8'))
110 106
@@ -133,7 +129,6 @@ class ViewTests(TestCase):
133 129
134 return False 130 return False
135 131
136
137 for url in urls: 132 for url in urls:
138 results = False 133 results = False
139 134
@@ -149,31 +144,31 @@ class ViewTests(TestCase):
149 144
150 def test_xhr_import_layer(self): 145 def test_xhr_import_layer(self):
151 """Test xhr_importlayer API""" 146 """Test xhr_importlayer API"""
152 #Test for importing an already existing layer 147 # Test for importing an already existing layer
153 args = {'vcs_url' : "git://git.example.com/test", 148 args = {'vcs_url': "git://git.example.com/test",
154 'name' : "base-layer", 149 'name': "base-layer",
155 'git_ref': "c12b9596afd236116b25ce26dbe0d793de9dc7ce", 150 'git_ref': "c12b9596afd236116b25ce26dbe0d793de9dc7ce",
156 'project_id': self.project.id, 151 'project_id': self.project.id,
157 'local_source_dir': "", 152 'local_source_dir': "",
158 'dir_path' : "/path/in/repository"} 153 'dir_path': "/path/in/repository"}
159 response = self.client.post(reverse('xhr_importlayer'), args) 154 response = self.client.post(reverse('xhr_importlayer'), args)
160 data = json.loads(response.content.decode('utf-8')) 155 data = json.loads(response.content.decode('utf-8'))
161 self.assertEqual(response.status_code, 200) 156 self.assertEqual(response.status_code, 200)
162 self.assertEqual(data["error"], "ok") 157 self.assertEqual(data["error"], "ok")
163 158
164 #Test to verify import of a layer successful 159 # Test to verify import of a layer successful
165 args['name'] = "meta-oe" 160 args['name'] = "meta-oe"
166 response = self.client.post(reverse('xhr_importlayer'), args) 161 response = self.client.post(reverse('xhr_importlayer'), args)
167 data = json.loads(response.content.decode('utf-8')) 162 data = json.loads(response.content.decode('utf-8'))
168 self.assertTrue(data["error"], "ok") 163 self.assertTrue(data["error"], "ok")
169 164
170 #Test for html tag in the data 165 # Test for html tag in the data
171 args['<'] = "testing html tag" 166 args['<'] = "testing html tag"
172 response = self.client.post(reverse('xhr_importlayer'), args) 167 response = self.client.post(reverse('xhr_importlayer'), args)
173 data = json.loads(response.content.decode('utf-8')) 168 data = json.loads(response.content.decode('utf-8'))
174 self.assertNotEqual(data["error"], "ok") 169 self.assertNotEqual(data["error"], "ok")
175 170
176 #Empty data passed 171 # Empty data passed
177 args = {} 172 args = {}
178 response = self.client.post(reverse('xhr_importlayer'), args) 173 response = self.client.post(reverse('xhr_importlayer'), args)
179 data = json.loads(response.content.decode('utf-8')) 174 data = json.loads(response.content.decode('utf-8'))
@@ -232,15 +227,14 @@ class ViewTests(TestCase):
232 "info": {'id': self.customr.id, 227 "info": {'id': self.customr.id,
233 'name': self.customr.name, 228 'name': self.customr.name,
234 'base_recipe_id': self.recipe1.id, 229 'base_recipe_id': self.recipe1.id,
235 'project_id': self.project.id, 230 'project_id': self.project.id}}
236 } 231 self.assertEqual(json.loads(response.content.decode('utf-8')),
237 } 232 expected)
238 self.assertEqual(json.loads(response.content.decode('utf-8')), expected)
239 233
240 def test_xhr_custom_del(self): 234 def test_xhr_custom_del(self):
241 """Test deleting custom recipe""" 235 """Test deleting custom recipe"""
242 name = "to be deleted" 236 name = "to be deleted"
243 recipe = CustomImageRecipe.objects.create(\ 237 recipe = CustomImageRecipe.objects.create(
244 name=name, project=self.project, 238 name=name, project=self.project,
245 base_recipe=self.recipe1, 239 base_recipe=self.recipe1,
246 file_path="/tmp/testing", 240 file_path="/tmp/testing",
@@ -259,7 +253,8 @@ class ViewTests(TestCase):
259 url = reverse('xhr_customrecipe_id', args=(recipe.id,)) 253 url = reverse('xhr_customrecipe_id', args=(recipe.id,))
260 response = self.client.delete(url) 254 response = self.client.delete(url)
261 self.assertEqual(response.status_code, 200) 255 self.assertEqual(response.status_code, 200)
262 self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") 256 self.assertNotEqual(json.loads(
257 response.content.decode('utf-8'))["error"], "ok")
263 258
264 def test_xhr_custom_packages(self): 259 def test_xhr_custom_packages(self):
265 """Test adding and deleting package to a custom recipe""" 260 """Test adding and deleting package to a custom recipe"""
@@ -280,7 +275,8 @@ class ViewTests(TestCase):
280 275
281 response = self.client.delete(del_url) 276 response = self.client.delete(del_url)
282 self.assertEqual(response.status_code, 200) 277 self.assertEqual(response.status_code, 200)
283 self.assertEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) 278 self.assertEqual(json.loads(response.content.decode('utf-8')),
279 {"error": "ok"})
284 all_packages = self.customr.get_all_packages().values_list('pk', 280 all_packages = self.customr.get_all_packages().values_list('pk',
285 flat=True) 281 flat=True)
286 282
@@ -292,7 +288,8 @@ class ViewTests(TestCase):
292 288
293 response = self.client.delete(del_url) 289 response = self.client.delete(del_url)
294 self.assertEqual(response.status_code, 200) 290 self.assertEqual(response.status_code, 200)
295 self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") 291 self.assertNotEqual(json.loads(
292 response.content.decode('utf-8'))["error"], "ok")
296 293
297 def test_xhr_custom_packages_err(self): 294 def test_xhr_custom_packages_err(self):
298 """Test error conditions of xhr_customrecipe_packages""" 295 """Test error conditions of xhr_customrecipe_packages"""
@@ -303,8 +300,9 @@ class ViewTests(TestCase):
303 for method in (self.client.put, self.client.delete): 300 for method in (self.client.put, self.client.delete):
304 response = method(url) 301 response = method(url)
305 self.assertEqual(response.status_code, 200) 302 self.assertEqual(response.status_code, 200)
306 self.assertNotEqual(json.loads(response.content.decode('utf-8')), 303 self.assertNotEqual(json.loads(
307 {"error": "ok"}) 304 response.content.decode('utf-8')),
305 {"error": "ok"})
308 306
309 def test_download_custom_recipe(self): 307 def test_download_custom_recipe(self):
310 """Download the recipe file generated for the custom image""" 308 """Download the recipe file generated for the custom image"""
@@ -490,27 +488,28 @@ class ViewTests(TestCase):
490 # filter string to pass as the option 488 # filter string to pass as the option
491 # This is the name of the filter:action 489 # This is the name of the filter:action
492 # e.g. project_filter:not_in_project 490 # e.g. project_filter:not_in_project
493 filter_string = "%s:%s" % (column['filter_name'], 491 filter_string = "%s:%s" % (
494 filter_action['action_name']) 492 column['filter_name'],
493 filter_action['action_name'])
495 # Now get the data with the filter applied 494 # Now get the data with the filter applied
496 filtered_data = get_data(table_cls(), 495 filtered_data = get_data(table_cls(),
497 {"filter" : filter_string}) 496 {"filter": filter_string})
498 497
499 # date range filter actions can't specify the 498 # date range filter actions can't specify the
500 # number of results they return, so their count is 0 499 # number of results they return, so their count is 0
501 if filter_action['count'] != None: 500 if filter_action['count'] is not None:
502 self.assertEqual(len(filtered_data['rows']), 501 self.assertEqual(
503 int(filter_action['count']), 502 len(filtered_data['rows']),
504 "We added a table filter for %s but " 503 int(filter_action['count']),
505 "the number of rows returned was not " 504 "We added a table filter for %s but "
506 "what the filter info said there " 505 "the number of rows returned was not "
507 "would be" % name) 506 "what the filter info said there "
508 507 "would be" % name)
509 508
510 # Test search functionality on the table 509 # Test search functionality on the table
511 something_found = False 510 something_found = False
512 for search in list(string.ascii_letters): 511 for search in list(string.ascii_letters):
513 search_data = get_data(table_cls(), {'search' : search}) 512 search_data = get_data(table_cls(), {'search': search})
514 513
515 if len(search_data['rows']) > 0: 514 if len(search_data['rows']) > 0:
516 something_found = True 515 something_found = True
@@ -521,20 +520,20 @@ class ViewTests(TestCase):
521 " was found for the search of table %s" % name) 520 " was found for the search of table %s" % name)
522 521
523 # Test the limit functionality on the table 522 # Test the limit functionality on the table
524 limited_data = get_data(table_cls(), {'limit' : "1"}) 523 limited_data = get_data(table_cls(), {'limit': "1"})
525 self.assertEqual(len(limited_data['rows']), 524 self.assertEqual(len(limited_data['rows']),
526 1, 525 1,
527 "Limit 1 set on table %s but not 1 row returned" 526 "Limit 1 set on table %s but not 1 row returned"
528 % name) 527 % name)
529 528
530 # Test the pagination functionality on the table 529 # Test the pagination functionality on the table
531 page_one_data = get_data(table_cls(), {'limit' : "1", 530 page_one_data = get_data(table_cls(), {'limit': "1",
532 "page": "1"})['rows'][0] 531 "page": "1"})['rows'][0]
533 532
534 page_two_data = get_data(table_cls(), {'limit' : "1", 533 page_two_data = get_data(table_cls(), {'limit': "1",
535 "page": "2"})['rows'][0] 534 "page": "2"})['rows'][0]
536 535
537 self.assertNotEqual(page_one_data, 536 self.assertNotEqual(page_one_data,
538 page_two_data, 537 page_two_data,
539 "Changed page on table %s but first row is the " 538 "Changed page on table %s but first row is"
540 "same as the previous page" % name) 539 " the same as the previous page" % name)