From 7736f3f94203de1e866d58d60b4383645df86911 Mon Sep 17 00:00:00 2001 From: Wolfgang Schnerring Date: Mon, 9 Sep 2024 14:01:40 +0200 Subject: [PATCH] MAINT: Set up product config via dict instead of str --- core/src/zeit/brightcove/testing.py | 31 ++++----- core/src/zeit/campus/testing.py | 12 ++-- core/src/zeit/cmp/testing.py | 5 +- core/src/zeit/cms/testing.py | 88 ++++++++++-------------- core/src/zeit/content/article/testing.py | 55 +++++++-------- core/src/zeit/content/audio/testing.py | 11 ++- core/src/zeit/content/author/testing.py | 22 +++--- core/src/zeit/content/cp/testing.py | 40 +++++------ core/src/zeit/content/gallery/testing.py | 17 ++--- core/src/zeit/content/image/testing.py | 25 +++---- core/src/zeit/content/link/testing.py | 13 ++-- core/src/zeit/content/modules/testing.py | 21 +++--- core/src/zeit/content/volume/testing.py | 28 ++++---- core/src/zeit/crop/testing.py | 15 ++-- core/src/zeit/find/testing.py | 13 ++-- core/src/zeit/newsimport/testing.py | 14 ++-- core/src/zeit/push/testing.py | 32 ++++----- core/src/zeit/reach/testing.py | 12 ++-- core/src/zeit/retresco/testing.py | 43 ++++++------ core/src/zeit/simplecast/testing.py | 18 ++--- core/src/zeit/sourcepoint/testing.py | 15 ++-- core/src/zeit/speech/testing.py | 17 ++--- core/src/zeit/vgwort/testing.py | 27 +++----- core/src/zeit/wochenmarkt/testing.py | 14 ++-- core/src/zeit/workflow/testing.py | 19 +++-- 25 files changed, 251 insertions(+), 356 deletions(-) diff --git a/core/src/zeit/brightcove/testing.py b/core/src/zeit/brightcove/testing.py index 64173dbd79..ac6c4e2926 100644 --- a/core/src/zeit/brightcove/testing.py +++ b/core/src/zeit/brightcove/testing.py @@ -9,24 +9,6 @@ import zeit.content.video.testing -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 - -""" - - class MockAPILayer(plone.testing.Layer): def setUp(self): self.cmsapi_patch = mock.patch('zeit.brightcove.connection.CMSAPI._request') @@ -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,), ) diff --git a/core/src/zeit/campus/testing.py b/core/src/zeit/campus/testing.py index fcd3aad1fc..fb291e7e72 100644 --- a/core/src/zeit/campus/testing.py +++ b/core/src/zeit/campus/testing.py @@ -14,15 +14,11 @@ import zeit.push.testing -product_config = """\ - - article-stoa-source file://{here}/tests/article-stoa.xml - -""".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, diff --git a/core/src/zeit/cmp/testing.py b/core/src/zeit/cmp/testing.py index a083f1f34e..e899c1e468 100644 --- a/core/src/zeit/cmp/testing.py +++ b/core/src/zeit/cmp/testing.py @@ -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,), ) diff --git a/core/src/zeit/cms/testing.py b/core/src/zeit/cms/testing.py index 331a005e34..db4f0966b6 100644 --- a/core/src/zeit/cms/testing.py +++ b/core/src/zeit/cms/testing.py @@ -1,4 +1,3 @@ -from io import StringIO from urllib.parse import urljoin import base64 import contextlib @@ -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 = {} @@ -541,54 +535,42 @@ def testSetUp(self): self['request_handler'].response_code = 200 -cms_product_config = """\ - - 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 - -""".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')) diff --git a/core/src/zeit/content/article/testing.py b/core/src/zeit/content/article/testing.py index 0aa46f3378..eb825d4f6f 100644 --- a/core/src/zeit/content/article/testing.py +++ b/core/src/zeit/content/article/testing.py @@ -18,43 +18,38 @@ import zeit.wochenmarkt.testing -product_config = """ - - 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 - -""".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}'), '')] ) 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, diff --git a/core/src/zeit/content/audio/testing.py b/core/src/zeit/content/audio/testing.py index 126782f54a..6ab6d46661 100644 --- a/core/src/zeit/content/audio/testing.py +++ b/core/src/zeit/content/audio/testing.py @@ -10,14 +10,11 @@ T = TypeVar('T') # Can be anything -product_config = """ - - podcast-source file://{here}/tests/fixtures/podcasts.xml - -""".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,), ) diff --git a/core/src/zeit/content/author/testing.py b/core/src/zeit/content/author/testing.py index 554b592a1a..fbf90d7d2c 100644 --- a/core/src/zeit/content/author/testing.py +++ b/core/src/zeit/content/author/testing.py @@ -8,19 +8,17 @@ import zeit.find.testing -product_config = """ - - 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 vivi@zeit.de - sso-password password - -""".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': 'vivi@zeit.de', + 'sso-password': 'password', + }, + bases=(zeit.find.testing.CONFIG_LAYER,), ) diff --git a/core/src/zeit/content/cp/testing.py b/core/src/zeit/content/cp/testing.py index 97a1c814df..6803f4e424 100644 --- a/core/src/zeit/content/cp/testing.py +++ b/core/src/zeit/content/cp/testing.py @@ -20,29 +20,25 @@ import zeit.retresco.testhelper -product_config = """ - - 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"' - -""".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' diff --git a/core/src/zeit/content/gallery/testing.py b/core/src/zeit/content/gallery/testing.py index 1c72807710..8cdd9a05d6 100644 --- a/core/src/zeit/content/gallery/testing.py +++ b/core/src/zeit/content/gallery/testing.py @@ -11,17 +11,14 @@ import zeit.push.testing -product_config = """ - - 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 - -""".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,)) diff --git a/core/src/zeit/content/image/testing.py b/core/src/zeit/content/image/testing.py index 497898c9a9..34011d35dc 100644 --- a/core/src/zeit/content/image/testing.py +++ b/core/src/zeit/content/image/testing.py @@ -11,21 +11,18 @@ import zeit.content.image.imagegroup -product_config = """ - - display-type-source file://{here}/tests/fixtures/display-types.xml - variant-source file://{here}/tests/fixtures/variants.xml - copyright-company-source file://{here}/tests/fixtures/copyright-company.xml - encoder-parameters file://{here}/tests/fixtures/encoders.xml - mdb-api-url http://example.invalid - mdb-api-username mdbuser - mdb-api-password mdbpass - -""".format(here=importlib.resources.files(__package__)) - - +HERE = importlib.resources.files(__package__) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.cms.testing.CONFIG_LAYER,) + { + 'display-type-source': f'file://{HERE}/tests/fixtures/display-types.xml', + 'variant-source': f'file://{HERE}/tests/fixtures/variants.xml', + 'copyright-company-source': f'file://{HERE}/tests/fixtures/copyright-company.xml', + 'encoder-parameters': f'file://{HERE}/tests/fixtures/encoders.xml', + 'mdb-api-url': 'http://example.invalid', + 'mdb-api-username': 'mdbuser', + 'mdb-api-password': 'mdbpass', + }, + bases=(zeit.cms.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer(bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,)) diff --git a/core/src/zeit/content/link/testing.py b/core/src/zeit/content/link/testing.py index 7d10e04e0b..5458a2030a 100644 --- a/core/src/zeit/content/link/testing.py +++ b/core/src/zeit/content/link/testing.py @@ -6,15 +6,12 @@ import zeit.push.testing -product_config = """ - - source-blogs file://{here}/blog_source.xml - -""".format(here=importlib.resources.files(__package__)) - - +HERE = importlib.resources.files(__package__) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.push.testing.CONFIG_LAYER,) + { + 'source-blogs': f'file://{HERE}/blog_source.xml', + }, + bases=(zeit.push.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer(bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,)) diff --git a/core/src/zeit/content/modules/testing.py b/core/src/zeit/content/modules/testing.py index b14e067676..1f496fcd0c 100644 --- a/core/src/zeit/content/modules/testing.py +++ b/core/src/zeit/content/modules/testing.py @@ -10,19 +10,16 @@ import zeit.wochenmarkt.testing -product_config = """\ - - jobticker-source file://{here}/tests/fixtures/jobticker.xml - subject-source file://{here}/tests/fixtures/mail-subjects.xml - embed-provider-source file://{here}/tests/fixtures/embed-providers.xml - newsletter-source file://{here}/tests/fixtures/newsletter.xml - recipe-metadata-source file://{here}/tests/fixtures/recipe-metadata.xml - -""".format(here=importlib.resources.files(__package__)) - - +HERE = importlib.resources.files(__package__) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.cmp.testing.CONFIG_LAYER, zeit.wochenmarkt.testing.CONFIG_LAYER) + { + 'jobticker-source': f'file://{HERE}/tests/fixtures/jobticker.xml', + 'subject-source': f'file://{HERE}/tests/fixtures/mail-subjects.xml', + 'embed-provider-source': f'file://{HERE}/tests/fixtures/embed-providers.xml', + 'newsletter-source': f'file://{HERE}/tests/fixtures/newsletter.xml', + 'recipe-metadata-source': f'file://{HERE}/tests/fixtures/recipe-metadata.xml', + }, + bases=(zeit.cmp.testing.CONFIG_LAYER, zeit.wochenmarkt.testing.CONFIG_LAYER), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer(bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,)) diff --git a/core/src/zeit/content/volume/testing.py b/core/src/zeit/content/volume/testing.py index 8d52531f8c..5b11e354cf 100644 --- a/core/src/zeit/content/volume/testing.py +++ b/core/src/zeit/content/volume/testing.py @@ -9,21 +9,18 @@ import zeit.push.testing -product_config = """ - - volume-cover-source file://{here}/tests/fixtures/volume-covers.xml - default-teaser-text Teäser {{name}}/{{year}} - access-control-config file://{here}/tests/fixtures/access-control.xml - access-control-webtrekk-url https://webtrekkapi.foo - access-control-webtrekk-timeout 10 - access-control-webtrekk-username foo - access-control-webtrekk-password bar - access-control-webtrekk-customerId 123 - -""".format(here=importlib.resources.files(__package__)) - +HERE = importlib.resources.files(__package__) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, + { + 'volume-cover-source': f'file://{HERE}/tests/fixtures/volume-covers.xml', + 'default-teaser-text': 'Teäser {name}/{year}', + 'access-control-config': f'file://{HERE}/tests/fixtures/access-control.xml', + 'access-control-webtrekk-url': 'https://webtrekkapi.foo', + 'access-control-webtrekk-timeout': '10', + 'access-control-webtrekk-username': 'foo', + 'access-control-webtrekk-password': 'bar', + 'access-control-webtrekk-customerid': '123', + }, bases=(zeit.content.cp.testing.CONFIG_LAYER, zeit.push.testing.CONFIG_LAYER), ) @@ -34,8 +31,7 @@ def setUp(self): # Break circular dependency import zeit.content.article.testing - config = zeit.content.article.testing.product_config - self.config = self.loadConfiguration(config, self.package) + self.config = zeit.content.article.testing.CONFIG_LAYER.config super().setUp() diff --git a/core/src/zeit/crop/testing.py b/core/src/zeit/crop/testing.py index cf8f686ff6..2cdfa6f1d9 100644 --- a/core/src/zeit/crop/testing.py +++ b/core/src/zeit/crop/testing.py @@ -7,16 +7,13 @@ import zeit.content.image.testing -product_config = """ - - scale-source file://{here}/scales.xml - color-source file://{here}/colors.xml - -""".format(here=importlib.resources.files(__package__)) - - +HERE = importlib.resources.files(__package__) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.content.image.testing.CONFIG_LAYER,) + { + 'scale-source': f'file://{HERE}/scales.xml', + 'color-source': f'file://{HERE}/colors.xml', + }, + bases=(zeit.content.image.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer(bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,)) diff --git a/core/src/zeit/find/testing.py b/core/src/zeit/find/testing.py index 7c32a99915..d6aef31230 100644 --- a/core/src/zeit/find/testing.py +++ b/core/src/zeit/find/testing.py @@ -12,16 +12,11 @@ import zeit.find.interfaces -product_config = """\ - - elasticsearch-url http://tms-backend.staging.zeit.de:80/elasticsearch - elasticsearch-index foo_pool - -""" - - CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, + { + 'elasticsearch-url': 'http://tms-backend.staging.zeit.de:80/elasticsearch', + 'elasticsearch-index': 'foo_pool', + }, bases=(zeit.content.image.testing.CONFIG_LAYER, zeit.content.audio.testing.CONFIG_LAYER), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer(bases=(CONFIG_LAYER,)) diff --git a/core/src/zeit/newsimport/testing.py b/core/src/zeit/newsimport/testing.py index 9c90f6cff5..6eb771f718 100644 --- a/core/src/zeit/newsimport/testing.py +++ b/core/src/zeit/newsimport/testing.py @@ -21,21 +21,17 @@ HERE = os.path.dirname(__file__) -product_config = """\ - - weblines-url http://dpa_api_test.com - nextline-url http://dpa_api_test.com - dpa-rubric-config-source file://{base}/tests/data/products.xml - -""".format(base=HERE) - def asset_path(*parts): return os.path.join(HERE, 'tests', 'data', *parts) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, + { + 'weblines-url': 'http://dpa_api_test.com', + 'nextline-url': 'http://dpa_api_test.com', + 'dpa-rubric-config-source': f'file://{HERE}/tests/data/products.xml', + }, bases=(zeit.retresco.testing.CONFIG_LAYER,), ) # NOTE author config layer is included in article config layer diff --git a/core/src/zeit/push/testing.py b/core/src/zeit/push/testing.py index 2ba293c406..4bd8100c3d 100644 --- a/core/src/zeit/push/testing.py +++ b/core/src/zeit/push/testing.py @@ -29,23 +29,20 @@ def send(self, text, link, **kw): log.info('PushNotifier.send(%s)', {'text': text, 'link': link, 'kw': kw}) -product_config = """\ - - facebook-main-account fb-test - facebook-breaking-news-expiration 1800 - push-target-url http://www.zeit.de/ - mobile-image-url http://img.zeit.de/ - urbanairship-audience-group subscriptions - urbanairship-expire-interval 60 - mobile-buttons file://{fixtures}/mobile-buttons.xml - push-payload-templates http://xml.zeit.de/data/urbanairship-templates/ - homepage-banner-uniqueid http://xml.zeit.de/banner - -""".format(fixtures='%s/tests/fixtures' % importlib.resources.files(__package__)) - - +HERE = importlib.resources.files(__package__) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.content.image.testing.CONFIG_LAYER,) + { + 'facebook-main-account': 'fb-test', + 'facebook-breaking-news-expiration': '1800', + 'push-target-url': 'http://www.zeit.de/', + 'mobile-image-url': 'http://img.zeit.de/', + 'urbanairship-audience-group': 'subscriptions', + 'urbanairship-expire-interval': '60', + 'mobile-buttons': f'file://{HERE}/tests/fixtures/mobile-buttons.xml', + 'push-payload-templates': 'http://xml.zeit.de/data/urbanairship-templates/', + 'homepage-banner-uniqueid': 'http://xml.zeit.de/banner', + }, + bases=(zeit.content.image.testing.CONFIG_LAYER,), ) @@ -54,8 +51,7 @@ def setUp(self): # Break circular dependency import zeit.content.article.testing - config = zeit.content.article.testing.product_config - self.config = self.loadConfiguration(config, self.package) + self.config = zeit.content.article.testing.CONFIG_LAYER.config super().setUp() diff --git a/core/src/zeit/reach/testing.py b/core/src/zeit/reach/testing.py index 3715b6216d..ac464c61a7 100644 --- a/core/src/zeit/reach/testing.py +++ b/core/src/zeit/reach/testing.py @@ -2,18 +2,14 @@ import zeit.retresco.testing -product_config = """ - - url http://localhost:{port} - freeze-now - -""" - HTTP_LAYER = zeit.cms.testing.HTTPLayer( zeit.cms.testing.RecordingRequestHandler, name='HTTPLayer', module=__name__ ) CONFIG_LAYER = zeit.retresco.testing.ProductConfigLayer( - product_config, + { + 'url': 'http://localhost:{port}', + 'freeze-now': '', + }, package='zeit.reach', bases=( HTTP_LAYER, diff --git a/core/src/zeit/retresco/testing.py b/core/src/zeit/retresco/testing.py index 2fe909f08f..3f656148b5 100644 --- a/core/src/zeit/retresco/testing.py +++ b/core/src/zeit/retresco/testing.py @@ -1,5 +1,5 @@ -from io import StringIO from unittest import mock +import copy import importlib.resources import json @@ -20,35 +20,34 @@ ) -product_config = """ - - primary-base-url http://localhost:{port} - secondary-base-url http://localhost:{port}/another-tms - elasticsearch-url http://tms-backend.staging.zeit.de:80/elasticsearch - elasticsearch-index zeit_pool - elasticsearch-connection-class zeit.retresco.search.Connection - topic-redirect-prefix http://www.zeit.de - index-principal zope.user - kpi-fields file://%(here)s/tests/kpi.xml - topicpages-source file://%(here)s/tests/topicpages.xml - topicpage-prefix /thema - -""" % {'here': importlib.resources.files(__package__)} - - class ProductConfigLayer(zeit.cms.testing.ProductConfigLayer): def __init__(self, config, **kw): - self.raw_config = config - super().__init__({}, **kw) + # pytest may setUp/tearDown the same layer multiple times, so we have to + # perform the `port` replacement each time. + self.raw_config = copy.deepcopy(config) + super().__init__(config, **kw) def setUp(self): - config = self.raw_config.format(port=self['http_port']) - self.config = zope.app.appsetup.product.loadConfiguration(StringIO(config))[self.package] + for key, value in self.raw_config.items(): + if '{port}' in value: + self.config[key] = value.format(port=self['http_port']) super().setUp() +HERE = importlib.resources.files(__package__) CONFIG_LAYER = ProductConfigLayer( - product_config, + { + 'primary-base-url': 'http://localhost:{port}', + 'secondary-base-url': 'http://localhost:{port}/another-tms', + 'elasticsearch-url': 'http://tms-backend.staging.zeit.de:80/elasticsearch', + 'elasticsearch-index': 'zeit_pool', + 'elasticsearch-connection-class': 'zeit.retresco.search.Connection', + 'topic-redirect-prefix': 'http://www.zeit.de', + 'index-principal': 'zope.user', + 'kpi-fields': f'file://{HERE}/tests/kpi.xml', + 'topicpages-source': f'file://{HERE}/tests/topicpages.xml', + 'topicpage-prefix': '/thema', + }, bases=( HTTP_LAYER, zeit.content.article.testing.CONFIG_LAYER, diff --git a/core/src/zeit/simplecast/testing.py b/core/src/zeit/simplecast/testing.py index 1877975b0f..e7e6c8344b 100644 --- a/core/src/zeit/simplecast/testing.py +++ b/core/src/zeit/simplecast/testing.py @@ -2,16 +2,6 @@ import zeit.content.audio.testing -product_config = """\ - - simplecast-url https://testapi.simplecast.com/ - simplecast-token TkQvZUd2MHRnR0UybFhsgTfs - podcast-folder podcasts - principal zope.simplecast - retry-delay-seconds 0 - -""" - EPISODE_200 = { 'created_at': '2023-08-31T13:51:00-01:00', 'description': 'lorem ipsum', @@ -50,7 +40,13 @@ } CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, + { + 'simplecast-url': 'https://testapi.simplecast.com/', + 'simplecast-token': 'TkQvZUd2MHRnR0UybFhsgTfs', + 'podcast-folder': 'podcasts', + 'principal': 'zope.simplecast', + 'retry-delay-seconds': '0', + }, bases=(zeit.content.audio.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer('ftesting.zcml', bases=(CONFIG_LAYER,)) diff --git a/core/src/zeit/sourcepoint/testing.py b/core/src/zeit/sourcepoint/testing.py index 952ddedd69..7f41673706 100644 --- a/core/src/zeit/sourcepoint/testing.py +++ b/core/src/zeit/sourcepoint/testing.py @@ -5,16 +5,13 @@ import zeit.cms.testing -product_config = """\ - - addefend-url http://example.com - addefend-javascript-folder http://xml.zeit.de/addefend/ - addefend-filename adf - -""" - CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.cms.testing.CONFIG_LAYER,) + { + 'addefend-url': 'http://example.com', + 'addefend-javascript-folder': 'http://xml.zeit.de/addefend/', + 'addefend-filename': 'adf', + }, + bases=(zeit.cms.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer('testing.zcml', bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,)) diff --git a/core/src/zeit/speech/testing.py b/core/src/zeit/speech/testing.py index de1d4c4d7b..20c6203883 100644 --- a/core/src/zeit/speech/testing.py +++ b/core/src/zeit/speech/testing.py @@ -12,16 +12,6 @@ import zeit.content.audio.testing -product_config = """\ - - principal zope.speech - speech-folder tts - retry-delay-seconds 0 - max-retries 1 - -""" - - TTS_CREATION_STARTED = { 'event': 'AUDIO_CREATION_STARTED', 'uuid': 'a89ce2e3-4887-466a-a52e-edc6b9802ef9', @@ -67,7 +57,12 @@ } CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, + { + 'principal': 'zope.speech', + 'speech-folder': 'tts', + 'retry-delay-seconds': '0', + 'max-retries': '1', + }, bases=(zeit.content.article.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer('ftesting.zcml', bases=(CONFIG_LAYER,)) diff --git a/core/src/zeit/vgwort/testing.py b/core/src/zeit/vgwort/testing.py index c7031f1176..0dadfdc66e 100644 --- a/core/src/zeit/vgwort/testing.py +++ b/core/src/zeit/vgwort/testing.py @@ -16,24 +16,17 @@ import zeit.vgwort.interfaces -product_config = """ - - vgwort-url https://tom-test.vgwort.de/ - username {username} - password {password} - minimum-token-amount 10 - order-token-amount 1 - days-before-report 7 - claim-token-url http://user:userpw@localhost/ - -""".format( - username=os.environ.get('ZEIT_VGWORT_USERNAME'), - password=os.environ.get('ZEIT_VGWORT_PASSWORD'), -) - - CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.content.author.testing.CONFIG_LAYER,) + { + 'vgwort-url': 'https://tom-test.vgwort.de/', + 'username': os.environ.get('ZEIT_VGWORT_USERNAME', ''), + 'password': os.environ.get('ZEIT_VGWORT_PASSWORD', ''), + 'minimum-token-amount': '10', + 'order-token-amount': '1', + 'days-before-report': '7', + 'claim-token-url': 'http://user:userpw@localhost/', + }, + bases=(zeit.content.author.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer('ftesting-mock.zcml', bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER, zeit.retresco.testhelper.TMS_MOCK_LAYER)) diff --git a/core/src/zeit/wochenmarkt/testing.py b/core/src/zeit/wochenmarkt/testing.py index 0930856e6e..68b667b42a 100644 --- a/core/src/zeit/wochenmarkt/testing.py +++ b/core/src/zeit/wochenmarkt/testing.py @@ -6,15 +6,13 @@ import zeit.wochenmarkt.ingredients -product_config = """\ - - categories-url file://{here}/tests/fixtures/categories.xml - ingredients-url file://{here}/tests/fixtures/ingredients.xml - -""".format(here=importlib.resources.files(__package__)) - +HERE = importlib.resources.files(__package__) CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.cms.testing.CONFIG_LAYER,) + { + 'categories-url': f'file://{HERE}/tests/fixtures/categories.xml', + 'ingredients-url': f'file://{HERE}/tests/fixtures/ingredients.xml', + }, + bases=(zeit.cms.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer('ftesting.zcml', bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,)) diff --git a/core/src/zeit/workflow/testing.py b/core/src/zeit/workflow/testing.py index 5ffc40eafa..dd5a7dfc23 100644 --- a/core/src/zeit/workflow/testing.py +++ b/core/src/zeit/workflow/testing.py @@ -12,18 +12,15 @@ import zeit.workflow.publishinfo -product_config = """ - - dependency-publish-limit 100 - blacklist /blacklist - publisher-base-url http://localhost:8060/test/ - speechbert-ignore-genres datenvisualisierung video quiz - speechbert-ignore-templates zon-liveblog - -""" - CONFIG_LAYER = zeit.cms.testing.ProductConfigLayer( - product_config, bases=(zeit.push.testing.CONFIG_LAYER,) + { + 'dependency-publish-limit': '100', + 'blacklist': '/blacklist', + 'publisher-base-url': 'http://localhost:8060/test/', + 'speechbert-ignore-genres': 'datenvisualisierung video quiz', + 'speechbert-ignore-templates': 'zon-liveblog', + }, + bases=(zeit.push.testing.CONFIG_LAYER,), ) ZCML_LAYER = zeit.cms.testing.ZCMLLayer(bases=(CONFIG_LAYER,)) ZOPE_LAYER = zeit.cms.testing.ZopeLayer(bases=(ZCML_LAYER,))