From 3f03e25bd3923fbf55500d3f73b023f55cfd94d1 Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Tue, 21 Jun 2022 16:59:43 +0200 Subject: [PATCH] refactoring; added operations to test config + overwriting main config in components fixture --- pyinfra/visitor/strategies/download/multi.py | 26 ++++++++++---------- test/config.yaml | 7 +++++- test/conftest.py | 1 - test/integration_tests/serve_test.py | 5 ++++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/pyinfra/visitor/strategies/download/multi.py b/pyinfra/visitor/strategies/download/multi.py index 1cb50fb..f0fee78 100644 --- a/pyinfra/visitor/strategies/download/multi.py +++ b/pyinfra/visitor/strategies/download/multi.py @@ -24,19 +24,6 @@ class MultiDownloadStrategy(DownloadStrategy): def __call__(self, storage, queue_item_body): return self.download(storage, queue_item_body) - def get_page_matcher(self, queue_item_body): - - pages = queue_item_body.get("pages", None) - - if "pages" in queue_item_body: - pages = "|".join(map(str, pages)) - page_matcher = "pages/id:(" + pages + ")." - - else: - page_matcher = "" - - return page_matcher - def get_names_of_objects_by_pages(self, storage, file_pattern: str): matches_pattern = flift(file_pattern) page_object_names = compose(matches_pattern, storage.get_all_object_names)(self.bucket_name) @@ -86,3 +73,16 @@ class MultiDownloadStrategy(DownloadStrategy): file_pattern = file_pattern.replace("", self.get_page_matcher(queue_item_body)) return file_pattern + + def get_page_matcher(self, queue_item_body): + + pages = queue_item_body.get("pages", None) + + if "pages" in queue_item_body: + pages = "|".join(map(str, pages)) + page_matcher = "pages/id:(" + pages + ")." + + else: + page_matcher = "" + + return page_matcher diff --git a/test/config.yaml b/test/config.yaml index d88ccf1..cede889 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -1,3 +1,9 @@ +service: + response_formatter: identity + operations: + default: + input_file_pattern: //ORIGIN.pdf.gz + storage: minio: endpoint: "http://127.0.0.1:9000" @@ -21,7 +27,6 @@ webserver: port: $SERVER_PORT|5000 # webserver port mode: $SERVER_MODE|production # webserver mode: {development, production} - mock_analysis_endpoint: "http://127.0.0.1:5000" use_docker_fixture: 0 diff --git a/test/conftest.py b/test/conftest.py index 4291894..7749b25 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -4,7 +4,6 @@ from pyinfra.config import CONFIG as MAIN_CONFIG MAIN_CONFIG["retry"]["delay"] = 0.1 MAIN_CONFIG["retry"]["jitter"] = (0.1, 0.2) -MAIN_CONFIG["service"]["response_formatter"] = "identity" import logging import time diff --git a/test/integration_tests/serve_test.py b/test/integration_tests/serve_test.py index b0de1a0..ebe7892 100644 --- a/test/integration_tests/serve_test.py +++ b/test/integration_tests/serve_test.py @@ -208,6 +208,11 @@ def components_type(request): @pytest.fixture def real_components(url, download_strategy): + from test.config import CONFIG as TEST_CONFIG + + CONFIG["service"]["operations"] = TEST_CONFIG.service.operations + CONFIG["service"]["response_formatter"] = TEST_CONFIG.service.response_formatter + component_factory = get_component_factory(CONFIG) callback = component_factory.get_callback(url)