Use pgwui_common.path for asset resolution
authorKarl O. Pinc <kop@meme.com>
Wed, 14 Nov 2018 03:37:10 +0000 (21:37 -0600)
committerKarl O. Pinc <kop@meme.com>
Wed, 14 Nov 2018 03:37:10 +0000 (21:37 -0600)
src/pgwui_common/path.py [new file with mode: 0644]
src/pgwui_common/templates/auth_base.mak
tests/test_path.py [new file with mode: 0644]

diff --git a/src/pgwui_common/path.py b/src/pgwui_common/path.py
new file mode 100644 (file)
index 0000000..d8f427e
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright (C) 2018 The Meme Factory, Inc.  http://www.meme.com/
+
+# This file is part of PGWUI_Common.
+#
+# 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@meme.com>
+
+'''Path library for PGWUI
+'''
+from pyramid.path import AssetResolver
+
+
+def asset_abspath(asset):
+    '''Return the absolute path of a pyramid asset
+    '''
+    asset_resolver = AssetResolver(None)
+    return asset_resolver.resolve(asset).abspath()
index 095e98749b534ae664f3cbd8a9510d32e6e0676f..9edac7ef7214e5e41ddf3a8a62d461b77af1d360 100644 (file)
 </%doc>
 
 <%!
-    from pyramid.path import AssetResolver
+    from pgwui_common.path import asset_abspath
 
-    asset_resolver = AssetResolver(None)
-    base_mak = (asset_resolver.resolve('pgwui_common:templates/base.mak')
-                .abspath())
+    base_mak = asset_abspath('pgwui_common:templates/base.mak')
 %>
 
 <%inherit file="${base_mak}" />
diff --git a/tests/test_path.py b/tests/test_path.py
new file mode 100644 (file)
index 0000000..6a73059
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright (C) 2018 The Meme Factory, Inc.  http://www.meme.com/
+
+# This file is part of PGWUI_Common.
+#
+# 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@meme.com>
+
+from pyramid.path import AssetResolver
+
+import pgwui_common.path
+
+
+# Integration tests
+
+# asset_abspath()
+
+def test_asset_abspath():
+    '''Returns what pyramid's asset resolver returns'''
+    asset_resolver = AssetResolver(None)
+    asset = 'pgwui_common:templates/base.mk'
+    answer = asset_resolver.resolve(asset).abspath()
+    result = pgwui_common.path.asset_abspath(asset)
+    assert result == answer