You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/03/10 16:12:04 UTC

[allura] 12/14: [#8354] make .ini settings compatible with py3 configparser

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8354
in repository https://gitbox.apache.org/repos/asf/allura.git

commit e2aad504f2f592deadc32b36cacc08e03a5089e8
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Mar 6 17:59:14 2020 -0500

    [#8354] make .ini settings compatible with py3 configparser
---
 Allura/allura/model/project.py               |  8 +++++++-
 Allura/allura/tests/functional/test_admin.py | 13 +++++++++++--
 Allura/allura/tests/test_tasks.py            |  1 +
 Allura/development.ini                       | 24 +++++++++++++++---------
 Allura/docker-dev.ini                        |  3 ++-
 Allura/production-docker-example.ini         |  3 ++-
 Allura/test.ini                              |  9 ++++-----
 7 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 5c95d19..2a6c8ff 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -1103,7 +1103,13 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         elif not self.is_root:
             shortname = self.shortname.split('/')[1]
 
-        return config['bulk_export_filename'].format(project=shortname, date=datetime.utcnow())
+        filename_format = config['bulk_export_filename']
+        if six.PY2:
+            # in py3 ConfigParser requires %% to escape literal "%"
+            # since % has interpolation meaning within ConfigParser
+            # but in py2 the "%%" stays as "%%" so we have to switch it back to a single one
+            filename_format = filename_format.replace('%%', '%')
+        return filename_format.format(project=shortname, date=datetime.utcnow())
 
     def bulk_export_status(self):
         '''
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index cb3a182..2450152 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -19,6 +19,8 @@
 from __future__ import unicode_literals
 from __future__ import absolute_import
 import os
+from datetime import datetime
+
 import allura
 import pkg_resources
 from io import BytesIO
@@ -1030,6 +1032,7 @@ class TestExport(TestController):
         assert_in('error', self.webflash(r))
 
     @mock.patch('allura.ext.admin.admin_main.export_tasks')
+    @mock.patch.dict(tg.config, {'bulk_export_filename': '{project}.zip'})
     def test_selected_one_tool(self, export_tasks):
         r = self.app.post('/admin/export', {'tools': 'wiki'})
         assert_in('ok', self.webflash(r))
@@ -1037,6 +1040,7 @@ class TestExport(TestController):
             ['wiki'], 'test.zip', send_email=True, with_attachments=False)
 
     @mock.patch('allura.ext.admin.admin_main.export_tasks')
+    @mock.patch.dict(tg.config, {'bulk_export_filename': '{project}.zip'})
     def test_selected_multiple_tools(self, export_tasks):
         r = self.app.post('/admin/export', {'tools': ['wiki', 'wiki2']})
         assert_in('ok', self.webflash(r))
@@ -1060,11 +1064,15 @@ class TestExport(TestController):
     @td.with_user_project('test-user')
     def test_bulk_export_filename_for_user_project(self):
         project = M.Project.query.get(shortname='u/test-user')
-        assert_equals(project.bulk_export_filename(), 'test-user.zip')
+        filename = project.bulk_export_filename()
+        assert filename.startswith('test-user-backup-{}-'.format(datetime.utcnow().year))
+        assert filename.endswith('.zip')
 
     def test_bulk_export_filename_for_nbhd(self):
         project = M.Project.query.get(name='Home Project for Projects')
-        assert_equals(project.bulk_export_filename(), 'p.zip')
+        filename = project.bulk_export_filename()
+        assert filename.startswith('p-backup-{}-'.format(datetime.utcnow().year))
+        assert filename.endswith('.zip')
 
     def test_bulk_export_path_for_nbhd(self):
         project = M.Project.query.get(name='Home Project for Projects')
@@ -1129,6 +1137,7 @@ class TestRestExport(TestRestApiBase):
     @mock.patch('allura.model.project.MonQTask')
     @mock.patch('allura.ext.admin.admin_main.AdminApp.exportable_tools_for')
     @mock.patch('allura.ext.admin.admin_main.export_tasks.bulk_export')
+    @mock.patch.dict(tg.config, {'bulk_export_filename': '{project}.zip'})
     def test_export_ok(self, bulk_export, exportable_tools, MonQTask):
         MonQTask.query.get.return_value = None
         exportable_tools.return_value = [
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 8f63478..c2d9117 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -641,6 +641,7 @@ class TestExportTasks(unittest.TestCase):
 
     @mock.patch('allura.tasks.export_tasks.shutil')
     @mock.patch('allura.tasks.export_tasks.zipdir')
+    @mock.patch.dict(tg.config, {'bulk_export_filename': '{project}.zip'})
     @td.with_wiki
     def test_bulk_export(self, zipdir, shutil):
         M.MonQTask.query.remove()
diff --git a/Allura/development.ini b/Allura/development.ini
index ad56a7a..010b550 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -89,8 +89,8 @@ base_url = http://localhost:8080
 ; `Allura/allura/public/nf/images/` and specify file name below
 ; logo.link = /
 ; logo.path = sf10a.png
-; logo.width = 125 ; in px
-; logo.height = 18 ; in px
+; logo.width = 125 (in px)
+; logo.height = 18 (in px)
 
 ; Used to uniquify references to static resources, can be a timestamp or any unique value
 ; This should be updated each time you deploy (or make significant changes, like new tools, new css)
@@ -149,7 +149,8 @@ project_icon_sizes = 16 24 32 48 64 72 90 96 128 135 180 270
 ; For LDAP see https://forge-allura.apache.org/docs/getting_started/installation.html#using-ldap
 ;auth.method = ldap
 auth.method = local
-auth.remember_for = 365  ; in days, for the "remember me" checkbox on login
+; in days, for the "remember me" checkbox on login
+auth.remember_for = 365
 
 ; Customize login/logout URLs only if you have some custom authentication set up.
 auth.login_url = /auth/
@@ -163,7 +164,8 @@ auth.max_password_len = 30
 
 ; password expiration options (disabled if neither is set)
 ;auth.pwdexpire.days = 1
-;auth.pwdexpire.before = 1401949912  ; unix timestamp
+; unix timestamp:
+;auth.pwdexpire.before = 1401949912
 
 ; if using LDAP, also run `pip install python-ldap` in your Allura environment
 
@@ -261,7 +263,8 @@ site_admin_project_nbhd = Projects
 ; for stopforumspam, should be a listed_ip_*_all.txt file
 ;spam.stopforumspam.ip_addr_file =
 ;spam.stopforumspam.threshold = 20
-spam.form_post_expiration = 345600 ; 4 days
+; 4 days:
+spam.form_post_expiration = 345600
 
 ; Phone verification service: Nexmo Verify
 ; phone.method = nexmo
@@ -312,7 +315,8 @@ webhook.repo_push.max_hooks = {"git": 3, "hg": 3, "svn": 3}
 ; To use ssl if and only if a user is logged in:
 ;force_ssl.logged_in = true
 ; If you set force_ssl.logged_in, you probably want some URLs to be ssl when logged out:
-;force_ssl.pattern = ^/auth|^/[a-z0-9-]+/import_project/  ; import_project uses a login overlay
+;   (import_project uses a login overlay)
+;force_ssl.pattern = ^/auth|^/[a-z0-9-]+/import_project/
 ; And to permit some URLs to be accessed over http anyway:
 ;    /_test_vars is used when running `paster shell`
 ;no_redirect.pattern = ^/nf/\d+/_(ew|static)_/|^/rest/|^/nf/tool_icon_css|^/auth/refresh_repo|^/_test_vars
@@ -328,7 +332,8 @@ static.script_name = /nf/%(build_key)s/_static_/
 static.url_base = /nf/%(build_key)s/_static_/
 
 ; Expires header for "static" resources served through allura (e.g. icons, attachments, /nf/tool_icon_css)
-files_expires_header_secs = 1209600 ; 2 weeks
+; 2 weeks:
+files_expires_header_secs = 1209600
 
 ; EasyWidgets settings
 ; This CORS header is necessary if serving webfonts via a different domain
@@ -432,7 +437,7 @@ scm.view.max_syntax_highlight_bytes = 500000
 ; If you keep bulk_export_enabled, you should set up your server to securely share bulk_export_path with users somehow
 bulk_export_path = /tmp/bulk_export/{nbhd}/{project}
 ; bulk_export_tmpdir can be set to hold files before building the zip file.  Defaults to use bulk_export_path
-bulk_export_filename = {project}-backup-{date:%Y-%m-%d-%H%M%S}.zip
+bulk_export_filename = {project}-backup-{date:%%Y-%%m-%%d-%%H%%M%%S}.zip
 ; You will need to specify site-specific instructions here for accessing the exported files.
 bulk_export_download_instructions = Sample instructions for {project}
 
@@ -656,7 +661,8 @@ next=main
 ;
 [app:task]
 use = main
-override_root = task ; TurboGears will use controllers/task.py as root controller
+; TurboGears will use controllers/task.py as root controller
+override_root = task
 
 
 
diff --git a/Allura/docker-dev.ini b/Allura/docker-dev.ini
index 980d8b8..7a7faaf 100644
--- a/Allura/docker-dev.ini
+++ b/Allura/docker-dev.ini
@@ -66,7 +66,8 @@ forgemail.port = 8825
 
 [app:task]
 use = main
-override_root = task ; TurboGears will use controllers/task.py as root controller
+; TurboGears will use controllers/task.py as root controller
+override_root = task
 
 [loggers]
 keys = root, allura, sqlalchemy, paste, ew, taskdstatus, timermiddleware, tmw_details
diff --git a/Allura/production-docker-example.ini b/Allura/production-docker-example.ini
index b5ba53c..1824aa1 100644
--- a/Allura/production-docker-example.ini
+++ b/Allura/production-docker-example.ini
@@ -89,7 +89,8 @@ stats.sample_rate = .01
 
 [app:task]
 use = main
-override_root = task ; TurboGears will use controllers/task.py as root controller
+; TurboGears will use controllers/task.py as root controller
+override_root = task
 
 
 
diff --git a/Allura/test.ini b/Allura/test.ini
index 82132b5..efe4228 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -26,7 +26,8 @@
 
 [app:main]
 use = config:development.ini#main
-override_root=basetest_project_root ; TurboGears will use controllers/basetest_project_root.py as root controller
+; TurboGears will use controllers/basetest_project_root.py as root controller
+override_root=basetest_project_root
 disable_template_overrides = True
 
 ; Use in-memory MongoDB
@@ -80,9 +81,6 @@ support_tool_choices = wiki tickets discussion
 ; tests expect max length of 40000
 markdown_render_max_length = 40000
 
-; TODO: make this and tests match development.ini
-bulk_export_filename = {project}.zip
-
 ; TODO: update tests and let this be true
 solr.use_new_types = false
 
@@ -91,7 +89,8 @@ auth.require_email_addr = false
 
 [app:task]
 use = main
-override_root = task ; TurboGears will use controllers/task.py as root controller
+; TurboGears will use controllers/task.py as root controller
+override_root = task
 
 ;
 ; Logging goes to a test.log file in current directory