aboutsummaryrefslogtreecommitdiff
path: root/license_protected_downloads
diff options
context:
space:
mode:
authorGeorgy Redkozubov <georgy.redkozubov@linaro.org>2012-07-27 19:25:36 +0400
committerGeorgy Redkozubov <georgy.redkozubov@linaro.org>2012-07-27 19:25:36 +0400
commitb416e909623ae33d2a26ecca295846f003a8ca23 (patch)
tree9a62f9739b43ec29db9144ba678934425416c16d /license_protected_downloads
parented6e8b4384d1e8349f31095b0023712e77d419ea (diff)
Moved HEADER.html processing to function. Added test.
Diffstat (limited to 'license_protected_downloads')
-rw-r--r--license_protected_downloads/tests/test_views.py8
-rw-r--r--license_protected_downloads/views.py29
2 files changed, 27 insertions, 10 deletions
diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py
index d945a1d..f2d5406 100644
--- a/license_protected_downloads/tests/test_views.py
+++ b/license_protected_downloads/tests/test_views.py
@@ -331,5 +331,13 @@ class ViewTests(TestCase):
file_path = os.path.join(TESTSERVER_ROOT, target_file)
self.assertEqual(response['X-Sendfile'], file_path)
+ def test_header_html(self):
+ target_file = "~linaro-android"
+ url = urlparse.urljoin("http://testserver/", target_file)
+ response = self.client.get(url, follow=True)
+
+ self.assertContains(response,
+ r"Welcome to the Linaro releases server")
+
if __name__ == '__main__':
unittest.main()
diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py
index d4f8160..1018d09 100644
--- a/license_protected_downloads/views.py
+++ b/license_protected_downloads/views.py
@@ -102,6 +102,24 @@ def _get_theme(path):
return vendor[1:]
+def _get_header_html_content(path):
+ """
+ Read HEADER.html in current directory if exists and return
+ contents of <div id="content"> block to include in rendered
+ html.
+ """
+ header_html = os.path.join(path, "HEADER.html")
+ header_content = u""
+ if os.path.isfile(header_html):
+ with open(header_html, "r") as infile:
+ body = infile.read()
+ soup = BeautifulSoup(body)
+ for chunk in soup.findAll(id="content"):
+ header_content += chunk.prettify().decode("utf-8")
+ header_content = '\n'.join(header_content.split('\n')[1:-1])
+ return header_content
+
+
def is_protected(path):
build_info = None
max_index = 1
@@ -230,16 +248,7 @@ def file_server(request, path):
else:
up_dir = None
- header_html = os.path.join(path, "HEADER.html")
- header_content = u""
- if os.path.isfile(header_html):
- with open(header_html, "r") as infile:
- body = infile.read()
- soup = BeautifulSoup(body)
- for chunk in soup.findAll(id="content"):
- header_content += chunk.prettify().decode("utf-8")
- header_content = '\n'.join(header_content.split('\n')[1:-1])
-
+ header_content = _get_header_html_content(path)
download = None
if 'dl' in request.GET:
download = request.GET['dl']