You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2022/09/15 13:46:35 UTC

[allura] branch dw/8455 updated (ba1a294cb -> a2aaab866)

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

dill0wn pushed a change to branch dw/8455
in repository https://gitbox.apache.org/repos/asf/allura.git


    from ba1a294cb all trivial failures resolved for ./Allura, only legit failures remain
     new 422a25a2e fixup! all trivial failures resolved for ./Allura, only legit failures remain
     new 132365a7e [#8455] allura pytest - fix misc test failures that popped up during pytest conversion
     new 47ec7df62 fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion
     new 8effcc6bd fixup! fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion
     new a2aaab866 fixup! fixup! fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion

The 5 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/lib/macro.py                         |  15 +--
 Allura/allura/model/project.py                     |  20 +++-
 Allura/allura/tests/exclude_from_rewrite_hook.py   |  31 ++++++
 .../allura/tests/functional/test_neighborhood.py   |   8 +-
 Allura/allura/tests/model/test_auth.py             |   2 +-
 Allura/allura/tests/test_globals.py                | 117 ++++++++++++---------
 Allura/allura/tests/test_plugin.py                 |  34 +++---
 Allura/allura/tests/test_tasks.py                  |  38 +++----
 Allura/allura/tests/test_webhooks.py               | 101 +++++++++---------
 9 files changed, 211 insertions(+), 155 deletions(-)
 create mode 100644 Allura/allura/tests/exclude_from_rewrite_hook.py


[allura] 01/05: fixup! all trivial failures resolved for ./Allura, only legit failures remain

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

dill0wn pushed a commit to branch dw/8455
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 422a25a2e41666ca3f77660903b2ad5060c6a590
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Mon Sep 12 15:11:09 2022 +0000

    fixup! all trivial failures resolved for ./Allura, only legit failures remain
---
 Allura/allura/tests/test_globals.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index f75f2d268..4d4b3b592 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -48,11 +48,17 @@ from forgewiki import model as WM
 from forgeblog import model as BM
 
 
+def setup_module(module):
+    setup_basic_test()
+    setup_unit_test()
+
+
 def squish_spaces(text):
     # \s is whitespace
     # \xa0 is &nbsp; in unicode form
     return re.sub(r'[\s\xa0]+', ' ', text)
 
+
 def get_project_names(r):
     """
     Extracts a list of project names from a wiki page HTML.
@@ -75,13 +81,10 @@ def get_projects_property_in_the_same_order(names, prop):
     return [projects_dict[name] for name in names]
 
 
-
 @with_nose_compatibility
 class Test():
 
     def setup_method(self, method):
-        setup_basic_test()
-        setup_unit_test()
         setup_global_objects()
 
     @td.with_wiki
@@ -514,7 +517,6 @@ class Test():
             '1. first item<br/>\n'
             '2. second item</p></div>')
 
-
     def test_markdown_autolink(self):
         tgt = 'http://everything2.com/?node=nate+oostendorp'
         s = g.markdown.convert('This is %s' % tgt)
@@ -759,7 +761,6 @@ class Test():
             assert '<div class="markdown_content"><p>test post2</p></div>' in r
             assert 'by <em>Test Admin</em>' in r
 
-
     def test_project_screenshots_macro(self):
         with h.push_context('test', neighborhood='Projects'):
             M.ProjectFile(project_id=c.project._id, category='screenshot', caption='caption', filename='test_file.jpg')
@@ -770,6 +771,7 @@ class Test():
             assert 'href="/p/test/screenshot/test_file.jpg"' in r
             assert 'src="/p/test/screenshot/test_file.jpg/thumb"' in r
 
+
 @with_nose_compatibility
 class TestCachedMarkdown(unittest.TestCase):
 


[allura] 03/05: fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion

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

dill0wn pushed a commit to branch dw/8455
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 47ec7df62614ae02e7731b5470c63c5bf5ccd8a0
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Wed Sep 14 14:37:01 2022 +0000

    fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion
---
 Allura/allura/tests/exclude_from_rewrite_hook.py   |  31 +++++++
 .../allura/tests/functional/test_neighborhood.py   |   8 +-
 Allura/allura/tests/test_plugin.py                 |  35 ++++---
 Allura/allura/tests/test_tasks.py                  |  38 +++-----
 Allura/allura/tests/test_webhooks.py               | 101 +++++++++++----------
 5 files changed, 117 insertions(+), 96 deletions(-)

diff --git a/Allura/allura/tests/exclude_from_rewrite_hook.py b/Allura/allura/tests/exclude_from_rewrite_hook.py
new file mode 100644
index 000000000..509841776
--- /dev/null
+++ b/Allura/allura/tests/exclude_from_rewrite_hook.py
@@ -0,0 +1,31 @@
+import sys
+
+from allura.app import Application
+from allura.lib.decorators import task
+from allura.lib.exceptions import CompoundError
+
+
+class ThemeProviderTestApp(Application):
+    """
+    If this test class is added directly to a test module, pkg_resources internals
+    will throw this error:
+        NotImplementedError: Can't perform this operation for unregistered loader type
+    This is because pytest adds a hook to override the default assert behavior and this
+    conflicts/messes-with pkg_resources. Theoretically on python > py37, importlib.resources
+    can do the same things as pkg_resources and faster, but those solutions don't currently
+    work on py37.
+    """
+    icons = {
+        24: 'images/testapp_24.png',
+    }
+
+
+@task
+def raise_compound_exception():
+    errs = []
+    for x in range(10):
+        try:
+            assert False, 'assert %d' % x
+        except Exception:
+            errs.append(sys.exc_info())
+    raise CompoundError(*errs)
\ No newline at end of file
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 5076ef049..3268a3b51 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -43,12 +43,12 @@ from allura.tests.pytest_helpers import with_nose_compatibility
 @with_nose_compatibility
 class TestNeighborhood(TestController):
 
-    def setUp(self):
-        super().setUp()
+    def setup_method(self, method):
+        super().setup_method(method)
         self._cleanup_audit_log()
 
-    def tearDown(self):
-        super().tearDown()
+    def teardown_method(self, method):
+        super().teardown_method(method)
         self._cleanup_audit_log()
 
     def _cleanup_audit_log(self):
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 22a7ed8bf..56b358a79 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -35,7 +35,6 @@ from alluratest.tools import (
 from mock import Mock, MagicMock, patch
 
 from allura import model as M
-from allura.app import Application
 from allura.lib import plugin
 from allura.lib import phone
 from allura.lib import helpers as h
@@ -44,15 +43,19 @@ from allura.lib.plugin import ProjectRegistrationProvider
 from allura.lib.plugin import ThemeProvider
 from allura.lib.exceptions import ProjectConflict, ProjectShortnameInvalid
 from allura.tests.decorators import audits
+from allura.tests.exclude_from_rewrite_hook import ThemeProviderTestApp
 from alluratest.controller import setup_basic_test, setup_global_objects
 from allura.tests.pytest_helpers import with_nose_compatibility
 
 
+def setup_module(module):
+    setup_basic_test()
+
+
 @with_nose_compatibility
 class TestProjectRegistrationProvider:
 
     def setup_method(self, method):
-        setup_basic_test()
         self.provider = ProjectRegistrationProvider()
 
     @patch('allura.lib.security.has_access')
@@ -170,7 +173,6 @@ class TestProjectRegistrationProviderPhoneVerification:
         self.user = UserMock()
         self.nbhd = MagicMock()
 
-
     def test_phone_verified_disabled(self):
         with h.push_config(tg.config, **{'project.verify_phone': 'false'}):
             assert self.p.phone_verified(self.user, self.nbhd)
@@ -280,36 +282,31 @@ class TestProjectRegistrationProviderPhoneVerification:
                     assert result == g.phone_service.verify.return_value
             assert 5 == g.phone_service.verify.call_count
 
+
 @with_nose_compatibility
 class TestThemeProvider:
 
     @patch('allura.app.g')
     @patch('allura.lib.plugin.g')
+    # FIXME: check with dave.
     def test_app_icon_str(self, plugin_g, app_g):
-        class TestApp(Application):
-            icons = {
-                24: 'images/testapp_24.png',
-            }
-        plugin_g.entry_points = {'tool': {'testapp': TestApp}}
-        assert (ThemeProvider().app_icon_url('testapp', 24) ==
-                      app_g.theme_href.return_value)
+        plugin_g.entry_points = {'tool': {'testapp': ThemeProviderTestApp}}
+        app_icon = ThemeProvider().app_icon_url('testapp', 24)
+        other = app_g.theme_href.return_value
+        assert app_icon == other
+            
         app_g.theme_href.assert_called_with('images/testapp_24.png')
 
     @patch('allura.lib.plugin.g')
     def test_app_icon_str_invalid(self, g):
         g.entry_points = {'tool': {'testapp': Mock()}}
-        assert (ThemeProvider().app_icon_url('invalid', 24) ==
-                      None)
+        assert ThemeProvider().app_icon_url('invalid', 24) == None
 
     @patch('allura.app.g')
     def test_app_icon_app(self, g):
-        class TestApp(Application):
-            icons = {
-                24: 'images/testapp_24.png',
-            }
-        app = TestApp(None, None)
-        assert (ThemeProvider().app_icon_url(app, 24) ==
-                      g.theme_href.return_value)
+        app = ThemeProviderTestApp(None, None)
+        assert ThemeProvider().app_icon_url(app, 24) == \
+            g.theme_href.return_value
         g.theme_href.assert_called_with('images/testapp_24.png')
 
 
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 735b3294b..429effd80 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -18,6 +18,7 @@
 import operator
 import shutil
 import sys
+from textwrap import dedent
 import unittest
 
 import six
@@ -52,6 +53,7 @@ from allura.tasks import export_tasks
 from allura.tasks import admin_tasks
 from allura.tests import decorators as td
 from allura.tests.pytest_helpers import with_nose_compatibility
+from allura.tests.exclude_from_rewrite_hook import raise_compound_exception
 from allura.lib.decorators import event_handler, task
 
 
@@ -148,7 +150,7 @@ class TestEventTasks(unittest.TestCase):
         assert M.MonQTask.query.get(task_name='allura.tasks.event_tasks.event', args=['my_event4'])
 
     def test_compound_error(self):
-        t = raise_exc.post()
+        t = raise_compound_exception.post()
         with LogCapture(level=logging.ERROR) as l, \
                 mock.patch.dict(tg.config, {'monq.raise_errors': False}):  # match normal non-test behavior
             t()
@@ -158,7 +160,7 @@ class TestEventTasks(unittest.TestCase):
         assert "AssertionError('assert 0'" in msg
         assert "AssertionError('assert 5'" in msg
         assert ' on job <MonQTask ' in msg
-        assert ' (error) P:10 allura.tests.test_tasks.raise_exc ' in msg
+        assert ' (error) P:10 allura.tests.exclude_from_rewrite_hook.raise_compound_exception ' in msg
         for x in range(10):
             assert ('assert %d' % x) in t.result
 
@@ -510,16 +512,17 @@ class TestMailTasks(unittest.TestCase):
 
     @td.with_tool('test', 'Tickets', 'bugs')
     def test_receive_autoresponse(self):
-        message = '''Date: Wed, 30 Oct 2013 01:38:40 -0700
-From: <te...@domain.net>
-To: <1...@bugs.test.p.in.localhost>
-Message-ID: <super-unique-id>
-Subject: Not here Re: Message notification
-Precedence: bulk
-X-Autoreply: yes
-Auto-Submitted: auto-replied
-
-I'm not here'''
+        message = dedent('''\
+            Date: Wed, 30 Oct 2013 01:38:40 -0700
+            From: <te...@domain.net>
+            To: <1...@bugs.test.p.in.localhost>
+            Message-ID: <super-unique-id>
+            Subject: Not here Re: Message notification
+            Precedence: bulk
+            X-Autoreply: yes
+            Auto-Submitted: auto-replied
+
+            I'm not here''')
         import forgetracker
         c.user = M.User.by_username('test-admin')
         with mock.patch.object(forgetracker.tracker_main.ForgeTrackerApp, 'handle_message') as hm:
@@ -597,17 +600,6 @@ def _my_event(event_type, testcase, *args, **kwargs):
     testcase.called_with.append((args, kwargs))
 
 
-@task
-def raise_exc():
-    errs = []
-    for x in range(10):
-        try:
-            assert False, 'assert %d' % x
-        except Exception:
-            errs.append(sys.exc_info())
-    raise CompoundError(*errs)
-
-
 class _TestArtifact(M.Artifact):
     _shorthand_id = FieldProperty(str)
     text = FieldProperty(str)
diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py
index 5b9d5b1f2..8237847d6 100644
--- a/Allura/allura/tests/test_webhooks.py
+++ b/Allura/allura/tests/test_webhooks.py
@@ -132,6 +132,7 @@ class TestValidators(TestWebhookBase):
 
 @with_nose_compatibility
 class TestWebhookController(TestController):
+
     def setup_method(self, method):
         super().setup_method(method)
         self.patches = self.monkey_patch()
@@ -182,6 +183,56 @@ class TestWebhookController(TestController):
         else:
             assert False, 'Validation error not found'
 
+    def test_AAAA_WORKAROUND__edit(self):
+        """
+        This must run first in this test class for unknown reasons ever since
+            https://github.com/TurboGears/tg2/commit/02fb49b14e70fdd8ac16973488fb3637e5e59114
+
+        If any test runs the self.app.post from create_webhook before this one, then this test will fail on:
+            with td.audits(msg):
+                r = form.submit()
+        because WebhookValidator's `value` will be "create" instead of an objectid str
+
+        Maybe something to do with WebhookControllerMeta setup of `validate` decorators?
+        """
+        data1 = {'url': 'http://httpbin.org/post',
+                 'secret': 'secret'}
+        data2 = {'url': 'http://example.com/hook',
+                 'secret': 'secret2'}
+        self.create_webhook(data1).follow()
+        self.create_webhook(data2).follow()
+        assert M.Webhook.query.find().count() == 2
+        wh1 = M.Webhook.query.get(hook_url=data1['url'])
+        r = self.app.get(self.url + '/repo-push/%s' % wh1._id)
+        form = r.forms[0]
+        assert form['url'].value == data1['url']
+        assert form['secret'].value == data1['secret']
+        assert form['webhook'].value == str(wh1._id)
+        form['url'] = 'http://host.org/hook'
+        form['secret'] = 'new secret'
+        msg = 'edit webhook repo-push\n{} => {}\n{}'.format(
+            data1['url'], form['url'].value, 'secret changed')
+        with td.audits(msg):
+            r = form.submit()
+        wf = json.loads(self.webflash(r))
+        assert wf['status'] == 'ok'
+        assert wf['message'] == 'Edited successfully'
+        assert M.Webhook.query.find().count() == 2
+        wh1 = M.Webhook.query.get(_id=wh1._id)
+        assert wh1.hook_url == 'http://host.org/hook'
+        assert wh1.app_config_id == self.git.config._id
+        assert wh1.secret == 'new secret'
+        assert wh1.type == 'repo-push'
+
+        # Duplicates
+        r = self.app.get(self.url + '/repo-push/%s' % wh1._id)
+        form = r.forms[0]
+        form['url'] = data2['url']
+        r = form.submit()
+        self.find_error(r, '_the_form',
+                        '"repo-push" webhook already exists for Git http://example.com/hook',
+                        form_type='edit')
+
     def test_access(self):
         self.app.get(self.url + '/repo-push/')
         self.app.get(self.url + '/repo-push/',
@@ -256,56 +307,6 @@ class TestWebhookController(TestController):
         self.find_error(r, 'url',
                         'You must provide a full domain name (like qwer.com)')
 
-    def test_AAAA_WORKAROUND__edit(self):
-        """
-        This must run first in this test class for unknown reasons ever since
-            https://github.com/TurboGears/tg2/commit/02fb49b14e70fdd8ac16973488fb3637e5e59114
-
-        If any test runs the self.app.post from create_webhook before this one, then this test will fail on:
-            with td.audits(msg):
-                r = form.submit()
-        because WebhookValidator's `value` will be "create" instead of an objectid str
-
-        Maybe something to do with WebhookControllerMeta setup of `validate` decorators?
-        """
-        data1 = {'url': 'http://httpbin.org/post',
-                 'secret': 'secret'}
-        data2 = {'url': 'http://example.com/hook',
-                 'secret': 'secret2'}
-        self.create_webhook(data1).follow()
-        self.create_webhook(data2).follow()
-        assert M.Webhook.query.find().count() == 2
-        wh1 = M.Webhook.query.get(hook_url=data1['url'])
-        r = self.app.get(self.url + '/repo-push/%s' % wh1._id)
-        form = r.forms[0]
-        assert form['url'].value == data1['url']
-        assert form['secret'].value == data1['secret']
-        assert form['webhook'].value == str(wh1._id)
-        form['url'] = 'http://host.org/hook'
-        form['secret'] = 'new secret'
-        msg = 'edit webhook repo-push\n{} => {}\n{}'.format(
-            data1['url'], form['url'].value, 'secret changed')
-        with td.audits(msg):
-            r = form.submit()
-        wf = json.loads(self.webflash(r))
-        assert wf['status'] == 'ok'
-        assert wf['message'] == 'Edited successfully'
-        assert M.Webhook.query.find().count() == 2
-        wh1 = M.Webhook.query.get(_id=wh1._id)
-        assert wh1.hook_url == 'http://host.org/hook'
-        assert wh1.app_config_id == self.git.config._id
-        assert wh1.secret == 'new secret'
-        assert wh1.type == 'repo-push'
-
-        # Duplicates
-        r = self.app.get(self.url + '/repo-push/%s' % wh1._id)
-        form = r.forms[0]
-        form['url'] = data2['url']
-        r = form.submit()
-        self.find_error(r, '_the_form',
-                        '"repo-push" webhook already exists for Git http://example.com/hook',
-                        form_type='edit')
-
     def test_edit_validation(self):
         invalid = M.Webhook(
             type='invalid type',


[allura] 02/05: [#8455] allura pytest - fix misc test failures that popped up during pytest conversion

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

dill0wn pushed a commit to branch dw/8455
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 132365a7ea5dbab0e3e3abb93c3e5b5cd5fdd633
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Mon Sep 12 20:00:41 2022 +0000

    [#8455] allura pytest - fix misc test failures that popped up during pytest conversion
---
 Allura/allura/tests/model/test_auth.py |  2 +-
 Allura/allura/tests/test_globals.py    | 90 +++++++++++++++++-----------------
 2 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index 2d6aa75f7..7f48c49bc 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -352,8 +352,8 @@ def test_check_sent_user_message_times():
     assert not user1.can_send_user_message()
 
 
-@td.with_user_project('test-admin')
 @with_setup(setup_method)
+@td.with_user_project('test-admin')
 def test_user_track_active():
     # without this session flushing inside track_active raises Exception
     setup_functional_test()
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 4d4b3b592..172c1c57b 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -18,6 +18,7 @@
 
 import re
 import os
+from textwrap import dedent
 import allura
 import unittest
 import hashlib
@@ -358,17 +359,19 @@ class Test():
 
     def test_markdown_toc(self):
         with h.push_context('test', neighborhood='Projects'):
-            r = g.markdown_wiki.convert("""[TOC]
+            r = g.markdown_wiki.convert(dedent("""\
+                [TOC]
 
-    # Header 1
+                # Header 1
 
-    ## Header 2""")
-        assert '''<ul>
-    <li><a href="#header-1">Header 1</a><ul>
-    <li><a href="#header-2">Header 2</a></li>
-    </ul>
-    </li>
-    </ul>''' in r, r
+                ## Header 2"""))
+        assert dedent('''\
+            <ul>
+            <li><a href="#header-1">Header 1</a><ul>
+            <li><a href="#header-2">Header 2</a></li>
+            </ul>
+            </li>
+            </ul>''') in r
 
     @td.with_wiki
     def test_wiki_artifact_links(self):
@@ -442,38 +445,35 @@ class Test():
             '<p>Line</p></div>')
 
         # should not raise an exception:
-        assert (
-            g.markdown.convert("<class 'foo'>") ==
-            '''<div class="markdown_content"><p>&lt;class 'foo'=""&gt;&lt;/class&gt;</p></div>''')
-
-        assert (
-            g.markdown.convert('''# Header
-
-    Some text in a regular paragraph
-
-        :::python
-        for i in range(10):
-            print i
-    ''') ==
-            # no <br
-            '<div class="markdown_content"><h1 id="header">Header</h1>\n'
-            '<p>Some text in a regular paragraph</p>\n'
-            '<div class="codehilite"><pre><span></span><code><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>\n'
-            '    <span class="nb">print</span> <span class="n">i</span>\n'
-            '</code></pre></div>\n'
-            '</div>')
+        assert g.markdown.convert("<class 'foo'>") == \
+            '''<div class="markdown_content"><p>&lt;class 'foo'=""&gt;&lt;/class&gt;</p></div>'''
+
+        assert g.markdown.convert(dedent('''\
+            # Header
+
+            Some text in a regular paragraph
+
+                :::python
+                for i in range(10):
+                    print i
+            ''')) == dedent('''\
+                <div class="markdown_content"><h1 id="header">Header</h1>
+                <p>Some text in a regular paragraph</p>
+                <div class="codehilite"><pre><span></span><code><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
+                    <span class="nb">print</span> <span class="n">i</span>
+                </code></pre></div>
+                </div>''')
         assert (
             g.forge_markdown(email=True).convert('[Home]') ==
             # uses localhost:
             '<div class="markdown_content"><p><a class="alink" href="http://localhost/p/test/wiki/Home/">[Home]</a></p></div>')
-        assert (
-            g.markdown.convert('''
-    ~~~~
-    def foo(): pass
-    ~~~~''') ==
-            '<div class="markdown_content"><div class="codehilite"><pre><span></span><code>def foo(): pass\n'
-            '</code></pre></div>\n'
-            '</div>')
+        assert g.markdown.convert(dedent('''\
+            ~~~~
+            def foo(): pass
+            ~~~~''')) == dedent('''\
+                <div class="markdown_content"><div class="codehilite"><pre><span></span><code>def foo(): pass
+                </code></pre></div>
+                </div>''')
 
     def test_markdown_list_without_break(self):
         # this is not a valid way to make a list in original Markdown or python-markdown
@@ -482,37 +482,37 @@ class Test():
         # TODO: try https://github.com/adamb70/mdx-breakless-lists
         #       or https://gitlab.com/ayblaq/prependnewline
         assert (
-            g.markdown.convert('''\
+            g.markdown.convert(dedent('''\
     Regular text
     * first item
-    * second item''') ==
+    * second item''')) ==
             '<div class="markdown_content"><p>Regular text\n'  # no <br>
             '* first item\n'  # no <br>
             '* second item</p></div>')
 
         assert (
-            g.markdown.convert('''\
+            g.markdown.convert(dedent('''\
     Regular text
     - first item
-    - second item''') ==
+    - second item''')) ==
             '<div class="markdown_content"><p>Regular text<br/>\n'
             '- first item<br/>\n'
             '- second item</p></div>')
 
         assert (
-            g.markdown.convert('''\
+            g.markdown.convert(dedent('''\
     Regular text
     + first item
-    + second item''') ==
+    + second item''')) ==
             '<div class="markdown_content"><p>Regular text<br/>\n'
             '+ first item<br/>\n'
             '+ second item</p></div>')
 
         assert (
-            g.markdown.convert('''\
+            g.markdown.convert(dedent('''\
     Regular text
     1. first item
-    2. second item''') ==
+    2. second item''')) ==
             '<div class="markdown_content"><p>Regular text<br/>\n'
             '1. first item<br/>\n'
             '2. second item</p></div>')


[allura] 05/05: fixup! fixup! fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion

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

dill0wn pushed a commit to branch dw/8455
in repository https://gitbox.apache.org/repos/asf/allura.git

commit a2aaab866fd482ad5f12358eef783ff96aa0be6d
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Thu Sep 15 13:46:24 2022 +0000

    fixup! fixup! fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion
---
 Allura/allura/tests/test_plugin.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 56b358a79..f11eae8d7 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -288,7 +288,6 @@ class TestThemeProvider:
 
     @patch('allura.app.g')
     @patch('allura.lib.plugin.g')
-    # FIXME: check with dave.
     def test_app_icon_str(self, plugin_g, app_g):
         plugin_g.entry_points = {'tool': {'testapp': ThemeProviderTestApp}}
         app_icon = ThemeProvider().app_icon_url('testapp', 24)


[allura] 04/05: fixup! fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion

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

dill0wn pushed a commit to branch dw/8455
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 8effcc6bde8e7685885f72955bfffc6d816af90c
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Thu Sep 15 13:44:16 2022 +0000

    fixup! fixup! [#8455] allura pytest - fix misc test failures that popped up during pytest conversion
---
 Allura/allura/lib/macro.py          | 15 ++++++++-------
 Allura/allura/model/project.py      | 20 +++++++++++++++++++-
 Allura/allura/tests/test_globals.py | 25 ++++++++++++++++++++-----
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index b1af50297..0e293037e 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -177,14 +177,15 @@ def project_blog_posts(max_number=5, sort='timestamp', summary=False, mount_poin
         'state': 'published',
     })
     posts = posts.sort(sort, pymongo.DESCENDING).limit(int(max_number)).all()
-    output = ((dict(
-        href=post.url(),
-        title=post.title,
-        author=post.author().display_name,
-        ago=h.ago(post.timestamp),
-        description=summary and '&nbsp;' or g.markdown.cached_convert(post, 'text')))
+    output = [
+        dict(href=post.url(),
+             title=post.title,
+             author=post.author().display_name,
+             ago=h.ago(post.timestamp),
+             description=summary and '&nbsp;' or g.markdown.cached_convert(post, 'text'))
         for post in posts if security.has_access(post, 'read', project=post.app.project)() and
-        security.has_access(post.app.project, 'read', project=post.app.project)())
+            security.has_access(post.app.project, 'read', project=post.app.project)()
+    ]
     posts = BlogPosts(posts=output)
     g.resource_manager.register(posts)
     response = posts.display(posts=output)
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index c0a010f5e..66b265e80 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -1102,12 +1102,30 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             ThreadLocalORMSession.flush_all()
 
     def add_user(self, user, role_names):
-        'Convenience method to add member with the given role(s).'
+        '''Convenience method to add member with the given role(s).'''
         pr = ProjectRole.by_user(user, project=self, upsert=True)
         for role_name in role_names:
             r = ProjectRole.by_name(role_name, self)
             pr.roles.append(r._id)
 
+    def remove_user(self, user, role_names=None):
+        '''Convenience method to add member with the given role(s).'''
+        pr = ProjectRole.by_user(user, project=self)
+        if not pr:
+            return
+
+        if not role_names or not isinstance(role_names, Iterable):
+            ProjectRole.query.remove({'_id': pr._id})
+            return
+
+        for role_name in role_names:
+            r = ProjectRole.by_name(role_name, self)
+            if r._id in pr.roles:
+                pr.roles.remove(r._id)
+
+        if not pr.roles:
+            pr.remove()
+
     @property
     def twitter_handle(self):
         return self.social_account('Twitter').accounturl
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 172c1c57b..389c7a228 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -49,11 +49,6 @@ from forgewiki import model as WM
 from forgeblog import model as BM
 
 
-def setup_module(module):
-    setup_basic_test()
-    setup_unit_test()
-
-
 def squish_spaces(text):
     # \s is whitespace
     # \xa0 is &nbsp; in unicode form
@@ -85,8 +80,28 @@ def get_projects_property_in_the_same_order(names, prop):
 @with_nose_compatibility
 class Test():
 
+    @classmethod
+    def setup_class(cls):
+        setup_basic_test()
+        setup_global_objects()
+
     def setup_method(self, method):
         setup_global_objects()
+        p_nbhd = M.Neighborhood.query.get(name='Projects')
+        p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+        self.acl_bak = p_test.acl.copy()
+
+    def teardown_method(self, method):
+        user = M.User.by_username('test-admin')
+        user.display_name = 'Test Admin'
+
+        p_nbhd = M.Neighborhood.query.get(name='Projects')
+        p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+        p_test.remove_user(M.User.by_username('test-user'))
+        p_test.remove_user(M.User.by_username('test-user-0'))
+        p_test.acl = self.acl_bak
+
+        ThreadLocalORMSession.flush_all()
 
     @td.with_wiki
     def test_app_globals(self):