Skip to content

Commit

Permalink
MAINT: Set up product config via dict instead of str
Browse files Browse the repository at this point in the history
  • Loading branch information
wosc committed Sep 9, 2024
1 parent 0474942 commit 7736f3f
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 356 deletions.
31 changes: 12 additions & 19 deletions core/src/zeit/brightcove/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@
import zeit.content.video.testing


product_config = """\
<product-config zeit.brightcove>
api-url none
oauth-url none
client-id none
client-secret none
timeout 300
playback-url none
playback-policy-key none
playback-timeout 3
video-folder video
index-principal zope.user
</product-config>
"""


class MockAPILayer(plone.testing.Layer):
def setUp(self):
self.cmsapi_patch = mock.patch('zeit.brightcove.connection.CMSAPI._request')
Expand All @@ -41,7 +23,18 @@ def tearDown(self):

MOCK_API_LAYER = MockAPILayer()
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
product_config,
{
'api-url': 'none',
'oauth-url': 'none',
'client-id': 'none',
'client-secret': 'none',
'timeout': '300',
'playback-url': 'none',
'playback-policy-key': 'none',
'playback-timeout': '3',
'video-folder': 'video',
'index-principal': 'zope.user',
},
patches={'zeit.cms': {'task-queue-brightcove': 'brightcove'}},
bases=(zeit.content.video.testing.CONFIG_LAYER,),
)
Expand Down
12 changes: 4 additions & 8 deletions core/src/zeit/campus/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
import zeit.push.testing


product_config = """\
<product-config zeit.campus>
article-stoa-source file://{here}/tests/article-stoa.xml
</product-config>
""".format(here=importlib.resources.files(__package__))


HERE = importlib.resources.files(__package__)
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
product_config,
{
'article-stoa-source': f'file://{HERE}/tests/article-stoa.xml',
},
bases=(
zeit.content.article.testing.CONFIG_LAYER,
zeit.content.link.testing.CONFIG_LAYER,
Expand Down
5 changes: 2 additions & 3 deletions core/src/zeit/cmp/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import zeit.cms.testing


HERE = importlib.resources.files(__package__)
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
{
'vendors': 'file://{here}/tests/fixtures/vendors.xml'.format(
here=importlib.resources.files(__package__)
)
'vendors': f'file://{HERE}/tests/fixtures/vendors.xml',
},
bases=(zeit.cms.testing.CONFIG_LAYER,),
)
Expand Down
88 changes: 35 additions & 53 deletions core/src/zeit/cms/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from io import StringIO
from urllib.parse import urljoin
import base64
import contextlib
Expand Down Expand Up @@ -98,14 +97,9 @@ def __init__(
if not package:
package = '.'.join(module.split('.')[:-1])
self.package = package
if isinstance(config, str): # BBB
config = self.loadConfiguration(config, package)
self.config = config
self.patches = patches or {}

def loadConfiguration(self, text, package):
return zope.app.appsetup.product.loadConfiguration(StringIO(text))[package]

def setUp(self):
self.previous = {}

Expand Down Expand Up @@ -541,54 +535,42 @@ def testSetUp(self):
self['request_handler'].response_code = 200


cms_product_config = """\
<product-config zeit.cms>
environment testing
source-access file://{here}/content/access.xml
source-serie file://{here}/content/serie.xml
source-ressorts file://{here}/content/ressorts.xml
source-keyword file://{here}/content/zeit-ontologie-prism.xml
source-products file://{here}/content/products.xml
source-badges file://{here}/asset/badges.xml
source-channels file://{here}/content/ressorts.xml
source-printressorts file://{here}/content/print-ressorts.xml
source-manual file://{here}/content/manual.xml
config-retractlog file://{here}/retractlog/retractlog.xml
checkout-lock-timeout 3600
checkout-lock-timeout-temporary 30
preview-prefix http://localhost/preview-prefix/
live-prefix http://localhost/live-prefix/
image-live-prefix http://localhost/img-live-prefix/
friebert-wc-preview-prefix /wcpreview
breadcrumbs-use-common-metadata true
cache-regions config, feature, newsimport, dav
cache-expiration-config 600
cache-expiration-feature 15
cache-expiration-newsimport 1
cache-expiration-dav 0
feature-toggle-source file://{here}/content/feature-toggle.xml
sso-cookie-name-prefix my_sso_
sso-cookie-domain
sso-expiration 300
sso-algorithm RS256
sso-private-key-file {here}/tests/sso-private.pem
source-api-mapping product=zeit.cms.content.sources.ProductSource
# We just need a dummy XML file
checkin-webhook-config file://{here}/content/access.xml
</product-config>
""".format(here=importlib.resources.files(__package__))


HERE = importlib.resources.files(__package__)
CONFIG_LAYER = ProductConfigLayer(
cms_product_config,
{
'environment': 'testing',
'source-access': f'file://{HERE}/content/access.xml',
'source-serie': f'file://{HERE}/content/serie.xml',
'source-ressorts': f'file://{HERE}/content/ressorts.xml',
'source-keyword': f'file://{HERE}/content/zeit-ontologie-prism.xml',
'source-products': f'file://{HERE}/content/products.xml',
'source-badges': f'file://{HERE}/asset/badges.xml',
'source-channels': f'file://{HERE}/content/ressorts.xml',
'source-printressorts': f'file://{HERE}/content/print-ressorts.xml',
'source-manual': f'file://{HERE}/content/manual.xml',
'config-retractlog': f'file://{HERE}/retractlog/retractlog.xml',
'checkout-lock-timeout': '3600',
'checkout-lock-timeout-temporary': '30',
'preview-prefix': 'http://localhost/preview-prefix/',
'live-prefix': 'http://localhost/live-prefix/',
'image-live-prefix': 'http://localhost/img-live-prefix/',
'friebert-wc-preview-prefix': '/wcpreview',
'breadcrumbs-use-common-metadata': 'true',
'cache-regions': 'config, feature, newsimport, dav',
'cache-expiration-config': '600',
'cache-expiration-feature': '15',
'cache-expiration-newsimport': '1',
'cache-expiration-dav': '0',
'feature-toggle-source': f'file://{HERE}/content/feature-toggle.xml',
'sso-cookie-name-prefix': 'my_sso_',
'sso-cookie-domain': '',
'sso-expiration': '300',
'sso-algorithm': 'RS256',
'sso-private-key-file': f'{HERE}/tests/sso-private.pem',
'source-api-mapping': 'product=zeit.cms.content.sources.ProductSource',
# We just need a dummy XML file
'checkin-webhook-config': f'file://{HERE}/content/access.xml',
},
patches={
'zeit.connector': {
'repository-path': str((importlib.resources.files('zeit.connector') / 'testcontent'))
Expand Down
55 changes: 25 additions & 30 deletions core/src/zeit/content/article/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,38 @@
import zeit.wochenmarkt.testing


product_config = """
<product-config zeit.content.article>
zeit-comments-api-url https://comments.staging.zeit.de
book-recension-categories file://{here}/tests/recension_categories.xml
genre-url file://{here}/tests/article-genres.xml
image-display-mode-source file://{here}/edit/tests/image-display-modes.xml
legacy-display-mode-source file://{here}/edit/tests/legacy-display-modes.xml
image-variant-name-source file://{here}/edit/tests/image-variant-names.xml
legacy-variant-name-source file://{here}/edit/tests/legacy-variant-names.xml
video-layout-source file://{here}/edit/tests/video-layouts.xml
infobox-layout-source file://{here}/edit/tests/infobox-layouts.xml
template-source file://{here}/edit/tests/templates.xml
module-source file://{here}/edit/tests/modules.xml
header-module-source file://{here}/edit/tests/header-modules.xml
topicbox-teaser-amount 5
citation-layout-source file://{here}/edit/tests/citation-layouts.xml
box-layout-source file://{here}/edit/tests/box-layouts.xml
puzzleforms-source file://{here}/edit/tests/puzzleforms.xml
topicpage-filter-source file://{here}/tests/topicpage-esqueries.json
config-here-url file://{here}/tests/
tagesschau-api-url-post https://ard-tagesschau/post
tagesschau-api-url-post-sync https://ard-tagesschau/post/sync
tagesschau-api-url-get https://ard-tagesschau/get
tagesschau-sig-uri XYZ
tagesschau-api-key 1a2b3c4d5e
</product-config>
""".format(here=importlib.resources.files(__package__))


checker = zope.testing.renormalizing.RENormalizing(
[(re.compile('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'), '<GUID>')]
)
checker.transformers[0:0] = zeit.cms.testing.checker.transformers


HERE = importlib.resources.files(__package__)
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
product_config,
{
'zeit-comments-api-url': 'https://comments.staging.zeit.de',
'book-recension-categories': f'file://{HERE}/tests/recension_categories.xml',
'genre-url': f'file://{HERE}/tests/article-genres.xml',
'image-display-mode-source': f'file://{HERE}/edit/tests/image-display-modes.xml',
'legacy-display-mode-source': f'file://{HERE}/edit/tests/legacy-display-modes.xml',
'image-variant-name-source': f'file://{HERE}/edit/tests/image-variant-names.xml',
'legacy-variant-name-source': f'file://{HERE}/edit/tests/legacy-variant-names.xml',
'video-layout-source': f'file://{HERE}/edit/tests/video-layouts.xml',
'infobox-layout-source': f'file://{HERE}/edit/tests/infobox-layouts.xml',
'template-source': f'file://{HERE}/edit/tests/templates.xml',
'module-source': f'file://{HERE}/edit/tests/modules.xml',
'header-module-source': f'file://{HERE}/edit/tests/header-modules.xml',
'topicbox-teaser-amount': '5',
'citation-layout-source': f'file://{HERE}/edit/tests/citation-layouts.xml',
'box-layout-source': f'file://{HERE}/edit/tests/box-layouts.xml',
'puzzleforms-source': f'file://{HERE}/edit/tests/puzzleforms.xml',
'topicpage-filter-source': f'file://{HERE}/tests/topicpage-esqueries.json',
'tagesschau-api-url-post': 'https://ard-tagesschau/post',
'tagesschau-api-url-post-sync': 'https://ard-tagesschau/post/sync',
'tagesschau-api-url-get': 'https://ard-tagesschau/get',
'tagesschau-sig-uri': 'XYZ',
'tagesschau-api-key': '1a2b3c4d5e',
},
bases=(
zeit.content.author.testing.CONFIG_LAYER,
zeit.content.gallery.testing.CONFIG_LAYER,
Expand Down
11 changes: 4 additions & 7 deletions core/src/zeit/content/audio/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

T = TypeVar('T') # Can be anything

product_config = """
<product-config zeit.content.audio>
podcast-source file://{here}/tests/fixtures/podcasts.xml
</product-config>
""".format(here=importlib.resources.files(__package__))

HERE = importlib.resources.files(__package__)
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
product_config,
{
'podcast-source': f'file://{HERE}/tests/fixtures/podcasts.xml',
},
bases=(zeit.cms.testing.CONFIG_LAYER,),
)

Expand Down
22 changes: 10 additions & 12 deletions core/src/zeit/content/author/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
import zeit.find.testing


product_config = """
<product-config zeit.content.author>
author-folder /foo/bar/authors
biography-questions file://{here}/tests/biography-questions.xml
roles file://{here}/tests/roles.xml
sso-api-url http://meine.fake/api/1
sso-user [email protected]
sso-password password
</product-config>
""".format(here=importlib.resources.files(__package__))

HERE = importlib.resources.files(__package__)
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
product_config, bases=(zeit.find.testing.CONFIG_LAYER,)
{
'author-folder': '/foo/bar/authors',
'biography-questions': f'file://{HERE}/tests/biography-questions.xml',
'roles': f'file://{HERE}/tests/roles.xml',
'sso-api-url': 'http://meine.fake/api/1',
'sso-user': '[email protected]',
'sso-password': 'password',
},
bases=(zeit.find.testing.CONFIG_LAYER,),
)


Expand Down
40 changes: 18 additions & 22 deletions core/src/zeit/content/cp/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,25 @@
import zeit.retresco.testhelper


product_config = """
<product-config zeit.content.cp>
block-layout-source file://{fixtures}/layout.xml
region-config-source file://{fixtures}/regions.xml
area-config-source file://{fixtures}/areas.xml
module-config-source file://{fixtures}/blocks.xml
cp-extra-url file://{fixtures}/cpextra.xml
cp-types-url file://{fixtures}/cp-types.xml
topicpage-filter-source file://{fixtures}/filter.json
layout-image-path /data/cp-layouts
layout-css-path /data/cp-layouts/layouts.css
header-image-variant cinema
cp-automatic-feed-source file://{fixtures}/feeds.xml
area-color-themes-source file://{fixtures}/area-color-themes.xml
reach-service-source file://{fixtures}/reach-services.xml
sql-query-add-clauses unsorted @@ '$$.workflow.published == "yes"' AND \
unsorted @@ '$$."zeit.content.gallery".type != "inline"'
</product-config>
""".format(fixtures='%s/tests/fixtures' % importlib.resources.files(__package__))


FIXTURES = importlib.resources.files(__package__) / 'tests/fixtures'
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
product_config,
{
'block-layout-source': f'file://{FIXTURES}/layout.xml',
'region-config-source': f'file://{FIXTURES}/regions.xml',
'area-config-source': f'file://{FIXTURES}/areas.xml',
'module-config-source': f'file://{FIXTURES}/blocks.xml',
'cp-extra-url': f'file://{FIXTURES}/cpextra.xml',
'cp-types-url': f'file://{FIXTURES}/cp-types.xml',
'topicpage-filter-source': f'file://{FIXTURES}/filter.json',
'layout-image-path': '/data/cp-layouts',
'layout-css-path': '/data/cp-layouts/layouts.css',
'header-image-variant': 'cinema',
'cp-automatic-feed-source': f'file://{FIXTURES}/feeds.xml',
'area-color-themes-source': f'file://{FIXTURES}/area-color-themes.xml',
'reach-service-source': f'file://{FIXTURES}/reach-services.xml',
'sql-query-add-clauses': """unsorted @@ '$.workflow.published == "yes"' \
AND unsorted @@ '$."zeit.content.gallery".type != "inline"'""",
},
patches={
'zeit.edit': {
'rules-url': 'file://%s/tests/fixtures/example_rules.py'
Expand Down
17 changes: 7 additions & 10 deletions core/src/zeit/content/gallery/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
import zeit.push.testing


product_config = """
<product-config zeit.content.gallery>
scale-source file://{here}/scales.xml
ticket-secret All work and no play makes jack a dull boy
gallery-types-url file://{here}/gallery-types.xml
</product-config>
""".format(here=importlib.resources.files(__package__))


HERE = importlib.resources.files(__package__)
CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer(
product_config, bases=(zeit.crop.testing.CONFIG_LAYER, zeit.push.testing.CONFIG_LAYER)
{
'scale-source': f'file://{HERE}/scales.xml',
'ticket-secret': 'All work and no play makes jack a dull boy',
'gallery-types-url': f'file://{HERE}/gallery-types.xml',
},
bases=(zeit.crop.testing.CONFIG_LAYER, zeit.push.testing.CONFIG_LAYER),
)
ZCML_LAYER = zeit.cms.testing.ZCMLLayer(bases=(CONFIG_LAYER,))
ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,))
Expand Down
Loading

0 comments on commit 7736f3f

Please sign in to comment.