Merge ~ack/maas:offline-docs-append-html into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 8de5d455ca2823731d743f9aaa2e54c3711b0554
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:offline-docs-append-html
Merge into: maas:master
Diff against target: 89 lines (+47/-5)
2 files modified
src/maasserver/tests/test_webapp.py (+41/-5)
src/maasserver/webapp.py (+6/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
Adam Collard (community) Approve
Review via email: mp+392591@code.launchpad.net

Commit message

LP: #1898679 - serve the file with ".html" extension if resource without extension is requested

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) wrote :

Can you add a test for a missing image or other static (non-html) resource>

Revision history for this message
Adam Collard (adam-collard) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b offline-docs-append-html lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 0ec05f4604d405fb724ff0cf54e283d872e726d0

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b offline-docs-append-html lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8540/console
COMMIT: 8de5d455ca2823731d743f9aaa2e54c3711b0554

review: Needs Fixing

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/tests/test_webapp.py b/src/maasserver/tests/test_webapp.py
2index 04121d2..3edc12a 100644
3--- a/src/maasserver/tests/test_webapp.py
4+++ b/src/maasserver/tests/test_webapp.py
5@@ -1,11 +1,8 @@
6 # Copyright 2014-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9-# TODO: Description here.
10-"""..."""
11-
12-__all__ = []
13
14+from pathlib import Path
15 import random
16 from unittest.mock import sentinel
17
18@@ -20,14 +17,53 @@ from twisted.web.test.requesthelper import DummyChannel, DummyRequest
19
20 from maasserver import eventloop, webapp
21 from maasserver.testing.listener import FakePostgresListenerService
22-from maasserver.webapp import OverlaySite
23+from maasserver.webapp import DocsFallbackFile, OverlaySite
24 from maasserver.websockets.protocol import WebSocketFactory
25 from maastesting.factory import factory
26+from maastesting.fixtures import TempDirectory
27 from maastesting.matchers import MockCalledOnceWith
28 from maastesting.testcase import MAASTestCase
29 from provisioningserver.utils.twisted import reducedWebLogFormatter
30
31
32+class TestDocsFallbackFile(MAASTestCase):
33+ def setUp(self):
34+ super().setUp()
35+ self.base_dir = self.useFixture(TempDirectory())
36+ self.docs = DocsFallbackFile(self.base_dir.path)
37+
38+ def touch_file(self, path):
39+ Path(self.base_dir.join(path)).touch()
40+
41+ def test_html_404(self):
42+ request = DummyRequest([b"foo.html"])
43+ resource = self.docs.getChild(b"foo.html", request)
44+ self.assertTrue(resource.path.endswith("404.html"))
45+
46+ def test_other_404(self):
47+ request = DummyRequest([b"foo.jpg"])
48+ resource = self.docs.getChild(b"foo.jpg", request)
49+ self.assertTrue(resource.path.endswith("404.html"))
50+
51+ def test_html_resource(self):
52+ self.touch_file("foo.html")
53+ request = DummyRequest([b"foo.html"])
54+ resource = self.docs.getChild(b"foo.html", request)
55+ self.assertTrue(resource.path.endswith("foo.html"))
56+
57+ def test_other_resource(self):
58+ self.touch_file("foo.jpg")
59+ request = DummyRequest([b"foo.jpg"])
60+ resource = self.docs.getChild(b"foo.jpg", request)
61+ self.assertTrue(resource.path.endswith("foo.jpg"))
62+
63+ def test_append_html(self):
64+ self.touch_file("foo.html")
65+ request = DummyRequest([b"foo"])
66+ resource = self.docs.getChild(b"foo", request)
67+ self.assertTrue(resource.path.endswith("foo.html"))
68+
69+
70 class TestCleanPathRequest(MAASTestCase):
71 def test_requestReceived_converts_extra_slashes_to_single(self):
72 mock_super_requestReceived = self.patch(
73diff --git a/src/maasserver/webapp.py b/src/maasserver/webapp.py
74index 8952914..9828bab 100644
75--- a/src/maasserver/webapp.py
76+++ b/src/maasserver/webapp.py
77@@ -181,6 +181,12 @@ class DocsFallbackFile(NoListingFile):
78 super().__init__(*args, **kwargs)
79 self.childNotFound = DefaultFile(self.child(fallback).path)
80
81+ def getChild(self, path, request):
82+ child = super().getChild(path, request)
83+ if child is self.childNotFound and not path.endswith(b".html"):
84+ child = super().getChild(path + b".html", request)
85+ return child
86+
87
88 class WebApplicationService(StreamServerEndpointService):
89 """Service encapsulating the Django web application.

Subscribers

People subscribed via source and target branches