Enable H302 check

This patch replaces some method imports with module imports and
makes H302 test enabled.

Fixes bug 1188531

Change-Id: Ibfbddeaa19cbbb244da58ffd5c918c41f03a0c65
This commit is contained in:
Tatiana Mazur 2013-08-02 13:23:46 +04:00
parent b255470a4e
commit 38943c7295
14 changed files with 85 additions and 93 deletions

View File

@ -14,9 +14,9 @@
import logging
from django.conf import settings
from django.conf import settings # noqa
from heatclient import client as heat_client
from openstack_dashboard.api.base import url_for
from openstack_dashboard.api import base
LOG = logging.getLogger(__name__)
@ -32,7 +32,7 @@ def format_parameters(params):
def heatclient(request, password=None):
api_version = "1"
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
endpoint = url_for(request, 'orchestration')
endpoint = base.url_for(request, 'orchestration')
LOG.debug('heatclient connection created using token "%s" and url "%s"' %
(request.user.token.id, endpoint))
kwargs = {

View File

@ -1,15 +1,10 @@
import json
import logging
from openstack_dashboard.api.heat import resources_list
from openstack_dashboard.api.heat import stack_get
from openstack_dashboard.api import heat
from openstack_dashboard.dashboards.project.stacks.mappings \
import get_resource_image
from openstack_dashboard.dashboards.project.stacks.mappings \
import get_resource_status
from openstack_dashboard.dashboards.project.stacks.sro import resource_info
from openstack_dashboard.dashboards.project.stacks.sro import stack_info
from openstack_dashboard.dashboards.project.stacks import mappings
from openstack_dashboard.dashboards.project.stacks import sro
LOG = logging.getLogger(__name__)
@ -21,7 +16,7 @@ class Stack(object):
def d3_data(request, stack_id=''):
try:
stack = stack_get(request, stack_id)
stack = heat.stack_get(request, stack_id)
except Exception:
stack = Stack()
stack.id = stack_id
@ -30,13 +25,13 @@ def d3_data(request, stack_id=''):
stack.stack_status_reason = 'DELETE_COMPLETE'
try:
resources = resources_list(request, stack.stack_name)
resources = heat.resources_list(request, stack.stack_name)
except Exception:
resources = []
d3_data = {"nodes": [], "stack": {}}
if stack:
stack_image = get_resource_image(stack.stack_status, 'stack')
stack_image = mappings.get_resource_image(stack.stack_status, 'stack')
stack_node = {
'stack_id': stack.id,
'name': stack.stack_name,
@ -47,17 +42,20 @@ def d3_data(request, stack_id=''):
'image_y': -30,
'text_x': 40,
'text_y': ".35em",
'in_progress': True if (get_resource_status(stack.stack_status) ==
'in_progress': True if (mappings.get_resource_status(
stack.stack_status) ==
'IN_PROGRESS') else False,
'info_box': stack_info(stack, stack_image)
'info_box': sro.stack_info(stack, stack_image)
}
d3_data['stack'] = stack_node
if resources:
for resource in resources:
resource_image = get_resource_image(resource.resource_status,
resource_image = mappings.get_resource_image(
resource.resource_status,
resource.resource_type)
resource_status = get_resource_status(resource.resource_status)
resource_status = mappings.get_resource_status(
resource.resource_status)
if resource_status in ('IN_PROGRESS', 'INIT'):
in_progress = True
else:
@ -73,7 +71,7 @@ def d3_data(request, stack_id=''):
'text_x': 35,
'text_y': ".35em",
'in_progress': in_progress,
'info_box': resource_info(resource)
'info_box': sro.resource_info(resource)
}
d3_data['nodes'].append(resource_node)
return json.dumps(d3_data)

View File

@ -16,8 +16,8 @@ import json
import logging
import re
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.debug import sensitive_variables
from django.utils.translation import ugettext_lazy as _ # noqa
from django.views.decorators.debug import sensitive_variables # noqa
from horizon import exceptions
from horizon import forms

View File

@ -17,10 +17,10 @@ import logging
import re
import urlparse
from django.core.urlresolvers import reverse
from django.template.defaultfilters import register
from django.core.urlresolvers import reverse # noqa
from django.template.defaultfilters import register # noqa
from openstack_dashboard.api.swift import FOLDER_DELIMITER
from openstack_dashboard.api.swift import FOLDER_DELIMITER # noqa
LOG = logging.getLogger(__name__)

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _ # noqa
import horizon

View File

@ -1,7 +1,7 @@
from django.template.defaultfilters import title
from django.template.loader import render_to_string
from django.template.defaultfilters import title # noqa
from django.template.loader import render_to_string # noqa
from horizon.utils.filters import replace_underscores
from horizon.utils.filters import replace_underscores # noqa
def stack_info(stack, stack_image):

View File

@ -14,15 +14,15 @@
import logging
from django.http import Http404
from django.template.defaultfilters import timesince
from django.template.defaultfilters import title
from django.utils.translation import ugettext_lazy as _
from django.http import Http404 # noqa
from django.template.defaultfilters import timesince # noqa
from django.template.defaultfilters import title # noqa
from django.utils.translation import ugettext_lazy as _ # noqa
from horizon import messages
from horizon import tables
from horizon.utils.filters import parse_isotime
from horizon.utils.filters import replace_underscores
from horizon.utils.filters import parse_isotime # noqa
from horizon.utils.filters import replace_underscores # noqa
from heatclient import exc

View File

@ -14,15 +14,16 @@
import logging
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _ # noqa
from horizon import messages
from horizon import tabs
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.stacks.api import d3_data
from openstack_dashboard.dashboards.project.stacks.tables import EventsTable
from openstack_dashboard.dashboards.project.stacks.tables import ResourcesTable
from openstack_dashboard.dashboards.project.stacks \
import api as project_api
from openstack_dashboard.dashboards.project.stacks \
import tables as project_tables
LOG = logging.getLogger(__name__)
@ -38,7 +39,7 @@ class StackTopologyTab(tabs.Tab):
context = {}
stack = self.tab_group.kwargs['stack']
context['stack_id'] = stack.id
context['d3_data'] = d3_data(request, stack_id=stack.id)
context['d3_data'] = project_api.d3_data(request, stack_id=stack.id)
return context
@ -79,7 +80,7 @@ class StackEventsTab(tabs.Tab):
messages.error(request, _(
'Unable to get events for stack "%s".') % stack.stack_name)
return {"stack": stack,
"table": EventsTable(request, data=events), }
"table": project_tables.EventsTable(request, data=events), }
class StackResourcesTab(tabs.Tab):
@ -99,7 +100,7 @@ class StackResourcesTab(tabs.Tab):
messages.error(request, _(
'Unable to get resources for stack "%s".') % stack.stack_name)
return {"stack": stack,
"table": ResourcesTable(
"table": project_tables.ResourcesTable(
request, data=resources, stack=stack), }

View File

@ -14,10 +14,10 @@
import json
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse # noqa
from django import http
from mox import IsA
from mox import IsA # noqa
from openstack_dashboard import api
from openstack_dashboard.test import helpers as test

View File

@ -12,27 +12,22 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls.defaults import patterns
from django.conf.urls.defaults import url
from django.conf.urls.defaults import patterns # noqa
from django.conf.urls.defaults import url # noqa
from openstack_dashboard.dashboards.project.stacks.views import CreateStackView
from openstack_dashboard.dashboards.project.stacks.views import DetailView
from openstack_dashboard.dashboards.project.stacks.views import IndexView
from openstack_dashboard.dashboards.project.stacks.views import JSONView
from openstack_dashboard.dashboards.project.stacks.views import ResourceView
from openstack_dashboard.dashboards.project.stacks.views \
import SelectTemplateView
from openstack_dashboard.dashboards.project.stacks import views
urlpatterns = patterns(
'',
url(r'^$', IndexView.as_view(), name='index'),
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^select_template$',
SelectTemplateView.as_view(),
views.SelectTemplateView.as_view(),
name='select_template'),
url(r'^launch$', CreateStackView.as_view(), name='launch'),
url(r'^stack/(?P<stack_id>[^/]+)/$', DetailView.as_view(), name='detail'),
url(r'^launch$', views.CreateStackView.as_view(), name='launch'),
url(r'^stack/(?P<stack_id>[^/]+)/$',
views.DetailView.as_view(), name='detail'),
url(r'^stack/(?P<stack_id>[^/]+)/(?P<resource_name>[^/]+)/$',
ResourceView.as_view(), name='resource'),
views.ResourceView.as_view(), name='resource'),
url(r'^get_d3_data/(?P<stack_id>[^/]+)/$',
JSONView.as_view(), name='d3_data'),
views.JSONView.as_view(), name='d3_data'),
)

View File

@ -20,28 +20,29 @@ from horizon import forms
from horizon import tables
from horizon import tabs
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse # noqa
from django.core.urlresolvers import reverse_lazy # noqa
from django.http import HttpResponse # noqa
from django.utils.translation import ugettext_lazy as _ # noqa
from django.views import generic
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.stacks.api import d3_data
from openstack_dashboard.dashboards.project.stacks.forms import StackCreateForm
from openstack_dashboard.dashboards.project.stacks.forms import TemplateForm
from openstack_dashboard.dashboards.project.stacks.tables import StacksTable
from openstack_dashboard.dashboards.project.stacks.tabs \
import ResourceDetailTabs
from openstack_dashboard.dashboards.project.stacks.tabs import StackDetailTabs
from openstack_dashboard.dashboards.project.stacks \
import api as project_api
from openstack_dashboard.dashboards.project.stacks \
import forms as project_forms
from openstack_dashboard.dashboards.project.stacks \
import tables as project_tables
from openstack_dashboard.dashboards.project.stacks \
import tabs as project_tabs
LOG = logging.getLogger(__name__)
class IndexView(tables.DataTableView):
table_class = StacksTable
table_class = project_tables.StacksTable
template_name = 'project/stacks/index.html'
def get_data(self):
@ -55,7 +56,7 @@ class IndexView(tables.DataTableView):
class SelectTemplateView(forms.ModalFormView):
form_class = TemplateForm
form_class = project_forms.TemplateForm
template_name = 'project/stacks/select_template.html'
success_url = reverse_lazy('horizon:project:stacks:launch')
@ -66,7 +67,7 @@ class SelectTemplateView(forms.ModalFormView):
class CreateStackView(forms.ModalFormView):
form_class = StackCreateForm
form_class = project_forms.StackCreateForm
template_name = 'project/stacks/create.html'
success_url = reverse_lazy('horizon:project:stacks:index')
@ -91,7 +92,7 @@ class CreateStackView(forms.ModalFormView):
class DetailView(tabs.TabView):
tab_group_class = StackDetailTabs
tab_group_class = project_tabs.StackDetailTabs
template_name = 'project/stacks/detail.html'
def get_context_data(self, **kwargs):
@ -119,7 +120,7 @@ class DetailView(tabs.TabView):
class ResourceView(tabs.TabView):
tab_group_class = ResourceDetailTabs
tab_group_class = project_tabs.ResourceDetailTabs
template_name = 'project/stacks/resource.html'
def get_context_data(self, **kwargs):
@ -165,5 +166,5 @@ class ResourceView(tabs.TabView):
class JSONView(generic.View):
def get(self, request, stack_id=''):
return HttpResponse(d3_data(request, stack_id=stack_id),
return HttpResponse(project_api.d3_data(request, stack_id=stack_id),
content_type="application/json")

View File

@ -18,16 +18,16 @@
# License for the specific language governing permissions and limitations
# under the License.
from functools import wraps
from functools import wraps # noqa
import os
from django.conf import settings
from django.contrib.auth.middleware import AuthenticationMiddleware
from django.contrib.messages.storage import default_storage
from django.conf import settings # noqa
from django.contrib.auth.middleware import AuthenticationMiddleware # noqa
from django.contrib.messages.storage import default_storage # noqa
from django.core.handlers import wsgi
from django import http
from django.test.client import RequestFactory
from django.utils.importlib import import_module
from django.test.client import RequestFactory # noqa
from django.utils.importlib import import_module # noqa
from django.utils import unittest
from cinderclient import client as cinder_client
@ -49,7 +49,7 @@ from horizon.test import helpers as horizon_helpers
from openstack_dashboard import api
from openstack_dashboard import context_processors
from openstack_dashboard.test.test_data.utils import load_test_data
from openstack_dashboard.test.test_data.utils import load_test_data # noqa
# Makes output of failing mox tests much easier to read.

View File

@ -1,13 +1,11 @@
import os
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _ # noqa
from horizon.test.settings import * # noqa
from horizon.utils.secret_key import generate_or_read_from_file
from horizon.utils.secret_key import generate_or_read_from_file # noqa
from openstack_dashboard.exceptions import NOT_FOUND
from openstack_dashboard.exceptions import RECOVERABLE
from openstack_dashboard.exceptions import UNAUTHORIZED
from openstack_dashboard import exceptions
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
@ -54,9 +52,9 @@ HORIZON_CONFIG = {
},
'user_home': None,
'help_url': "http://docs.openstack.org",
'exceptions': {'recoverable': RECOVERABLE,
'not_found': NOT_FOUND,
'unauthorized': UNAUTHORIZED},
'exceptions': {'recoverable': exceptions.RECOVERABLE,
'not_found': exceptions.NOT_FOUND,
'unauthorized': exceptions.UNAUTHORIZED},
}
# Set to True to allow users to upload images to glance via Horizon server.

View File

@ -39,8 +39,7 @@ exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,p
# F403 'from <smth> import *' used; unable to detect undefined names
# F999 syntax error in doctest
# H102 Apache 2.0 license header not found
# H302 import only modules.'from optparse import make_option' does not import a module
# H4xx docstrings
# H701 empty localization string
# H702 Formatting operation should be outside of localization method call
ignore = E121,E126,E127,E128,F403,F999,H102,H302,H4,H701,H702
# H702 Formatting operation should be outside of localization method call
ignore = E121,E126,E127,E128,F403,F999,H102,H4,H701,H702