From edc1d334f2226bc5e2b4b8844ccb2e5be37dd2c2 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 13 Nov 2018 21:37:10 -0600 Subject: [PATCH] Use pgwui_common.path for asset resolution --- src/pgwui_common/path.py | 31 ++++++++++++++++++++ src/pgwui_common/templates/auth_base.mak | 6 ++-- tests/test_path.py | 37 ++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/pgwui_common/path.py create mode 100644 tests/test_path.py diff --git a/src/pgwui_common/path.py b/src/pgwui_common/path.py new file mode 100644 index 0000000..d8f427e --- /dev/null +++ b/src/pgwui_common/path.py @@ -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 +# . +# + +# Karl O. Pinc + +'''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() diff --git a/src/pgwui_common/templates/auth_base.mak b/src/pgwui_common/templates/auth_base.mak index 095e987..9edac7e 100644 --- a/src/pgwui_common/templates/auth_base.mak +++ b/src/pgwui_common/templates/auth_base.mak @@ -37,11 +37,9 @@ <%! - 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 index 0000000..6a73059 --- /dev/null +++ b/tests/test_path.py @@ -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 +# . +# + +# Karl O. Pinc + +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 -- 2.34.1