Loading .pre-commit-config.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -93,4 +93,4 @@ repos: args: ["--python-version=3.9"] additional_dependencies: - types-requests - behave-utils ~=0.3.2 - behave-utils ~=0.3.3 tests/environment.py +5 −4 Original line number Diff line number Diff line Loading @@ -34,21 +34,22 @@ SITE_URL = URL("http://test.example.com") def before_all(context: Context) -> None: """ Setup fixtures for all tests Prepare fixtures for all tests """ use_fixture(running_site_fixture, context, site_url=SITE_URL) def before_feature(context: FeatureContext, feature: Feature) -> None: """ Setup/revert fixtures before each feature Prepare/revert fixtures before each feature """ use_fixture(snapshot_rollback, context, context.site.database) site = use_fixture(running_site_fixture, context) use_fixture(snapshot_rollback, context, site.database) def before_scenario(context: ScenarioContext, scenario: Scenario) -> None: """ Setup tools for each scenario Prepare tools for each scenario """ Loading tests/steps/commands.py +5 −2 Original line number Diff line number Diff line # Copyright 2021-2022 Dominik Sekotill <dom.sekotill@kodo.org.uk> # Copyright 2021-2023 Dominik Sekotill <dom.sekotill@kodo.org.uk> # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this Loading @@ -15,10 +15,12 @@ import shlex from typing import TYPE_CHECKING from behave import then from behave import use_fixture from behave import when from behave_utils.behave import PatternEnum from behave_utils.behave import register_pattern from wp import Container from wp import running_site_fixture if TYPE_CHECKING: from behave.runner import Context Loading Loading @@ -54,8 +56,9 @@ def run_command(context: Context, args: Arguments) -> None: """ if len(args) == 0: raise ValueError("No arguments in argument list") site = use_fixture(running_site_fixture, context) if args[0] in ('wp', 'php'): container: Container = context.site.backend container: Container = site.backend else: raise ValueError(f"Unknown command: {args[0]}") context.process = container.run(args, capture_output=True) Loading tests/steps/pages.py +6 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ from behave_utils import JSONArray from behave_utils import JSONObject from behave_utils import PatternEnum from request_steps import get_request from wp import running_site_fixture DEFAULT_CONTENT = """ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut Loading @@ -48,13 +49,13 @@ def assert_not_exist(context: Context, path: str) -> None: """ Assert that the path does not route to any resource """ site = use_fixture(running_site_fixture, context) cmd = [ "post", "list", "--field=url", "--format=json", "--post_type=post,page", "--post_status=publish", ] urls = {*context.site.backend.cli(*cmd, deserialiser=JSONArray.from_string)} assert context.site.url / path not in urls, \ f"{context.site.url / path} exists" urls = {*site.backend.cli(*cmd, deserialiser=JSONArray.from_string)} assert site.url / path not in urls, f"{site.url / path} exists" @given("a blank {post_type:PostType} exists") Loading Loading @@ -128,7 +129,7 @@ def wp_post( """ Create a WP post fixture of the given type with the given content """ wp = context.site.backend wp = use_fixture(running_site_fixture, context).backend postid = wp.cli( "post", "create", f"--post_type={post_type.value}", "--post_status=publish", Loading Loading @@ -162,7 +163,7 @@ def set_specials( Pages are reset at the end of a scenario """ wp = context.site.backend wp = use_fixture(running_site_fixture, context).backend options = { opt["option_name"]: opt["option_value"] Loading tests/steps/request_steps.py +6 −3 Original line number Diff line number Diff line Loading @@ -113,8 +113,9 @@ def get_request(context: Context, url: URL) -> None: """ Assign the response from making a GET request to "url" to the context """ site = use_fixture(running_site_fixture, context) session = use_fixture(requests_session, context) context.response = session.get(context.site.url / url, allow_redirects=False) context.response = session.get(site.url / url, allow_redirects=False) @when("data is sent with {method:Method} to {url:URL}") Loading @@ -124,10 +125,11 @@ def post_request(context: Context, method: Method, url: URL) -> None: """ if context.text is None: raise ValueError("Missing data, please add as text to step definition") site = use_fixture(running_site_fixture, context) session = use_fixture(requests_session, context) context.response = session.request( method.value, context.site.url / url, site.url / url, data=context.text.strip().format(context=context).encode("utf-8"), allow_redirects=False, ) Loading Loading @@ -159,7 +161,8 @@ def assert_header(context: Context, header_name: str, header_value: str) -> None Assert that an expected header was received during a previous step """ if SAMPLE_SITE_NAME in header_value: header_value = header_value.replace(SAMPLE_SITE_NAME, context.site.url) site = use_fixture(running_site_fixture, context) header_value = header_value.replace(SAMPLE_SITE_NAME, site.url) headers = context.response.headers assert header_name in headers, \ f"Expected header not found in response: {header_name!r}" Loading Loading
.pre-commit-config.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -93,4 +93,4 @@ repos: args: ["--python-version=3.9"] additional_dependencies: - types-requests - behave-utils ~=0.3.2 - behave-utils ~=0.3.3
tests/environment.py +5 −4 Original line number Diff line number Diff line Loading @@ -34,21 +34,22 @@ SITE_URL = URL("http://test.example.com") def before_all(context: Context) -> None: """ Setup fixtures for all tests Prepare fixtures for all tests """ use_fixture(running_site_fixture, context, site_url=SITE_URL) def before_feature(context: FeatureContext, feature: Feature) -> None: """ Setup/revert fixtures before each feature Prepare/revert fixtures before each feature """ use_fixture(snapshot_rollback, context, context.site.database) site = use_fixture(running_site_fixture, context) use_fixture(snapshot_rollback, context, site.database) def before_scenario(context: ScenarioContext, scenario: Scenario) -> None: """ Setup tools for each scenario Prepare tools for each scenario """ Loading
tests/steps/commands.py +5 −2 Original line number Diff line number Diff line # Copyright 2021-2022 Dominik Sekotill <dom.sekotill@kodo.org.uk> # Copyright 2021-2023 Dominik Sekotill <dom.sekotill@kodo.org.uk> # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this Loading @@ -15,10 +15,12 @@ import shlex from typing import TYPE_CHECKING from behave import then from behave import use_fixture from behave import when from behave_utils.behave import PatternEnum from behave_utils.behave import register_pattern from wp import Container from wp import running_site_fixture if TYPE_CHECKING: from behave.runner import Context Loading Loading @@ -54,8 +56,9 @@ def run_command(context: Context, args: Arguments) -> None: """ if len(args) == 0: raise ValueError("No arguments in argument list") site = use_fixture(running_site_fixture, context) if args[0] in ('wp', 'php'): container: Container = context.site.backend container: Container = site.backend else: raise ValueError(f"Unknown command: {args[0]}") context.process = container.run(args, capture_output=True) Loading
tests/steps/pages.py +6 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ from behave_utils import JSONArray from behave_utils import JSONObject from behave_utils import PatternEnum from request_steps import get_request from wp import running_site_fixture DEFAULT_CONTENT = """ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut Loading @@ -48,13 +49,13 @@ def assert_not_exist(context: Context, path: str) -> None: """ Assert that the path does not route to any resource """ site = use_fixture(running_site_fixture, context) cmd = [ "post", "list", "--field=url", "--format=json", "--post_type=post,page", "--post_status=publish", ] urls = {*context.site.backend.cli(*cmd, deserialiser=JSONArray.from_string)} assert context.site.url / path not in urls, \ f"{context.site.url / path} exists" urls = {*site.backend.cli(*cmd, deserialiser=JSONArray.from_string)} assert site.url / path not in urls, f"{site.url / path} exists" @given("a blank {post_type:PostType} exists") Loading Loading @@ -128,7 +129,7 @@ def wp_post( """ Create a WP post fixture of the given type with the given content """ wp = context.site.backend wp = use_fixture(running_site_fixture, context).backend postid = wp.cli( "post", "create", f"--post_type={post_type.value}", "--post_status=publish", Loading Loading @@ -162,7 +163,7 @@ def set_specials( Pages are reset at the end of a scenario """ wp = context.site.backend wp = use_fixture(running_site_fixture, context).backend options = { opt["option_name"]: opt["option_value"] Loading
tests/steps/request_steps.py +6 −3 Original line number Diff line number Diff line Loading @@ -113,8 +113,9 @@ def get_request(context: Context, url: URL) -> None: """ Assign the response from making a GET request to "url" to the context """ site = use_fixture(running_site_fixture, context) session = use_fixture(requests_session, context) context.response = session.get(context.site.url / url, allow_redirects=False) context.response = session.get(site.url / url, allow_redirects=False) @when("data is sent with {method:Method} to {url:URL}") Loading @@ -124,10 +125,11 @@ def post_request(context: Context, method: Method, url: URL) -> None: """ if context.text is None: raise ValueError("Missing data, please add as text to step definition") site = use_fixture(running_site_fixture, context) session = use_fixture(requests_session, context) context.response = session.request( method.value, context.site.url / url, site.url / url, data=context.text.strip().format(context=context).encode("utf-8"), allow_redirects=False, ) Loading Loading @@ -159,7 +161,8 @@ def assert_header(context: Context, header_name: str, header_value: str) -> None Assert that an expected header was received during a previous step """ if SAMPLE_SITE_NAME in header_value: header_value = header_value.replace(SAMPLE_SITE_NAME, context.site.url) site = use_fixture(running_site_fixture, context) header_value = header_value.replace(SAMPLE_SITE_NAME, site.url) headers = context.response.headers assert header_name in headers, \ f"Expected header not found in response: {header_name!r}" Loading