launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06628
[Merge] lp:~rvb/maas/maas-user-convoy into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/maas-user-convoy into lp:maas with lp:~rvb/maas/maas-convoy as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/maas-user-convoy/+merge/96407
This branch uses convoy to serve YUI files. It also fixes the YUI setting used in tests ('raw' instead of 'min').
The inclusion of the convoy package is still missing. I'll add it in a followup branch. This branch *should* be landed with its follow up branch.
--
https://code.launchpad.net/~rvb/maas/maas-user-convoy/+merge/96407
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-user-convoy into lp:maas.
=== modified file 'src/maas/settings.py'
--- src/maas/settings.py 2012-03-02 13:20:37 +0000
+++ src/maas/settings.py 2012-03-07 17:22:24 +0000
@@ -55,6 +55,7 @@
API_URL_REGEXP = '^/api/1[.]0/'
METADATA_URL_REGEXP = '^/metadata/'
+YUI_COMBO_URL = "combo/"
# We handle exceptions ourselves (in
# maasserver.middleware.APIErrorsMiddleware)
=== modified file 'src/maasserver/context_processors.py'
--- src/maasserver/context_processors.py 2012-03-05 16:27:03 +0000
+++ src/maasserver/context_processors.py 2012-03-07 17:22:24 +0000
@@ -21,6 +21,8 @@
return {
'YUI_DEBUG': settings.YUI_DEBUG,
'YUI_VERSION': settings.YUI_VERSION,
+ 'YUI_COMBO_URL': settings.YUI_COMBO_URL,
+ 'FORCE_SCRIPT_NAME': settings.FORCE_SCRIPT_NAME,
}
=== modified file 'src/maasserver/middleware.py'
--- src/maasserver/middleware.py 2012-03-02 17:52:27 +0000
+++ src/maasserver/middleware.py 2012-03-07 17:22:24 +0000
@@ -59,8 +59,10 @@
def __init__(self):
# URL prefixes that do not require authentication by Django.
public_url_roots = [
- # Login/logout pages: must be visible to anonymous users.
+ # Login page: must be visible to anonymous users.
reverse('login'),
+ # The combo loader is publicly accessible.
+ '^/' + settings.YUI_COMBO_URL,
# Static resources are publicly visible.
settings.STATIC_URL,
reverse('favicon'),
=== modified file 'src/maasserver/static/js/tests/test_node.html'
--- src/maasserver/static/js/tests/test_node.html 2012-02-03 14:39:50 +0000
+++ src/maasserver/static/js/tests/test_node.html 2012-03-07 17:22:24 +0000
@@ -4,7 +4,8 @@
<title>Test maas.node</title>
<!-- YUI and test setup -->
- <script type="text/javascript" src="../yui/tests/yui/yui-min.js"></script>
+ <script type="text/javascript" src="../testing/yui_test_conf.js"></script>
+ <script type="text/javascript" src="../../jslibs/yui/tests/build/yui/yui.js"></script>
<script type="text/javascript" src="../testing/testrunner.js"></script>
<!-- The module under test -->
<script type="text/javascript" src="../node.js"></script>
=== modified file 'src/maasserver/static/js/tests/test_node_add.html'
--- src/maasserver/static/js/tests/test_node_add.html 2012-02-24 17:37:01 +0000
+++ src/maasserver/static/js/tests/test_node_add.html 2012-03-07 17:22:24 +0000
@@ -4,7 +4,8 @@
<title>Test maas.node_add</title>
<!-- YUI and test setup -->
- <script type="text/javascript" src="../yui/tests/yui/yui-min.js"></script>
+ <script type="text/javascript" src="../testing/yui_test_conf.js"></script>
+ <script type="text/javascript" src="../../jslibs/yui/tests/build/yui/yui.js"></script>
<script type="text/javascript" src="../testing/testrunner.js"></script>
<script type="text/javascript" src="../testing/testing.js"></script>
<!-- The module under test -->
=== modified file 'src/maasserver/static/js/tests/test_node_views.html'
--- src/maasserver/static/js/tests/test_node_views.html 2012-02-24 17:37:01 +0000
+++ src/maasserver/static/js/tests/test_node_views.html 2012-03-07 17:22:24 +0000
@@ -4,7 +4,8 @@
<title>Test maas.node_views</title>
<!-- YUI and test setup -->
- <script type="text/javascript" src="../yui/tests/yui/yui-min.js"></script>
+ <script type="text/javascript" src="../testing/yui_test_conf.js"></script>
+ <script type="text/javascript" src="../../jslibs/yui/tests/build/yui/yui.js"></script>
<script type="text/javascript" src="../testing/testrunner.js"></script>
<script type="text/javascript" src="../testing/testing.js"></script>
<script type="text/javascript" src="../node.js"></script>
=== modified file 'src/maasserver/static/js/tests/test_prefs.html'
--- src/maasserver/static/js/tests/test_prefs.html 2012-03-05 03:19:36 +0000
+++ src/maasserver/static/js/tests/test_prefs.html 2012-03-07 17:22:24 +0000
@@ -4,7 +4,8 @@
<title>Test maas.prefs</title>
<!-- YUI and test setup -->
- <script type="text/javascript" src="../yui/tests/yui/yui.js"></script>
+ <script type="text/javascript" src="../testing/yui_test_conf.js"></script>
+ <script type="text/javascript" src="../../jslibs/yui/tests/build/yui/yui.js"></script>
<script type="text/javascript" src="../testing/testrunner.js"></script>
<script type="text/javascript" src="../testing/testing.js"></script>
<!-- The module under test -->
=== modified file 'src/maasserver/static/js/tests/test_user_panel.html'
--- src/maasserver/static/js/tests/test_user_panel.html 2012-02-21 05:50:08 +0000
+++ src/maasserver/static/js/tests/test_user_panel.html 2012-03-07 17:22:24 +0000
@@ -4,7 +4,8 @@
<title>Test maas.user_panel</title>
<!-- YUI and test setup -->
- <script type="text/javascript" src="../yui/tests/yui/yui-min.js"></script>
+ <script type="text/javascript" src="../testing/yui_test_conf.js"></script>
+ <script type="text/javascript" src="../../jslibs/yui/tests/build/yui/yui.js"></script>
<script type="text/javascript" src="../testing/testrunner.js"></script>
<script type="text/javascript" src="../testing/testing.js"></script>
<!-- The module under test -->
=== modified file 'src/maasserver/static/js/tests/test_utils.html'
--- src/maasserver/static/js/tests/test_utils.html 2012-03-06 12:31:34 +0000
+++ src/maasserver/static/js/tests/test_utils.html 2012-03-07 17:22:24 +0000
@@ -4,7 +4,8 @@
<title>Test maas.utils</title>
<!-- YUI and test setup -->
- <script type="text/javascript" src="../yui/tests/yui/yui.js"></script>
+ <script type="text/javascript" src="../testing/yui_test_conf.js"></script>
+ <script type="text/javascript" src="../../jslibs/yui/tests/build/yui/yui.js"></script>
<script type="text/javascript" src="../testing/testrunner.js"></script>
<script type="text/javascript" src="../testing/testing.js"></script>
<!-- The module under test -->
=== modified file 'src/maasserver/templates/maasserver/js-conf.html'
--- src/maasserver/templates/maasserver/js-conf.html 2012-03-06 12:31:34 +0000
+++ src/maasserver/templates/maasserver/js-conf.html 2012-03-07 17:22:24 +0000
@@ -2,8 +2,10 @@
<!--
var YUI_config = {
debug: {% if YUI_DEBUG %}true{% else %}false{% endif %},
- combine: {% if YUI_DEBUG %}true{% else %}false{% endif %},
- base: '{{ STATIC_URL }}js/yui/{{ YUI_VERSION }}/'
+ combine: true,
+ filter: {% if YUI_DEBUG %}'raw'{% else %}'min'{% endif %},
+ base: '{{ STATIC_URL }}jslibs/yui/{{ YUI_VERSION }}/build/',
+ comboBase: '{% if FORCE_SCRIPT_NAME %}{{ FORCE_SCRIPT_NAME }}{% endif%}/{{ YUI_COMBO_URL }}?',
};
var MaaS_config = {
uris: {
@@ -18,7 +20,7 @@
// -->
</script>
<script type="text/javascript"
- src="{{ STATIC_URL }}js/yui/{{ YUI_VERSION }}/yui-base/yui-base-min.js">
+ src="{{ STATIC_URL }}jslibs/yui/{{ YUI_VERSION }}/build/yui-base/yui-base-min.js">
</script>
<script type="text/javascript" src="{{ STATIC_URL }}js/user_panel.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/node_add.js"></script>
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py 2012-03-07 08:32:33 +0000
+++ src/maasserver/tests/test_views.py 2012-03-07 17:22:24 +0000
@@ -66,6 +66,47 @@
doc.cssselect('h2')])
+class TestComboLoaderView(TestCase):
+ """Test combo loader view."""
+
+ def test_load_js(self):
+ requested_files = [
+ 'tests/build/oop/oop.js',
+ 'tests/build/event-custom-base/event-custom-base.js'
+ ]
+ response = self.client.get('/combo/?%s' % '&'.join(requested_files))
+ self.assertIn('text/javascript', response['Content-Type'])
+ for requested_file in requested_files:
+ self.assertIn(requested_file, response.content)
+ # No sign of a missing js file.
+ self.assertNotIn("/* [missing] */", response.content)
+ # The file contains a link to YUI's licence.
+ self.assertIn('http://yuilibrary.com/license/', response.content)
+
+ def test_load_css(self):
+ requested_files = [
+ 'tests/build/widget-base/assets/skins/sam/widget-base.css',
+ 'tests/build/widget-stack/assets/skins/sam/widget-stack.css',
+ ]
+ response = self.client.get('/combo/?%s' % '&'.join(requested_files))
+ self.assertIn('text/css', response['Content-Type'])
+ for requested_file in requested_files:
+ self.assertIn(requested_file, response.content)
+ # No sign of a missing css file.
+ self.assertNotIn("/* [missing] */", response.content)
+ # The file contains a link to YUI's licence.
+ self.assertIn('http://yuilibrary.com/license/', response.content)
+
+ def test_combo_no_file_returns_not_found(self):
+ response = self.client.get('/combo/')
+ self.assertEqual(httplib.NOT_FOUND, response.status_code)
+
+ def test_combo_wrong_file_extension_returns_bad_request(self):
+ response = self.client.get('/combo/?file.wrongextension')
+ self.assertEqual(httplib.BAD_REQUEST, response.status_code)
+ self.assertEqual("Invalid file type requested.", response.content)
+
+
class UserPrefsViewTest(LoggedInTestCase):
def test_prefs_GET_profile(self):
=== modified file 'src/maasserver/urls.py'
--- src/maasserver/urls.py 2012-03-02 17:52:27 +0000
+++ src/maasserver/urls.py 2012-03-07 17:22:24 +0000
@@ -11,6 +11,7 @@
__metaclass__ = type
__all__ = []
+from django.conf import settings as django_settings
from django.conf.urls.defaults import (
include,
patterns,
@@ -28,13 +29,14 @@
AccountsDelete,
AccountsEdit,
AccountsView,
+ combo_view,
+ KeystoreView,
logout,
NodeListView,
NodesCreateView,
settings,
settings_add_archive,
userprefsview,
- KeystoreView,
)
@@ -45,6 +47,7 @@
# URLs accessible to anonymous users.
urlpatterns = patterns('maasserver.views',
+ url(r'^%s' % django_settings.YUI_COMBO_URL, combo_view, name='yui-combo'),
url(r'^accounts/login/$', login, name='login'),
url(
r'^robots\.txt$', direct_to_template,
=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py 2012-03-02 17:52:27 +0000
+++ src/maasserver/views.py 2012-03-07 17:22:24 +0000
@@ -15,12 +15,23 @@
"NodesCreateView",
]
+import os
+
+from convoy.combo import (
+ combine_files,
+ parse_qs,
+ )
from django.contrib import messages
from django.contrib.auth.forms import PasswordChangeForm as PasswordForm
from django.contrib.auth.models import User
from django.contrib.auth.views import logout as dj_logout
from django.core.urlresolvers import reverse
-from django.http import HttpResponseRedirect
+from django.http import (
+ HttpResponse,
+ HttpResponseBadRequest,
+ HttpResponseNotFound,
+ HttpResponseRedirect,
+ )
from django.shortcuts import (
get_object_or_404,
render_to_response,
@@ -45,8 +56,8 @@
)
from maasserver.models import (
Node,
+ SSHKeys,
UserProfile,
- SSHKeys,
)
@@ -258,3 +269,29 @@
'maasserver/settings_add_archive.html',
{'form': form},
context_instance=RequestContext(request))
+
+
+YUI_LOCATION = os.path.join(
+ 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", ""))
+
+ 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 = "".join(
+ line.decode('utf8') for line in combine_files(
+ fnames, YUI_LOCATION, resource_prefix='/',
+ rewrite_urls=True))
+
+ return HttpResponse(
+ content_type=content_type, status=200, content=content)
+
+ return HttpResponseNotFound()
=== modified file 'templates/test_module.html'
--- templates/test_module.html 2012-02-24 17:37:01 +0000
+++ templates/test_module.html 2012-03-07 17:22:24 +0000
@@ -4,7 +4,8 @@
<title>Test maas.sample</title>
<!-- YUI and test setup -->
- <script type="text/javascript" src="../yui/tests/yui/yui-min.js"></script>
+ <script type="text/javascript" src="../testing/yui_test_conf.js"></script>
+ <script type="text/javascript" src="../../jslibs/yui/tests/build/yui/yui.js"></script>
<script type="text/javascript" src="../testing/testrunner.js"></script>
<script type="text/javascript" src="../testing/testing.js"></script>
<script type="text/javascript" src="../node.js"></script>
Follow ups