Move code out of __init__.py
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 17 Nov 2020 20:13:46 +0000 (14:13 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 17 Nov 2020 20:13:46 +0000 (14:13 -0600)
src/pgwui_upload/__init__.py
src/pgwui_upload/pgwui_upload.py [new file with mode: 0644]
tests/test___init__.py [deleted file]
tests/test_pgwui_upload.py [new file with mode: 0644]

index b5fb682aa20ef0077e5931849031be92d98170f3..4a95019f02303191aae972c616347c18349d09e5 100644 (file)
 
 # Karl O. Pinc <kop@karlpinc.com>
 
-'''Provide a way to configure PGWUI.
-'''
-PGWUI_COMPONENT = 'pgwui_upload'
-DEFAULT_UPLOAD_ROUTE = '/upload'
-DEFAULT_UPLOAD_MENU_LABEL = 'upload -- Upload File Into Database'
-
-
-def init_menu(config):
-    '''Add default menu information into settings when they are not present
-    '''
-    settings = config.get_settings()
-    pgwui = settings.setdefault('pgwui', dict())
-    pgwui.setdefault(PGWUI_COMPONENT, dict())
-    pgwui[PGWUI_COMPONENT].setdefault(
-        'menu_label', DEFAULT_UPLOAD_MENU_LABEL)
-
-
-def includeme(config):
-    '''Pyramid configuration for PGWUI_Upload
-    '''
-    init_menu(config)
-    config.add_route(PGWUI_COMPONENT, DEFAULT_UPLOAD_ROUTE)
-    config.scan()
+from .pgwui_upload import includeme        # noqa: F401
diff --git a/src/pgwui_upload/pgwui_upload.py b/src/pgwui_upload/pgwui_upload.py
new file mode 100644 (file)
index 0000000..b5fb682
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright (C) 2018, 2020 The Meme Factory, Inc.  http://www.karlpinc.com/
+
+# This file is part of PGWUI_Upload.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+'''Provide a way to configure PGWUI.
+'''
+PGWUI_COMPONENT = 'pgwui_upload'
+DEFAULT_UPLOAD_ROUTE = '/upload'
+DEFAULT_UPLOAD_MENU_LABEL = 'upload -- Upload File Into Database'
+
+
+def init_menu(config):
+    '''Add default menu information into settings when they are not present
+    '''
+    settings = config.get_settings()
+    pgwui = settings.setdefault('pgwui', dict())
+    pgwui.setdefault(PGWUI_COMPONENT, dict())
+    pgwui[PGWUI_COMPONENT].setdefault(
+        'menu_label', DEFAULT_UPLOAD_MENU_LABEL)
+
+
+def includeme(config):
+    '''Pyramid configuration for PGWUI_Upload
+    '''
+    init_menu(config)
+    config.add_route(PGWUI_COMPONENT, DEFAULT_UPLOAD_ROUTE)
+    config.scan()
diff --git a/tests/test___init__.py b/tests/test___init__.py
deleted file mode 100644 (file)
index a2e6bc1..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-# Copyright (C) 2019, 2020 The Meme Factory, Inc.  http://www.karlpinc.com/
-
-# This file is part of PGWUI_Upload.
-#
-# This program is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Affero General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program.  If not, see
-# <http://www.gnu.org/licenses/>.
-#
-
-# Karl O. Pinc <kop@karlpinc.com>
-
-import pyramid.testing
-
-import pgwui_upload.__init__ as pgwui_upload_init
-
-from pgwui_testing import testing
-
-# Activiate our pytest plugin
-pytest_plugins = ("pgwui",)
-
-
-# Module packaging test
-
-def test_pgwui_upload_is_pgwui_component(pgwui_component_entry_point):
-    '''Ensure that pgwui_upload is a pgwui.component entry point
-    '''
-    assert pgwui_component_entry_point('pgwui_upload') is True
-
-
-# init_menu()
-
-def test_init_menu_default():
-    '''The settings get the module's default value when no settings exist
-    '''
-    with pyramid.testing.testConfig() as config:
-
-        pgwui_upload_init.init_menu(config)
-
-        new_settings = config.get_settings()
-    assert new_settings['pgwui']['pgwui_upload']['menu_label'] \
-        == pgwui_upload_init.DEFAULT_UPLOAD_MENU_LABEL
-
-
-def test_init_menu_no_default():
-    '''The settings keep their value when they exist
-    '''
-    test_menu_label = 'test label'
-
-    with pyramid.testing.testConfig() as config:
-        sample_settings = config.get_settings()
-
-        sample_settings['pgwui'] = dict()
-        sample_settings['pgwui']['pgwui_upload'] = dict()
-        sample_settings['pgwui']['pgwui_upload']['menu_label'] \
-            = test_menu_label
-
-        pgwui_upload_init.init_menu(config)
-
-        new_settings = config.get_settings()
-    assert new_settings['pgwui']['pgwui_upload']['menu_label'] \
-        == test_menu_label
-
-
-mock_init_menu = testing.make_mock_fixture(pgwui_upload_init, 'init_menu')
-
-
-# includeme()
-
-mock_add_route = testing.instance_method_mock_fixture('add_route')
-mock_scan = testing.instance_method_mock_fixture('scan')
-
-
-def test_includeme(mock_init_menu, mock_add_route, mock_scan):
-    '''init_menu, add_route, and scan are all called
-    '''
-    with pyramid.testing.testConfig() as config:
-        mocked_add_route = mock_add_route(config)
-        mocked_scan = mock_scan(config)
-
-        pgwui_upload_init.includeme(config)
-
-    mock_init_menu.assert_called_once()
-    mocked_add_route.assert_called_once()
-    mocked_scan.assert_called_once()
diff --git a/tests/test_pgwui_upload.py b/tests/test_pgwui_upload.py
new file mode 100644 (file)
index 0000000..131a5d3
--- /dev/null
@@ -0,0 +1,94 @@
+# Copyright (C) 2019, 2020 The Meme Factory, Inc.  http://www.karlpinc.com/
+
+# This file is part of PGWUI_Upload.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+import pyramid.testing
+
+import pgwui_upload.pgwui_upload as pgwui_upload
+
+from pgwui_testing import testing
+
+# Activiate our pytest plugin
+pytest_plugins = ("pgwui",)
+
+
+# Module packaging test
+
+def test_pgwui_upload_is_pgwui_component(pgwui_component_entry_point):
+    '''Ensure that pgwui_upload is a pgwui.component entry point
+    '''
+    assert pgwui_component_entry_point('pgwui_upload') is True
+
+
+# init_menu()
+
+def test_init_menu_default():
+    '''The settings get the module's default value when no settings exist
+    '''
+    with pyramid.testing.testConfig() as config:
+
+        pgwui_upload.init_menu(config)
+
+        new_settings = config.get_settings()
+    assert new_settings['pgwui']['pgwui_upload']['menu_label'] \
+        == pgwui_upload.DEFAULT_UPLOAD_MENU_LABEL
+
+
+def test_init_menu_no_default():
+    '''The settings keep their value when they exist
+    '''
+    test_menu_label = 'test label'
+
+    with pyramid.testing.testConfig() as config:
+        sample_settings = config.get_settings()
+
+        sample_settings['pgwui'] = dict()
+        sample_settings['pgwui']['pgwui_upload'] = dict()
+        sample_settings['pgwui']['pgwui_upload']['menu_label'] \
+            = test_menu_label
+
+        pgwui_upload.init_menu(config)
+
+        new_settings = config.get_settings()
+    assert new_settings['pgwui']['pgwui_upload']['menu_label'] \
+        == test_menu_label
+
+
+mock_init_menu = testing.make_mock_fixture(pgwui_upload, 'init_menu')
+
+
+# includeme()
+
+mock_add_route = testing.instance_method_mock_fixture('add_route')
+mock_scan = testing.instance_method_mock_fixture('scan')
+
+
+def test_includeme(mock_init_menu, mock_add_route, mock_scan):
+    '''init_menu, add_route, and scan are all called
+    '''
+    with pyramid.testing.testConfig() as config:
+        mocked_add_route = mock_add_route(config)
+        mocked_scan = mock_scan(config)
+
+        pgwui_upload.includeme(config)
+
+    mock_init_menu.assert_called_once()
+    mocked_add_route.assert_called_once()
+    mocked_scan.assert_called_once()