launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #07206
[Merge] lp:~rvb/maas/views-bug-973215-4 into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/views-bug-973215-4 into lp:maas with lp:~rvb/maas/views-bug-973215-3 as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #973215 in MAAS: "src/maasserver/views.py is huge."
https://bugs.launchpad.net/maas/+bug/973215
For more details, see:
https://code.launchpad.net/~rvb/maas/views-bug-973215-4/+merge/103098
This branch is the third in a series of branches that will refactor src/maasserver/views.py into modules in src/maasserver/views/.
This branch follows up on the work done in https://code.launchpad.net/~rvb/maas/views-bug-973215-3/+merge/103079.
It moves combo views to src/maasserver/views/combo.py. It also moves the related tests in src/maasserver/tests/test_views_combo.py.
It also moves some tests I forgot which belong to src/maasserver/tests/test_views_nodes.py.
--
https://code.launchpad.net/~rvb/maas/views-bug-973215-4/+merge/103098
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/views-bug-973215-4 into lp:maas.
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py 2012-04-23 13:32:20 +0000
+++ src/maasserver/tests/test_views.py 2012-04-23 13:32:20 +0000
@@ -13,11 +13,9 @@
__all__ = []
import httplib
-import os
from urlparse import urlparse
from xmlrpclib import Fault
-from django.conf import settings
from django.conf.urls.defaults import patterns
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
@@ -26,16 +24,10 @@
from django.test.client import RequestFactory
from django.utils.html import escape
from lxml.html import fromstring
-from maasserver import (
- components,
- messages,
- )
+from maasserver import components
from maasserver.components import register_persistent_error
from maasserver.enum import NODE_AFTER_COMMISSIONING_ACTION
-from maasserver.exceptions import (
- ExternalComponentException,
- NoRabbit,
- )
+from maasserver.exceptions import ExternalComponentException
from maasserver.models import (
Config,
UserProfile,
@@ -50,16 +42,8 @@
LoggedInTestCase,
TestCase,
)
-from maasserver.views import (
- get_yui_location,
- HelpfulDeleteView,
- nodes as nodes_views,
- )
-from maasserver.views.nodes import (
- get_longpoll_context,
- NodeEdit,
- )
-from maastesting.rabbit import uses_rabbit_fixture
+from maasserver.views import HelpfulDeleteView
+from maasserver.views.nodes import NodeEdit
from provisioningserver.enum import (
POWER_TYPE_CHOICES,
PSERV_FAULT,
@@ -174,54 +158,6 @@
self.assertEqual("Invalid file type requested.", response.content)
-class TestUtilities(TestCase):
-
- def test_get_yui_location_if_static_root_is_none(self):
- self.patch(settings, 'STATIC_ROOT', None)
- yui_location = os.path.join(
- os.path.dirname(os.path.dirname(__file__)),
- 'static', 'jslibs', 'yui')
- self.assertEqual(yui_location, get_yui_location())
-
- def test_get_yui_location(self):
- static_root = factory.getRandomString()
- self.patch(settings, 'STATIC_ROOT', static_root)
- yui_location = os.path.join(static_root, 'jslibs', 'yui')
- self.assertEqual(yui_location, get_yui_location())
-
- def test_get_longpoll_context_empty_if_rabbitmq_publish_is_none(self):
- self.patch(settings, 'RABBITMQ_PUBLISH', None)
- self.patch(nodes_views, 'messaging', messages.get_messaging())
- self.assertEqual({}, get_longpoll_context())
-
- def test_get_longpoll_context_returns_empty_if_rabbit_not_running(self):
-
- class FakeMessaging:
- """Fake :class:`RabbitMessaging`: fail with `NoRabbit`."""
-
- def getQueue(self, *args, **kwargs):
- raise NoRabbit("Pretending not to have a rabbit.")
-
- self.patch(messages, 'messaging', FakeMessaging())
- self.assertEqual({}, get_longpoll_context())
-
- def test_get_longpoll_context_empty_if_longpoll_url_is_None(self):
- self.patch(settings, 'LONGPOLL_PATH', None)
- self.patch(nodes_views, 'messaging', messages.get_messaging())
- self.assertEqual({}, get_longpoll_context())
-
- @uses_rabbit_fixture
- def test_get_longpoll_context(self):
- longpoll = factory.getRandomString()
- self.patch(settings, 'LONGPOLL_PATH', longpoll)
- self.patch(settings, 'RABBITMQ_PUBLISH', True)
- self.patch(nodes_views, 'messaging', messages.get_messaging())
- context = get_longpoll_context()
- self.assertItemsEqual(
- ['LONGPOLL_PATH', 'longpoll_queue'], context)
- self.assertEqual(longpoll, context['LONGPOLL_PATH'])
-
-
class FakeDeletableModel:
"""A fake model class, with a delete method."""
=== added file 'src/maasserver/tests/test_views_combo.py'
--- src/maasserver/tests/test_views_combo.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_views_combo.py 2012-04-23 13:32:20 +0000
@@ -0,0 +1,36 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Test combo view."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = []
+
+import os
+
+from django.conf import settings
+from maasserver.testing.factory import factory
+from maasserver.testing.testcase import TestCase
+from maasserver.views.combo import get_yui_location
+
+
+class TestUtilities(TestCase):
+
+ def test_get_yui_location_if_static_root_is_none(self):
+ self.patch(settings, 'STATIC_ROOT', None)
+ yui_location = os.path.join(
+ os.path.dirname(os.path.dirname(__file__)),
+ 'static', 'jslibs', 'yui')
+ self.assertEqual(yui_location, get_yui_location())
+
+ def test_get_yui_location(self):
+ static_root = factory.getRandomString()
+ self.patch(settings, 'STATIC_ROOT', static_root)
+ yui_location = os.path.join(static_root, 'jslibs', 'yui')
+ self.assertEqual(yui_location, get_yui_location())
=== modified file 'src/maasserver/tests/test_views_nodes.py'
--- src/maasserver/tests/test_views_nodes.py 2012-04-23 13:32:20 +0000
+++ src/maasserver/tests/test_views_nodes.py 2012-04-23 13:32:20 +0000
@@ -14,12 +14,15 @@
import httplib
+from django.conf import settings
from django.core.urlresolvers import reverse
from lxml.html import fromstring
+from maasserver import messages
from maasserver.enum import (
NODE_AFTER_COMMISSIONING_ACTION,
NODE_STATUS,
)
+from maasserver.exceptions import NoRabbit
from maasserver.forms import NodeActionForm
from maasserver.models import Node
from maasserver.testing import (
@@ -28,7 +31,13 @@
)
from maasserver.testing.enum import map_enum
from maasserver.testing.factory import factory
-from maasserver.testing.testcase import LoggedInTestCase
+from maasserver.testing.testcase import (
+ LoggedInTestCase,
+ TestCase,
+ )
+from maasserver.views import nodes as nodes_views
+from maasserver.views.nodes import get_longpoll_context
+from maastesting.rabbit import uses_rabbit_fixture
class NodeViewsTest(LoggedInTestCase):
@@ -288,3 +297,38 @@
self.assertEqual(
["Node started."],
[message.message for message in response.context['messages']])
+
+
+class TestGetLongpollContext(TestCase):
+
+ def test_get_longpoll_context_empty_if_rabbitmq_publish_is_none(self):
+ self.patch(settings, 'RABBITMQ_PUBLISH', None)
+ self.patch(nodes_views, 'messaging', messages.get_messaging())
+ self.assertEqual({}, get_longpoll_context())
+
+ def test_get_longpoll_context_returns_empty_if_rabbit_not_running(self):
+
+ class FakeMessaging:
+ """Fake :class:`RabbitMessaging`: fail with `NoRabbit`."""
+
+ def getQueue(self, *args, **kwargs):
+ raise NoRabbit("Pretending not to have a rabbit.")
+
+ self.patch(messages, 'messaging', FakeMessaging())
+ self.assertEqual({}, get_longpoll_context())
+
+ def test_get_longpoll_context_empty_if_longpoll_url_is_None(self):
+ self.patch(settings, 'LONGPOLL_PATH', None)
+ self.patch(nodes_views, 'messaging', messages.get_messaging())
+ self.assertEqual({}, get_longpoll_context())
+
+ @uses_rabbit_fixture
+ def test_get_longpoll_context(self):
+ longpoll = factory.getRandomString()
+ self.patch(settings, 'LONGPOLL_PATH', longpoll)
+ self.patch(settings, 'RABBITMQ_PUBLISH', True)
+ self.patch(nodes_views, 'messaging', messages.get_messaging())
+ context = get_longpoll_context()
+ self.assertItemsEqual(
+ ['LONGPOLL_PATH', 'longpoll_queue'], context)
+ self.assertEqual(longpoll, context['LONGPOLL_PATH'])
=== modified file 'src/maasserver/urls.py'
--- src/maasserver/urls.py 2012-04-23 13:32:20 +0000
+++ src/maasserver/urls.py 2012-04-23 13:32:20 +0000
@@ -32,7 +32,6 @@
AccountsDelete,
AccountsEdit,
AccountsView,
- combo_view,
settings,
settings_add_archive,
)
@@ -40,6 +39,7 @@
login,
logout,
)
+from maasserver.views.combo import combo_view
from maasserver.views.nodes import (
NodeDelete,
NodeEdit,
=== modified file 'src/maasserver/views/__init__.py'
--- src/maasserver/views/__init__.py 2012-04-23 13:32:20 +0000
+++ src/maasserver/views/__init__.py 2012-04-23 13:32:20 +0000
@@ -15,7 +15,6 @@
"AccountsDelete",
"AccountsEdit",
"AccountsView",
- "combo_view",
"settings",
"settings_add_archive",
]
@@ -24,22 +23,13 @@
ABCMeta,
abstractmethod,
)
-import os
-from convoy.combo import (
- combine_files,
- parse_qs,
- )
-from django.conf import settings as django_settings
from django.contrib import messages
from django.contrib.auth.forms import AdminPasswordChangeForm
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.http import (
Http404,
- HttpResponse,
- HttpResponseBadRequest,
- HttpResponseNotFound,
HttpResponseRedirect,
)
from django.shortcuts import (
@@ -332,36 +322,3 @@
'maasserver/settings_add_archive.html',
{'form': form},
context_instance=RequestContext(request))
-
-
-def get_yui_location():
- if django_settings.STATIC_ROOT:
- return os.path.join(
- django_settings.STATIC_ROOT, 'jslibs', 'yui')
- else:
- return os.path.join(
- os.path.dirname(os.path.dirname(__file__)), 'static',
- 'jslibs', 'yui')
-
-
-def combo_view(request):
- """Handle a request for combining a set of files."""
- fnames = parse_qs(request.META.get("QUERY_STRING", ""))
- YUI_LOCATION = get_yui_location()
-
- if fnames:
- if fnames[0].endswith('.js'):
- content_type = 'text/javascript; charset=UTF-8'
- elif fnames[0].endswith('.css'):
- content_type = 'text/css'
- else:
- return HttpResponseBadRequest("Invalid file type requested.")
- content = b"".join(
- combine_files(
- fnames, YUI_LOCATION, resource_prefix='/',
- rewrite_urls=True))
-
- return HttpResponse(
- content_type=content_type, status=200, content=content)
-
- return HttpResponseNotFound()
=== added file 'src/maasserver/views/combo.py'
--- src/maasserver/views/combo.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/views/combo.py 2012-04-23 13:32:20 +0000
@@ -0,0 +1,61 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Combo view."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ 'combo_view',
+ ]
+
+import os
+
+from convoy.combo import (
+ combine_files,
+ parse_qs,
+ )
+from django.conf import settings as django_settings
+from django.http import (
+ HttpResponse,
+ HttpResponseBadRequest,
+ HttpResponseNotFound,
+ )
+
+
+def get_yui_location():
+ if django_settings.STATIC_ROOT:
+ return os.path.join(
+ django_settings.STATIC_ROOT, 'jslibs', 'yui')
+ else:
+ return os.path.join(
+ os.path.dirname(os.path.dirname(__file__)), 'static',
+ 'jslibs', 'yui')
+
+
+def combo_view(request):
+ """Handle a request for combining a set of files."""
+ fnames = parse_qs(request.META.get("QUERY_STRING", ""))
+ YUI_LOCATION = get_yui_location()
+
+ if fnames:
+ if fnames[0].endswith('.js'):
+ content_type = 'text/javascript; charset=UTF-8'
+ elif fnames[0].endswith('.css'):
+ content_type = 'text/css'
+ else:
+ return HttpResponseBadRequest("Invalid file type requested.")
+ content = b"".join(
+ combine_files(
+ fnames, YUI_LOCATION, resource_prefix='/',
+ rewrite_urls=True))
+
+ return HttpResponse(
+ content_type=content_type, status=200, content=content)
+
+ return HttpResponseNotFound()