Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 0CA18E00E33; Fri, 21 Oct 2016 10:08:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-HAM-Report: * 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source * [209.85.192.179 listed in dnsbl.sorbs.net] * -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no * trust * [209.85.192.179 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-pf0-f179.google.com (mail-pf0-f179.google.com [209.85.192.179]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id C37B0E00E1E for ; Fri, 21 Oct 2016 10:07:57 -0700 (PDT) Received: by mail-pf0-f179.google.com with SMTP id 128so60032463pfz.0 for ; Fri, 21 Oct 2016 10:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qcqCawFSASr2T/ftI/kJRuG/VT0DFiARZuXxcB2a+No=; b=Rr5QZv63+4/IoLWkWx3UV0SmnCKqI8vDmFd5bZv2zSQxjZSLJPMqJ4bItsnSnv/lm2 c/pJHaFY1A4u09wQgzlx++RjwmdELpdaNtBItbvjrkh+5VBIeLdxoRJV6Osf2yQAxx8v B/QYzJ+Joz+7ljQDQ/4HyxaouYjb7xpkNf8c8C38/pQttRm6uE6kicQpRbw+IaIFdf5d 9tzUf5EIRgN4J5v7RDZWUfxVeUtO6PqnbN1NqcVcKubDm17iWL9U/jWQQ4ZC+4PSwAxK BURpotaZdtCq807BHkA7Dvkq2WCwsXvqo6ghpN4n75U/XOXCTVDyUrzMYP1N4ego/E2L k7eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qcqCawFSASr2T/ftI/kJRuG/VT0DFiARZuXxcB2a+No=; b=ZmzyjgwnSC9+hsqvnZh2CVD6tMBIi6xsdUmbyOPQMaWyUEjQtUoaJw30G4TgblxydW a3TgCW+IjW/2pLbBN2r+/BNJMiTWDlAbBRb5a5u2d799c5Rg4Mqds+RRP0B451qNAoyP 6E0naEv4zEV3PoRi9zbxlQnDk9OUB/k0EtpLKivaE5e22aBBmN63riGEx4VlRjPnutUx xlXgCfLYmWTYqxlRowsyzlWaSu8PXYBls2px2cKjTybWtJImQWHIuXsDzsN78gr3h27f pDs46kLSfwoZzMEG2qd6QmcVfYqShv2EsVKpdgYbOEt/Sr5KwUDeAv4sm5JbcULDx+wo TS8w== X-Gm-Message-State: ABUngvcGmq4SpRJ6mu6hhwNIdFNrLqEwGKhkVypMzKZgjy+pPiY5v81WUCcH41FCFeRYd6ZT X-Received: by 10.98.58.73 with SMTP id h70mr3370246pfa.138.1477069676914; Fri, 21 Oct 2016 10:07:56 -0700 (PDT) Received: from orion.ger.corp.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by smtp.gmail.com with ESMTPSA id v10sm6514350pag.44.2016.10.21.10.07.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Oct 2016 10:07:56 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Fri, 21 Oct 2016 18:07:39 +0100 Message-Id: <1477069666-25701-2-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477069666-25701-1-git-send-email-michael.g.wood@intel.com> References: <1477069666-25701-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 1/8] toaster: views Tests fix all pyflake identified issues X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2016 17:08:00 -0000 Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/tests.py | 95 ++++++++++++++++----------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 2b5894f..c20b3fe 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py @@ -24,31 +24,26 @@ from django.test import TestCase from django.test.client import RequestFactory from django.core.urlresolvers import reverse -from django.utils import timezone from django.db.models import Q -from orm.models import Project, Release, BitbakeVersion, Package, LogMessage -from orm.models import LayerSource, Layer, Build -from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target -from orm.models import CustomImageRecipe, ProjectVariable +from orm.models import Project, Package +from orm.models import Layer_Version, Recipe +from orm.models import CustomImageRecipe from orm.models import CustomImagePackage -import toastermain import inspect import toastergui from toastergui.tables import SoftwareRecipesTable import json -from datetime import timedelta from bs4 import BeautifulSoup -import re import string -import json PROJECT_NAME = "test project" PROJECT_NAME2 = "test project 2" CLI_BUILDS_PROJECT_NAME = 'Command line builds' + class ViewTests(TestCase): """Tests to verify view APIs.""" @@ -75,7 +70,8 @@ class ViewTests(TestCase): url = reverse('all-projects') response = self.client.get(url, {"format": "json"}, follow=True) self.assertEqual(response.status_code, 200) - self.assertTrue(response['Content-Type'].startswith('application/json')) + self.assertTrue(response['Content-Type'].startswith( + 'application/json')) data = json.loads(response.content.decode('utf-8')) @@ -98,13 +94,13 @@ class ViewTests(TestCase): urls = [layers_url, prj_url, reverse('xhr_recipestypeahead', args=(self.project.id,)), - reverse('xhr_machinestypeahead', args=(self.project.id,)), - ] + reverse('xhr_machinestypeahead', args=(self.project.id,))] def basic_reponse_check(response, url): """Check data structure of http response.""" self.assertEqual(response.status_code, 200) - self.assertTrue(response['Content-Type'].startswith('application/json')) + self.assertTrue(response['Content-Type'].startswith( + 'application/json')) data = json.loads(response.content.decode('utf-8')) @@ -133,7 +129,6 @@ class ViewTests(TestCase): return False - for url in urls: results = False @@ -149,31 +144,31 @@ class ViewTests(TestCase): def test_xhr_import_layer(self): """Test xhr_importlayer API""" - #Test for importing an already existing layer - args = {'vcs_url' : "git://git.example.com/test", - 'name' : "base-layer", + # Test for importing an already existing layer + args = {'vcs_url': "git://git.example.com/test", + 'name': "base-layer", 'git_ref': "c12b9596afd236116b25ce26dbe0d793de9dc7ce", 'project_id': self.project.id, 'local_source_dir': "", - 'dir_path' : "/path/in/repository"} + 'dir_path': "/path/in/repository"} response = self.client.post(reverse('xhr_importlayer'), args) data = json.loads(response.content.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(data["error"], "ok") - #Test to verify import of a layer successful + # Test to verify import of a layer successful args['name'] = "meta-oe" response = self.client.post(reverse('xhr_importlayer'), args) data = json.loads(response.content.decode('utf-8')) self.assertTrue(data["error"], "ok") - #Test for html tag in the data + # Test for html tag in the data args['<'] = "testing html tag" response = self.client.post(reverse('xhr_importlayer'), args) data = json.loads(response.content.decode('utf-8')) self.assertNotEqual(data["error"], "ok") - #Empty data passed + # Empty data passed args = {} response = self.client.post(reverse('xhr_importlayer'), args) data = json.loads(response.content.decode('utf-8')) @@ -232,15 +227,14 @@ class ViewTests(TestCase): "info": {'id': self.customr.id, 'name': self.customr.name, 'base_recipe_id': self.recipe1.id, - 'project_id': self.project.id, - } - } - self.assertEqual(json.loads(response.content.decode('utf-8')), expected) + 'project_id': self.project.id}} + self.assertEqual(json.loads(response.content.decode('utf-8')), + expected) def test_xhr_custom_del(self): """Test deleting custom recipe""" name = "to be deleted" - recipe = CustomImageRecipe.objects.create(\ + recipe = CustomImageRecipe.objects.create( name=name, project=self.project, base_recipe=self.recipe1, file_path="/tmp/testing", @@ -259,7 +253,8 @@ class ViewTests(TestCase): url = reverse('xhr_customrecipe_id', args=(recipe.id,)) response = self.client.delete(url) self.assertEqual(response.status_code, 200) - self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") + self.assertNotEqual(json.loads( + response.content.decode('utf-8'))["error"], "ok") def test_xhr_custom_packages(self): """Test adding and deleting package to a custom recipe""" @@ -280,7 +275,8 @@ class ViewTests(TestCase): response = self.client.delete(del_url) self.assertEqual(response.status_code, 200) - self.assertEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) + self.assertEqual(json.loads(response.content.decode('utf-8')), + {"error": "ok"}) all_packages = self.customr.get_all_packages().values_list('pk', flat=True) @@ -292,7 +288,8 @@ class ViewTests(TestCase): response = self.client.delete(del_url) self.assertEqual(response.status_code, 200) - self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") + self.assertNotEqual(json.loads( + response.content.decode('utf-8'))["error"], "ok") def test_xhr_custom_packages_err(self): """Test error conditions of xhr_customrecipe_packages""" @@ -303,8 +300,9 @@ class ViewTests(TestCase): for method in (self.client.put, self.client.delete): response = method(url) self.assertEqual(response.status_code, 200) - self.assertNotEqual(json.loads(response.content.decode('utf-8')), - {"error": "ok"}) + self.assertNotEqual(json.loads( + response.content.decode('utf-8')), + {"error": "ok"}) def test_download_custom_recipe(self): """Download the recipe file generated for the custom image""" @@ -490,27 +488,28 @@ class ViewTests(TestCase): # filter string to pass as the option # This is the name of the filter:action # e.g. project_filter:not_in_project - filter_string = "%s:%s" % (column['filter_name'], - filter_action['action_name']) + filter_string = "%s:%s" % ( + column['filter_name'], + filter_action['action_name']) # Now get the data with the filter applied filtered_data = get_data(table_cls(), - {"filter" : filter_string}) + {"filter": filter_string}) # date range filter actions can't specify the # number of results they return, so their count is 0 - if filter_action['count'] != None: - self.assertEqual(len(filtered_data['rows']), - int(filter_action['count']), - "We added a table filter for %s but " - "the number of rows returned was not " - "what the filter info said there " - "would be" % name) - + if filter_action['count'] is not None: + self.assertEqual( + len(filtered_data['rows']), + int(filter_action['count']), + "We added a table filter for %s but " + "the number of rows returned was not " + "what the filter info said there " + "would be" % name) # Test search functionality on the table something_found = False for search in list(string.ascii_letters): - search_data = get_data(table_cls(), {'search' : search}) + search_data = get_data(table_cls(), {'search': search}) if len(search_data['rows']) > 0: something_found = True @@ -521,20 +520,20 @@ class ViewTests(TestCase): " was found for the search of table %s" % name) # Test the limit functionality on the table - limited_data = get_data(table_cls(), {'limit' : "1"}) + limited_data = get_data(table_cls(), {'limit': "1"}) self.assertEqual(len(limited_data['rows']), 1, "Limit 1 set on table %s but not 1 row returned" % name) # Test the pagination functionality on the table - page_one_data = get_data(table_cls(), {'limit' : "1", + page_one_data = get_data(table_cls(), {'limit': "1", "page": "1"})['rows'][0] - page_two_data = get_data(table_cls(), {'limit' : "1", + page_two_data = get_data(table_cls(), {'limit': "1", "page": "2"})['rows'][0] self.assertNotEqual(page_one_data, page_two_data, - "Changed page on table %s but first row is the " - "same as the previous page" % name) + "Changed page on table %s but first row is" + " the same as the previous page" % name) -- 2.7.4