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/30 01:17:50 UTC

[allura] 01/05: fixup! fixup! fixup! [#8455] remove @with_setup

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

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

commit e26ca2e2b60e5e1057e0d05fa1de2734e32bd05a
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Fri Sep 30 00:30:54 2022 +0000

    fixup! fixup! fixup! [#8455] remove @with_setup
---
 Allura/allura/tests/test_app.py | 295 +++++++++++++++++++---------------------
 1 file changed, 143 insertions(+), 152 deletions(-)

diff --git a/Allura/allura/tests/test_app.py b/Allura/allura/tests/test_app.py
index 71733a2d5..8a6924ce2 100644
--- a/Allura/allura/tests/test_app.py
+++ b/Allura/allura/tests/test_app.py
@@ -20,161 +20,152 @@ import mock
 from ming.base import Object
 import pytest
 from formencode import validators as fev
+from textwrap import dedent
 
 from alluratest.controller import setup_unit_test
 from alluratest.tools import with_setup
 from allura import app
 from allura.lib.app_globals import Icon
 from allura.lib import mail_util
-from alluratest.pytest_helpers import with_nose_compatibility
-
-
-def setup_method():
-    setup_unit_test()
-    c.user._id = None
-    c.project = mock.Mock()
-    c.project.name = 'Test Project'
-    c.project.shortname = 'tp'
-    c.project._id = 'testproject/'
-    c.project.url = lambda: '/testproject/'
-    app_config = mock.Mock()
-    app_config._id = None
-    app_config.project_id = 'testproject/'
-    app_config.tool_name = 'tool'
-    app_config.options = Object(mount_point='foo')
-    c.app = mock.Mock()
-    c.app.config = app_config
-    c.app.config.script_name = lambda: '/testproject/test_application/'
-    c.app.config.url = lambda: 'http://testproject/test_application/'
-    c.app.url = c.app.config.url()
-    c.app.__version__ = '0.0'
-
-def test_config_options():
-    options = [
-        app.ConfigOption('test1', str, 'MyTestValue'),
-        app.ConfigOption('test2', str, lambda:'MyTestValue')]
-    assert options[0].default == 'MyTestValue'
-    assert options[1].default == 'MyTestValue'
-
-
-def test_config_options_render_attrs():
-    opt = app.ConfigOption('test1', str, None, extra_attrs={'type': 'url'})
-    assert opt.render_attrs() == 'type="url"'
-
-
-def test_config_option_without_validator():
-    opt = app.ConfigOption('test1', str, None)
-    assert opt.validate(None) == None
-    assert opt.validate('') == ''
-    assert opt.validate('val') == 'val'
-
-
-def test_config_option_with_validator():
-    v = fev.NotEmpty()
-    opt = app.ConfigOption('test1', str, None, validator=v)
-    assert opt.validate('val') == 'val'
-    pytest.raises(fev.Invalid, opt.validate, None)
-    pytest.raises(fev.Invalid, opt.validate, '')
-
-
-@with_setup(setup_method)
-def test_options_on_install_default():
-    a = app.Application(c.project, c.app.config)
-    assert a.options_on_install() == []
-
-
-@with_setup(setup_method)
-def test_options_on_install():
-    opts = [app.ConfigOption('url', str, None),
-            app.ConfigOption('private', bool, None)]
-    class TestApp(app.Application):
-        config_options = app.Application.config_options + opts + [
-            app.ConfigOption('not_on_install', str, None),
-        ]
-        config_on_install = ['url', 'private']
-
-    a = TestApp(c.project, c.app.config)
-    assert a.options_on_install() == opts
-
-@with_setup(setup_method)
-def test_main_menu():
-    class TestApp(app.Application):
-        @property
-        def sitemap(self):
-            children = [app.SitemapEntry('New', 'new', ui_icon=Icon('some-icon')),
-                        app.SitemapEntry('Recent', 'recent'),
-                        ]
-            return [app.SitemapEntry('My Tool', '.')[children]]
-
-    a = TestApp(c.project, c.app.config)
-    main_menu = a.main_menu()
-    assert len(main_menu) == 1
-    assert main_menu[0].children == []  # default main_menu implementation should drop the children from sitemap()
-
-
-@with_setup(setup_method)
-def test_sitemap():
-    sm = app.SitemapEntry('test', '')[
-        app.SitemapEntry('a', 'a/'),
-        app.SitemapEntry('b', 'b/')]
-    sm[app.SitemapEntry(lambda app:app.config.script_name(), 'c/')]
-    bound_sm = sm.bind_app(c.app)
-    assert bound_sm.url == 'http://testproject/test_application/', bound_sm.url
-    assert bound_sm.children[
-        -1].label == '/testproject/test_application/', bound_sm.children[-1].label
-    assert len(sm.children) == 3
-    sm.extend([app.SitemapEntry('a', 'a/')[
-        app.SitemapEntry('d', 'd/')]])
-    assert len(sm.children) == 3
-
-
-@with_setup(setup_method)
-@mock.patch('allura.app.Application.PostClass.query.get')
-def test_handle_artifact_unicode(qg):
-    """
-    Tests that app.handle_artifact_message can accept utf strings
-    """
-    ticket = mock.MagicMock()
-    ticket.get_discussion_thread.return_value = (mock.MagicMock(), mock.MagicMock())
-    post = mock.MagicMock()
-    qg.return_value = post
-
-    a = app.Application(c.project, c.app.config)
-
-    msg = dict(payload='foo ƒ†©¥˙¨ˆ'.encode(), message_id=1, headers={})
-    a.handle_artifact_message(ticket, msg)
-    assert post.attach.call_args[0][1].getvalue() == 'foo ƒ†©¥˙¨ˆ'.encode()
-
-    msg = dict(payload=b'foo', message_id=1, headers={})
-    a.handle_artifact_message(ticket, msg)
-    assert post.attach.call_args[0][1].getvalue() == b'foo'
-
-    msg = dict(payload="\x94my quote\x94".encode(), message_id=1, headers={})
-    a.handle_artifact_message(ticket, msg)
-    assert post.attach.call_args[0][1].getvalue() == '\x94my quote\x94'.encode()
-
-    # assert against prod example
-    msg_raw = """Message-Id: <15...@webmail.messagingengine.com>
-From: foo <fo...@bar.com>
-To: "[forge:site-support]" <15...@site-support.forge.p.re.sf.net>
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-Content-Type: multipart/alternative; boundary="_----------=_150235203132168580"
-Date: Thu, 10 Aug 2017 10:00:31 +0200
-Subject: Re: [forge:site-support] #15391 Unable to join (my own) mailing list
-This is a multi-part message in MIME format.
---_----------=_150235203132168580
-Content-Transfer-Encoding: quoted-printable
-Content-Type: text/plain; charset="utf-8"
-Hi
---_----------=_150235203132168580
-Content-Transfer-Encoding: quoted-printable
-Content-Type: text/html; charset="utf-8"
-<!DOCTYPE html>
-<html><body>Hi</body></html>
---_----------=_150235203132168580--
-    """
-    msg = mail_util.parse_message(msg_raw)
-    for p in [p for p in msg['parts'] if p['payload'] is not None]:
-        # filter here mimics logic in `route_email`
-        a.handle_artifact_message(ticket, p)
+
+
+class TestApp:
+
+    def setup_method(self):
+        setup_unit_test()
+        c.user._id = None
+        c.project = mock.Mock()
+        c.project.name = 'Test Project'
+        c.project.shortname = 'tp'
+        c.project._id = 'testproject/'
+        c.project.url = lambda: '/testproject/'
+        app_config = mock.Mock()
+        app_config._id = None
+        app_config.project_id = 'testproject/'
+        app_config.tool_name = 'tool'
+        app_config.options = Object(mount_point='foo')
+        c.app = mock.Mock()
+        c.app.config = app_config
+        c.app.config.script_name = lambda: '/testproject/test_application/'
+        c.app.config.url = lambda: 'http://testproject/test_application/'
+        c.app.url = c.app.config.url()
+        c.app.__version__ = '0.0'
+
+    def test_config_options(self):
+        options = [
+            app.ConfigOption('test1', str, 'MyTestValue'),
+            app.ConfigOption('test2', str, lambda:'MyTestValue')]
+        assert options[0].default == 'MyTestValue'
+        assert options[1].default == 'MyTestValue'
+
+    def test_config_options_render_attrs(self):
+        opt = app.ConfigOption('test1', str, None, extra_attrs={'type': 'url'})
+        assert opt.render_attrs() == 'type="url"'
+
+    def test_config_option_without_validator(self):
+        opt = app.ConfigOption('test1', str, None)
+        assert opt.validate(None) == None
+        assert opt.validate('') == ''
+        assert opt.validate('val') == 'val'
+
+    def test_config_option_with_validator(self):
+        v = fev.NotEmpty()
+        opt = app.ConfigOption('test1', str, None, validator=v)
+        assert opt.validate('val') == 'val'
+        pytest.raises(fev.Invalid, opt.validate, None)
+        pytest.raises(fev.Invalid, opt.validate, '')
+
+    def test_options_on_install_default(self):
+        a = app.Application(c.project, c.app.config)
+        assert a.options_on_install() == []
+
+    def test_options_on_install(self):
+        opts = [app.ConfigOption('url', str, None),
+                app.ConfigOption('private', bool, None)]
+        class TestApp(app.Application):
+            config_options = app.Application.config_options + opts + [
+                app.ConfigOption('not_on_install', str, None),
+            ]
+            config_on_install = ['url', 'private']
+
+        a = TestApp(c.project, c.app.config)
+        assert a.options_on_install() == opts
+
+    def test_main_menu(self):
+        class TestApp(app.Application):
+            @property
+            def sitemap(self):
+                children = [app.SitemapEntry('New', 'new', ui_icon=Icon('some-icon')),
+                            app.SitemapEntry('Recent', 'recent'),
+                            ]
+                return [app.SitemapEntry('My Tool', '.')[children]]
+
+        a = TestApp(c.project, c.app.config)
+        main_menu = a.main_menu()
+        assert len(main_menu) == 1
+        assert main_menu[0].children == []  # default main_menu implementation should drop the children from sitemap()
+
+    def test_sitemap(self):
+        sm = app.SitemapEntry('test', '')[
+            app.SitemapEntry('a', 'a/'),
+            app.SitemapEntry('b', 'b/')]
+        sm[app.SitemapEntry(lambda app:app.config.script_name(), 'c/')]
+        bound_sm = sm.bind_app(c.app)
+        assert bound_sm.url == 'http://testproject/test_application/', bound_sm.url
+        assert bound_sm.children[
+            -1].label == '/testproject/test_application/', bound_sm.children[-1].label
+        assert len(sm.children) == 3
+        sm.extend([app.SitemapEntry('a', 'a/')[
+            app.SitemapEntry('d', 'd/')]])
+        assert len(sm.children) == 3
+
+    @mock.patch('allura.app.Application.PostClass.query.get')
+    def test_handle_artifact_unicode(self, qg):
+        """
+        Tests that app.handle_artifact_message can accept utf strings
+        """
+        ticket = mock.MagicMock()
+        ticket.get_discussion_thread.return_value = (mock.MagicMock(), mock.MagicMock())
+        post = mock.MagicMock()
+        qg.return_value = post
+
+        a = app.Application(c.project, c.app.config)
+
+        msg = dict(payload='foo ƒ†©¥˙¨ˆ'.encode(), message_id=1, headers={})
+        a.handle_artifact_message(ticket, msg)
+        assert post.attach.call_args[0][1].getvalue() == 'foo ƒ†©¥˙¨ˆ'.encode()
+
+        msg = dict(payload=b'foo', message_id=1, headers={})
+        a.handle_artifact_message(ticket, msg)
+        assert post.attach.call_args[0][1].getvalue() == b'foo'
+
+        msg = dict(payload="\x94my quote\x94".encode(), message_id=1, headers={})
+        a.handle_artifact_message(ticket, msg)
+        assert post.attach.call_args[0][1].getvalue() == '\x94my quote\x94'.encode()
+
+        # assert against prod example
+        msg_raw = dedent("""\
+            Message-Id: <15...@webmail.messagingengine.com>
+            From: foo <fo...@bar.com>
+            To: "[forge:site-support]" <15...@site-support.forge.p.re.sf.net>
+            MIME-Version: 1.0
+            Content-Transfer-Encoding: 7bit
+            Content-Type: multipart/alternative; boundary="_----------=_150235203132168580"
+            Date: Thu, 10 Aug 2017 10:00:31 +0200
+            Subject: Re: [forge:site-support] #15391 Unable to join (my own) mailing list
+            This is a multi-part message in MIME format.
+            --_----------=_150235203132168580
+            Content-Transfer-Encoding: quoted-printable
+            Content-Type: text/plain; charset="utf-8"
+            Hi
+            --_----------=_150235203132168580
+            Content-Transfer-Encoding: quoted-printable
+            Content-Type: text/html; charset="utf-8"
+            <!DOCTYPE html>
+            <html><body>Hi</body></html>
+            --_----------=_150235203132168580--
+        """)
+        msg = mail_util.parse_message(msg_raw)
+        for p in [p for p in msg['parts'] if p['payload'] is not None]:
+            # filter here mimics logic in `route_email`
+            a.handle_artifact_message(ticket, p)