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 2019/11/15 23:32:02 UTC

[allura] branch db/8340 updated (ad856f3 -> 3879db3)

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

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


 discard ad856f3  [#8340] misc other coverage
     new 6205d4e  [#8340] misc other coverage
     new 8de16c8  [#8340] more blog tests
     new d3f789d  misc
     new 8f045bc  misc
     new 636ef8e  misc - discussion
     new a1fc72f  fixup - tracker
     new 3879db3  misc

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ad856f3)
            \
             N -- N -- N   refs/heads/db/8340 (3879db3)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Allura/allura/controllers/secure.py               | 23 ------
 Allura/allura/lib/app_globals.py                  |  5 --
 Allura/allura/lib/macro.py                        |  9 ++-
 Allura/allura/lib/stats.py                        | 85 -----------------------
 Allura/allura/tests/functional/test_root.py       | 15 +++-
 Allura/allura/tests/test_globals.py               | 39 +++++++++++
 Allura/allura/tests/test_mail_util.py             | 16 +++++
 Allura/allura/tests/test_utils.py                 | 18 ++++-
 ForgeBlog/forgeblog/tests/functional/test_root.py | 22 +++++-
 ForgeBlog/forgeblog/tests/test_app.py             | 20 +++++-
 ForgeDiscussion/forgediscussion/tests/test_app.py | 22 +++++-
 ForgeTracker/forgetracker/tests/test_app.py       | 18 +++++
 12 files changed, 172 insertions(+), 120 deletions(-)
 delete mode 100644 Allura/allura/controllers/secure.py
 delete mode 100644 Allura/allura/lib/stats.py


[allura] 02/07: [#8340] more blog tests

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8de16c84dbd4b36f39dc2072acd65be2958b3dd0
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Thu Nov 14 17:47:27 2019 -0500

    [#8340] more blog tests
---
 Allura/allura/tests/test_globals.py               | 23 +++++++++++++++++++++++
 ForgeBlog/forgeblog/tests/functional/test_root.py | 22 +++++++++++++++++++++-
 ForgeBlog/forgeblog/tests/test_app.py             | 20 +++++++++++++++++++-
 3 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 33453cb..7176654 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -644,6 +644,29 @@ def test_hideawards_macro():
         assert_not_in('Award short', r)
 
 
+@td.with_tool('test', 'Blog', 'blog')
+def test_project_blog_posts_macro():
+    from forgeblog import model as BM
+    with h.push_context('test', 'blog', neighborhood='Projects'):
+        BM.BlogPost.new(
+            title='Test title',
+            text='test post',
+            state='published',
+        )
+        BM.BlogPost.new(
+            title='Test title2',
+            text='test post2',
+            state='published',
+        )
+
+        r = g.markdown_wiki.convert('[[project_blog_posts]]')
+        assert_in('Test title</a></h3>', r)
+        assert_in('Test title2</a></h3>', r)
+        assert_in('<div class="markdown_content"><p>test post</p></div>', r)
+        assert_in('<div class="markdown_content"><p>test post2</p></div>', r)
+        assert_in('by <em>Test Admin</em>', r)
+
+
 def get_project_names(r):
     """
     Extracts a list of project names from a wiki page HTML.
diff --git a/ForgeBlog/forgeblog/tests/functional/test_root.py b/ForgeBlog/forgeblog/tests/functional/test_root.py
index 47b4d87..310f690 100644
--- a/ForgeBlog/forgeblog/tests/functional/test_root.py
+++ b/ForgeBlog/forgeblog/tests/functional/test_root.py
@@ -21,7 +21,7 @@ import datetime
 import json
 
 import tg
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_in
 from mock import patch
 
 from allura.lib import helpers as h
@@ -268,3 +268,23 @@ class Test(TestController):
             wf = json.loads(self.webflash(r))
             assert_equal(wf['status'], 'error')
             assert_equal(wf['message'], 'Create/edit rate limit exceeded. Please try again later.')
+
+    def test_admin_external_feed_invalid(self):
+        r = self.app.get('/blog/')
+        r = self.app.get('/admin/blog/exfeed')
+        form = r.forms[0]
+        form['new_exfeed'].value = 'asdfasdf'
+        r = form.submit()
+        assert_in('Invalid', self.webflash(r))
+
+    def test_admin_external_feed_ok(self):
+        # sidebar menu doesn't expose link to this, unless "forgeblog.exfeed" config is true, but can use form anyway
+        r = self.app.get('/blog/')
+        r = self.app.get('/admin/blog/exfeed')
+        form = r.forms[0]
+        form['new_exfeed'].value = 'https://example.com/feed.rss'
+        r = form.submit()
+        assert_in('External feeds updated', self.webflash(r))
+
+        r = self.app.get('/admin/blog/exfeed')
+        r.mustcontain('https://example.com/feed.rss')
diff --git a/ForgeBlog/forgeblog/tests/test_app.py b/ForgeBlog/forgeblog/tests/test_app.py
index ac50f8b..24e6bfa 100644
--- a/ForgeBlog/forgeblog/tests/test_app.py
+++ b/ForgeBlog/forgeblog/tests/test_app.py
@@ -20,6 +20,7 @@
 import tempfile
 import json
 import os
+from cgi import FieldStorage
 
 from nose.tools import assert_equal
 from tg import tmpl_context as c
@@ -31,7 +32,24 @@ from allura.lib import helpers as h
 from alluratest.controller import setup_basic_test, setup_global_objects
 from allura.tests import decorators as td
 from forgeblog import model as BM
-from cgi import FieldStorage
+
+
+class TestApp(object):
+
+    def setUp(self):
+        setup_basic_test()
+
+    @td.with_tool('test', 'Blog', 'blog')
+    def test_uninstall(self):
+        BM.BlogPost.new(
+            title='Test title',
+            text='test post',
+        )
+        ThreadLocalORMSession.flush_all()
+        assert BM.BlogPost.query.get(title='Test title')
+        # c.app.uninstall(c.project) errors out, but works ok in test_uninstall for repo tools.  So instead:
+        c.project.uninstall_app('blog')
+        assert not BM.BlogPost.query.get(title='Test title')
 
 
 class TestBulkExport(object):


[allura] 06/07: fixup - tracker

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a1fc72fdb473ac5c3cfd6668f2a3e08b19cdc5ff
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Nov 15 18:13:41 2019 -0500

    fixup - tracker
---
 ForgeTracker/forgetracker/tests/test_app.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/ForgeTracker/forgetracker/tests/test_app.py b/ForgeTracker/forgetracker/tests/test_app.py
index 8c416a9..9128d30 100644
--- a/ForgeTracker/forgetracker/tests/test_app.py
+++ b/ForgeTracker/forgetracker/tests/test_app.py
@@ -31,6 +31,7 @@ from ming.orm import ThreadLocalORMSession
 from allura import model as M
 from allura.tests import decorators as td
 from forgetracker import model as TM
+from forgetracker.site_stats import tickets_stats_24hr
 from forgetracker.tests.functional.test_root import TrackerTestController
 
 
@@ -66,6 +67,23 @@ class TestApp(object):
         post = M.Post.query.get(_id=message_id)
         assert_equal(post, None)
 
+    @td.with_tracker
+    def test_uninstall(self):
+        t = TM.Ticket.new()
+        t.summary = 'new ticket'
+        ThreadLocalORMSession.flush_all()
+        assert TM.Ticket.query.get(summary='new ticket')
+        # c.app.uninstall(c.project) errors out, but works ok in test_uninstall for repo tools.  So instead:
+        c.project.uninstall_app('bugs')
+        assert not TM.Ticket.query.get(summary='new ticket')
+
+    @td.with_tracker
+    def test_tickets_stats_24hr(self):
+        # invoked normally via entry point
+        TM.Ticket.new()
+        TM.Ticket.new()
+        assert_equal(2, tickets_stats_24hr())
+
 
 class TestBulkExport(TrackerTestController):
 


[allura] 03/07: misc

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d3f789d99e9f9224b2337f539f6b005c660dd10f
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Nov 15 12:42:51 2019 -0500

    misc
---
 Allura/allura/lib/macro.py          |  2 +-
 Allura/allura/lib/stats.py          | 85 -------------------------------------
 Allura/allura/tests/test_globals.py | 11 +++++
 3 files changed, 12 insertions(+), 86 deletions(-)

diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index b01eaad..4dc1f54 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -312,7 +312,7 @@ def project_screenshots():
     from allura.lib.widgets.project_list import ProjectScreenshots
     ps = ProjectScreenshots()
     g.resource_manager.register(ps)
-    response = ps.display(project=c.project)
+    response = ps.display(project=c.project, h=h)
     return response
 
 
diff --git a/Allura/allura/lib/stats.py b/Allura/allura/lib/stats.py
deleted file mode 100644
index d5244b1..0000000
--- a/Allura/allura/lib/stats.py
+++ /dev/null
@@ -1,85 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-from __future__ import with_statement
-from time import time
-from contextlib import contextmanager
-from tg import request
-
-
-class StatsRecord(object):
-
-    def __init__(self, request, active):
-        self.timers = dict(
-            mongo=0,
-            template=0,
-            total=0)
-        self.url = request.environ['PATH_INFO']
-        self.active = active
-        # Avoid double-timing things
-        self._now_timing = set()
-
-    def __repr__(self):
-        stats = ' '.join(
-            ('%s=%.0fms' % (k, v * 1000))
-            for k, v in sorted(self.timers.iteritems()))
-        return '%s: %s' % (self.url, stats)
-
-    def asdict(self):
-        return dict(
-            url=self.url,
-            timers=self.timers)
-
-    @contextmanager
-    def timing(self, name):
-        if self.active and name not in self._now_timing:
-            self._now_timing.add(name)
-            self.timers.setdefault(name, 0)
-            begin = time()
-            try:
-                yield
-            finally:
-                end = time()
-                self.timers[name] += end - begin
-                self._now_timing.remove(name)
-        else:
-            yield
-
-
-class timing(object):
-
-    '''Decorator to time a method call'''
-
-    def __init__(self, timer):
-        self.timer = timer
-
-    def __call__(self, func):
-        def inner(*l, **kw):
-            try:
-                stats = request.environ['sf.stats']
-            except TypeError:
-                return func(*l, **kw)
-            with stats.timing(self.timer):
-                return func(*l, **kw)
-        inner.__name__ = func.__name__
-        return inner
-
-    def decorate(self, obj, names):
-        names = names.split()
-        for name in names:
-            setattr(obj, name,
-                    self(getattr(obj, name)))
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 7176654..f7b2be4 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -667,6 +667,17 @@ def test_project_blog_posts_macro():
         assert_in('by <em>Test Admin</em>', r)
 
 
+def test_project_screenshots_macro():
+    with h.push_context('test', neighborhood='Projects'):
+        M.ProjectFile(project_id=c.project._id, category='screenshot', caption='caption', filename='test_file.jpg')
+        ThreadLocalORMSession.flush_all()
+
+        r = g.markdown_wiki.convert('[[project_screenshots]]')
+
+        assert_in('href="/p/test/screenshot/test_file.jpg"', r)
+        assert_in('src="/p/test/screenshot/test_file.jpg/thumb"', r)
+
+
 def get_project_names(r):
     """
     Extracts a list of project names from a wiki page HTML.


[allura] 01/07: [#8340] misc other coverage

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6205d4e7ca4df13841b1ce3dabf6d6968ae238e0
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Wed Nov 13 18:13:32 2019 -0500

    [#8340] misc other coverage
---
 Allura/allura/config/app_cfg.py              |  1 -
 Allura/allura/lib/app_globals.py             |  5 ---
 Allura/allura/lib/helpers.py                 | 60 ++--------------------------
 Allura/allura/lib/macro.py                   |  7 ++++
 Allura/allura/tests/decorators.py            |  2 +-
 Allura/allura/tests/functional/test_admin.py |  4 ++
 Allura/allura/tests/functional/test_root.py  | 24 +++++++++--
 Allura/allura/tests/test_globals.py          |  5 +++
 Allura/allura/tests/test_helpers.py          | 16 ++++----
 9 files changed, 50 insertions(+), 74 deletions(-)

diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py
index 222fa54..f5b1464 100644
--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -103,7 +103,6 @@ class AlluraJinjaRenderer(JinjaRenderer):
             cache_size=config.get('jinja_cache_size', -1),
             extensions=['jinja2.ext.do', 'jinja2.ext.i18n'])
         jinja2_env.install_gettext_translations(tg.i18n)
-        jinja2_env.filters['filesizeformat'] = helpers.do_filesizeformat
         jinja2_env.filters['datetimeformat'] = helpers.datetimeformat
         jinja2_env.filters['filter'] = lambda s, t=None: filter(t and jinja2_env.tests[t], s)
         jinja2_env.filters['nl2br'] = helpers.nl2br_jinja_filter
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index f558b74..c748579 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -562,11 +562,6 @@ class Globals(object):
         'h.set_context() is preferred over this method'
         c.app = c.project.app_instance(name)
 
-    def postload_contents(self):
-        text = '''
-'''
-        return json.dumps(dict(text=text))
-
     def year(self):
         return datetime.datetime.utcnow().year
 
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 82285f9..69342c5 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -58,7 +58,7 @@ from tg.decorators import before_validate
 from formencode.variabledecode import variable_decode
 import formencode
 from jinja2 import Markup
-from jinja2.filters import contextfilter, escape
+from jinja2.filters import contextfilter, escape, do_filesizeformat
 from paste.deploy.converters import asbool, aslist, asint
 
 from webhelpers import date, feedgenerator, html, number, misc, text
@@ -233,14 +233,6 @@ def make_neighborhoods(ids):
     return _make_xs('Neighborhood', ids)
 
 
-def make_projects(ids):
-    return _make_xs('Project', ids)
-
-
-def make_users(ids):
-    return _make_xs('User', ids)
-
-
 def make_roles(ids):
     return _make_xs('ProjectRole', ids)
 
@@ -265,6 +257,8 @@ def make_app_admin_only(app):
 
 @contextmanager
 def push_config(obj, **kw):
+    # if you need similar for a dict, use mock.patch.dict
+
     saved_attrs = {}
     new_attrs = []
     for k, v in kw.iteritems():
@@ -745,40 +739,6 @@ def render_any_markup(name, txt, code_mode=False, linenumbers_style=TABLE):
                 txt = '<pre>%s</pre>' % txt
     return Markup(txt)
 
-# copied from jinja2 dev
-# latest release, 2.6, implements this incorrectly
-# can remove and use jinja2 implementation after upgrading to 2.7
-
-
-def do_filesizeformat(value, binary=False):
-    """Format the value like a 'human-readable' file size (i.e. 13 kB,
-4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega,
-Giga, etc.), if the second parameter is set to `True` the binary
-prefixes are used (Mebi, Gibi).
-"""
-    bytes = float(value)
-    base = binary and 1024 or 1000
-    prefixes = [
-        (binary and 'KiB' or 'kB'),
-        (binary and 'MiB' or 'MB'),
-        (binary and 'GiB' or 'GB'),
-        (binary and 'TiB' or 'TB'),
-        (binary and 'PiB' or 'PB'),
-        (binary and 'EiB' or 'EB'),
-        (binary and 'ZiB' or 'ZB'),
-        (binary and 'YiB' or 'YB')
-    ]
-    if bytes == 1:
-        return '1 Byte'
-    elif bytes < base:
-        return '%d Bytes' % bytes
-    else:
-        for i, prefix in enumerate(prefixes):
-            unit = base ** (i + 2)
-            if bytes < unit:
-                return '%.1f %s' % ((base * bytes / unit), prefix)
-        return '%.1f %s' % ((base * bytes / unit), prefix)
-
 
 def nl2br_jinja_filter(value):
     result = '<br>\n'.join(escape(line) for line in value.split('\n'))
@@ -1165,20 +1125,6 @@ def login_overlay(exceptions=None):
         c.show_login_overlay = True
 
 
-def get_filter(ctx, filter_name):
-    """
-    Gets a named Jinja2 filter, passing through
-    any context requested by the filter.
-    """
-    filter_ = ctx.environment.filters[filter_name]
-    if getattr(filter_, 'contextfilter', False):
-        return partial(filter_, ctx)
-    elif getattr(filter_, 'evalcontextfilter', False):
-        return partial(filter_, ctx.eval_ctx)
-    elif getattr(filter_, 'environmentfilter', False):
-        return partial(filter_, ctx.environment)
-
-
 def unidiff(old, new):
     """Returns unified diff between `one` and `two`."""
     return '\n'.join(difflib.unified_diff(
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index abb4776..b01eaad 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -20,6 +20,8 @@ import random
 import shlex
 import logging
 import traceback
+import urllib2
+
 import oembed
 import jinja2
 from operator import attrgetter
@@ -461,6 +463,11 @@ def embed(url=None):
             html = consumer.embed(url)['html']
         except oembed.OEmbedNoEndpoint:
             html = None
+        except urllib2.HTTPError as e:
+            if e.code == 404:
+                return 'Video not available'
+            else:
+                raise
 
     if html:
         # youtube has a trailing ")" at the moment
diff --git a/Allura/allura/tests/decorators.py b/Allura/allura/tests/decorators.py
index 726a402..f044c0e 100644
--- a/Allura/allura/tests/decorators.py
+++ b/Allura/allura/tests/decorators.py
@@ -200,7 +200,7 @@ def out_audits(*messages, **kwargs):
             message=re.compile(preamble + message))).count(), 'Found unexpected: "%s"' % message
 
 
-# not a decorator but use it with LogCapture() decorator
+# not a decorator but use it with LogCapture() context manager
 def assert_logmsg_and_no_warnings_or_errors(logs, msg):
     """
     :param testfixtures.logcapture.LogCapture logs: LogCapture() instance
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 3b2c4df..534863e 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -951,6 +951,10 @@ class TestProjectAdmin(TestController):
             assert url.endswith('/admin/ext/foo'), url
             assert_equals('here the foo settings go', foo_page.body)
 
+    def test_nbhd_invitations(self):
+        r = self.app.get('/admin/invitations')
+        r.mustcontain('Neighborhood Invitation(s) for test')
+
 
 class TestExport(TestController):
 
diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py
index 34da302..ca078fb 100644
--- a/Allura/allura/tests/functional/test_root.py
+++ b/Allura/allura/tests/functional/test_root.py
@@ -28,8 +28,11 @@ functional tests exercise the whole application and its WSGI stack.
 Please read http://pythonpaste.org/webtest/ for more information.
 
 """
+import os
+from urllib import quote
+
 from tg import tmpl_context as c
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_in
 from ming.orm.ormsession import ThreadLocalORMSession
 import mock
 from IPython.testing.decorators import module_not_available, skipif
@@ -37,7 +40,7 @@ from IPython.testing.decorators import module_not_available, skipif
 from allura.tests import decorators as td
 from allura.tests import TestController
 from allura import model as M
-from allura.lib.helpers import push_config
+from allura.lib import helpers as h
 from alluratest.controller import setup_trove_categories
 
 
@@ -69,6 +72,14 @@ class TestRootController(TestController):
         assert cat_links[0].find('a').get('href') == '/browse/clustering'
         assert cat_links[0].find('a').find('span').string == 'Clustering'
 
+    def test_validation(self):
+        # this is not configured ON currently, so adding an individual test to get coverage of the validator itself
+        with mock.patch.dict(os.environ, ALLURA_VALIDATION='all'):
+            self.app.get('/neighborhood')
+            self.app.get('/nf/markdown_to_html?markdown=aaa&project=test&app=bugs&neighborhood=%s'
+                         % M.Neighborhood.query.get(name='Projects')._id,
+                         validate_chunk=True)
+
     def test_sidebar_escaping(self):
         # use this as a convenient way to get something in the sidebar
         M.ProjectCategory(name='test-xss', label='<script>alert(1)</script>')
@@ -123,7 +134,7 @@ class TestRootController(TestController):
         # Install home app
         nb = M.Neighborhood.query.get(name='Adobe')
         p = nb.neighborhood_project
-        with push_config(c, user=M.User.query.get(username='test-admin')):
+        with h.push_config(c, user=M.User.query.get(username='test-admin')):
             p.install_app('home', 'home', 'Home', ordinal=0)
 
         response = self.app.get('/adobe/')
@@ -165,6 +176,13 @@ class TestRootController(TestController):
             '/nf/markdown_to_html?markdown=*aaa*bb[wiki:Home]&project=test&app=bugs&neighborhood=%s' % n._id, validate_chunk=True)
         assert '<p><em>aaa</em>bb<a class="alink" href="/p/test/wiki/Home/">[wiki:Home]</a></p>' in r, r
 
+        # this happens to trigger an error
+        bad_markdown = '<foo {bar}>'
+        r = self.app.get('/nf/markdown_to_html?markdown=%s&project=test&app=bugs&neighborhood=%s' %
+                         (quote(bad_markdown), n._id))
+        r.mustcontain('The markdown supplied could not be parsed correctly.')
+        r.mustcontain('<pre>&lt;foo {bar}&gt;</pre>')
+
     def test_slash_redirect(self):
         self.app.get('/p', status=301)
         self.app.get('/p/', status=302)
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index e8787fb..33453cb 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -345,6 +345,11 @@ def test_macro_embed(oembed_fetch):
               r.replace('\n', ''))
 
 
+def test_macro_embed_video_gone():
+    r = g.markdown_wiki.convert('[[embed url=https://www.youtube.com/watch?v=OWsFqPZ3v-0]]')
+    assert_equal(r, '<div class="markdown_content"><p>Video not available</p></div>')
+
+
 def test_macro_embed_notsupported():
     r = g.markdown_wiki.convert('[[embed url=http://vimeo.com/46163090]]')
     assert_equal(
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 3abde3b..8fccf90 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -107,11 +107,6 @@ def test_find_project():
     assert proj is None
 
 
-def test_make_users():
-    r = h.make_users([None]).next()
-    assert r.username == '*anonymous', r
-
-
 def test_make_roles():
     h.set_context('test', 'wiki', neighborhood='Projects')
     pr = M.ProjectRole.anonymous()
@@ -594,8 +589,11 @@ def test_base64uri_img():
 
 
 def test_base64uri_text():
-    b64txt = h.base64uri('blah blah blah 123 456 foo bar baz', mimetype='text/plain')
-    assert b64txt.startswith('data:text/plain;base64,'), b64txt
+    b64txt = h.base64uri('blah blah blah\n123 456\nfoo bar baz', mimetype='text/plain')
+    assert_equals(b64txt, 'data:text/plain;base64,YmxhaCBibGFoIGJsYWgKMTIzIDQ1Ngpmb28gYmFyIGJheg==')
+
+    b64txt = h.base64uri('blah blah blah\n123 456\nfoo bar baz', mimetype='text/plain', windows_line_endings=True)
+    assert_equals(b64txt, 'data:text/plain;base64,YmxhaCBibGFoIGJsYWgNCjEyMyA0NTYNCmZvbyBiYXIgYmF6')
 
 
 def test_slugify():
@@ -649,3 +647,7 @@ def test_hide_private_info():
 
     with h.push_config(h.tg.config, hide_private_info=False):
         assert_equals(h.hide_private_info('foo bar baz@bing.com'), 'foo bar baz@bing.com')
+
+
+def test_emojize():
+    assert_equals(h.emojize(':smile:'), u'😄')


[allura] 04/07: misc

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8f045bcac47819a1eb8679efe145782cb4d0588a
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Nov 15 17:55:00 2019 -0500

    misc
---
 Allura/allura/tests/functional/test_root.py |  5 +++++
 Allura/allura/tests/test_utils.py           | 18 +++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py
index ca078fb..e6a6bc7 100644
--- a/Allura/allura/tests/functional/test_root.py
+++ b/Allura/allura/tests/functional/test_root.py
@@ -199,6 +199,11 @@ class TestRootController(TestController):
                          NeighborhoodController.index.__wrapped__)
             set_transaction_name.assert_called_with('foo')
 
+    def test_error_page(self):
+        # hard to force a real error (esp. with middleware debugging being different for tests) but we can hit direct:
+        r = self.app.get('/error/document')
+        r.mustcontain("We're sorry but we weren't able to process")
+
 
 class TestRootWithSSLPattern(TestController):
     def setUp(self):
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index 8887cef..12017e2 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -410,4 +410,20 @@ def test_is_nofollow_url():
 def test_close_ipv4_addrs():
     assert utils.close_ipv4_addrs('1.2.3.4', '1.2.3.4')
     assert utils.close_ipv4_addrs('1.2.3.4', '1.2.3.255')
-    assert not utils.close_ipv4_addrs('1.2.3.4', '1.2.4.4')
\ No newline at end of file
+    assert not utils.close_ipv4_addrs('1.2.3.4', '1.2.4.4')
+
+
+def test_lsub_utf8():
+    assert_equal(b'asdf',
+                 utils.lsub_utf8(h.really_unicode('asdf').encode('utf-8'), 40))
+    assert_equal(b'as\xf0\x9f\x98\x84\xc2\xb6\xc2\xba\xc2\xb6',
+                 utils.lsub_utf8(h.really_unicode(u'as😄¶º¶').encode('utf-8'), 40))
+    assert_equal(b'as\xf0\x9f\x98\x84',
+                 utils.lsub_utf8(h.really_unicode(u'as😄¶º¶').encode('utf-8'), 6))
+    # these would truncate the smiley:
+    assert_equal(b'as',
+                 utils.lsub_utf8(h.really_unicode(u'as😄¶º¶').encode('utf-8'), 5))
+    assert_equal(b'as',
+                 utils.lsub_utf8(h.really_unicode(u'as😄¶º¶').encode('utf-8'), 4))
+    assert_equal(b'as',
+                 utils.lsub_utf8(h.really_unicode(u'as😄¶º¶').encode('utf-8'), 3))


[allura] 07/07: misc

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3879db31383ad6aad69f122d28eedced75ba5a4f
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Nov 15 18:31:34 2019 -0500

    misc
---
 Allura/allura/tests/test_mail_util.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Allura/allura/tests/test_mail_util.py b/Allura/allura/tests/test_mail_util.py
index 8568191..7b75f16 100644
--- a/Allura/allura/tests/test_mail_util.py
+++ b/Allura/allura/tests/test_mail_util.py
@@ -27,6 +27,7 @@ from ming.orm import ThreadLocalORMSession
 from tg import config as tg_config
 
 from alluratest.controller import setup_basic_test, setup_global_objects
+from allura.command.smtp_server import MailServer
 from allura.lib.utils import ConfigProxy
 from allura.app import Application
 from allura.lib.mail_util import (
@@ -323,3 +324,18 @@ def test_parse_message_id():
         'de31888f6be2d87dc377d9e713876bb514548625.patches@libjpeg-turbo.p.domain.net',
         'de31888f6be2d87dc377d9e713876bb514548625.patches@libjpeg-turbo.p.domain.net',
     ])
+
+
+class TestMailServer(object):
+
+    def setUp(self):
+        setup_basic_test()
+
+    @mock.patch('allura.command.base.log', autospec=True)
+    def test(self, log):
+        listen_port = ('0.0.0.0', 8825)
+        mailserver = MailServer(listen_port, None)
+        mailserver.process_message('127.0.0.1', 'foo@bar.com', ['1234@tickets.test.p.localhost'],
+                                   u'this is the email body with headers and everything Ο'.encode('utf-8'))
+        assert_equal([], log.exception.call_args_list)
+        log.info.assert_called_with('Msg passed along')


[allura] 05/07: misc - discussion

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 636ef8ef0a448e0fb6d502cca8725993f5a10b5e
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Nov 15 18:13:33 2019 -0500

    misc - discussion
---
 Allura/allura/controllers/secure.py               | 23 -----------------------
 ForgeDiscussion/forgediscussion/tests/test_app.py | 22 ++++++++++++++++++++--
 2 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/Allura/allura/controllers/secure.py b/Allura/allura/controllers/secure.py
deleted file mode 100644
index 899ad42..0000000
--- a/Allura/allura/controllers/secure.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# -*- coding: utf-8 -*-
-
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-"""Sample controller with all its actions protected."""
-
-# This controller is only used when you activate auth. You can safely remove
-# this file from your project.
diff --git a/ForgeDiscussion/forgediscussion/tests/test_app.py b/ForgeDiscussion/forgediscussion/tests/test_app.py
index 4e23cfa..e980fc1 100644
--- a/ForgeDiscussion/forgediscussion/tests/test_app.py
+++ b/ForgeDiscussion/forgediscussion/tests/test_app.py
@@ -23,16 +23,34 @@ import tempfile
 import json
 import os
 from operator import attrgetter
+from cgi import FieldStorage
 
 from nose.tools import assert_equal
 from tg import tmpl_context as c
 from cStringIO import StringIO
+
+from forgediscussion.site_stats import posts_24hr
 from ming.orm import ThreadLocalORMSession
-from cgi import FieldStorage
 
 from allura import model as M
+from allura.tests import decorators as td
 from forgediscussion.tests.functional.test_rest import TestDiscussionApiBase
-from forgediscussion.model.forum import Forum
+from forgediscussion.model.forum import Forum, ForumPost
+
+
+class TestApp(TestDiscussionApiBase):  # creates some sample data
+
+    @td.with_discussion
+    def test_uninstall(self):
+        assert ForumPost.query.get(text='Hi boys and girls')
+        # c.app.uninstall(c.project) errors out, but works ok in test_uninstall for repo tools.  So instead:
+        c.project.uninstall_app('discussion')
+        assert not ForumPost.query.get(text='Hi boys and girls')
+
+    @td.with_discussion
+    def test_tickets_stats_24hr(self):
+        # invoked normally via entry point
+        assert_equal(2, posts_24hr())
 
 
 class TestBulkExport(TestDiscussionApiBase):