Commit 10b35d81 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add regression test for #20

parent b64662db
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -96,4 +96,4 @@ repos:
    args: ["--config-file=.lint.cfg"]
    additional_dependencies:
    - types-requests
    - git+https://code.kodo.org.uk/dom/behave-utils.git@v0.2#behave-utils
    - behave-utils ~=0.3.2
+15 −0
Original line number Diff line number Diff line
Feature: Return favicons when requests
	Regression check for "#20": Fix/remove favicon.ico intercept in Nginx

	An icon should always be served when requesting "/favicon.ico", either one
	added by the owner, or a default icon.

	Scenario: Default icon
		When /favicon.ico is requested
		Then 302 is returned
		And the "Location" header's value is "http://test.example.com/wp-includes/images/w-logo-blue-white-bg.png"

	Scenario: Owner supplied icon
		Given /app/static/favicon.ico exists in the frontend
		When /favicon.ico is requested
		Then 200 is returned
+1 −1
Original line number Diff line number Diff line
Python ~=3.9; python_version < '3.9'

behave
git+https://code.kodo.org.uk/dom/behave-utils.git@v0.2#behave-utils
behave-utils ~=0.3.2
requests ~=2.26
+5 −1
Original line number Diff line number Diff line
#  Copyright 2021  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#  Copyright 2021-2022  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
@@ -19,6 +19,8 @@ from behave.runner import Context
from behave_utils import URL
from behave_utils import PatternEnum

SAMPLE_SITE_NAME = "http://test.example.com"


class Method(PatternEnum):
	"""
@@ -120,6 +122,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)
	headers = context.response.headers
	assert header_name in headers, \
		f"Expected header not found in response: {header_name!r}"

tests/steps/static.py

0 → 100644
+39 −0
Original line number Diff line number Diff line
#  Copyright 2022  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
#  file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""
Step implementations involving creating files in containers
"""

from __future__ import annotations

from typing import Iterator

from behave import fixture
from behave import given
from behave import use_fixture
from behave.runner import Context
from behave_utils.docker import Cli


@given("{path} exists in the {container}")
def step_impl(context: Context, path: str, container: str) -> None:
	"""
	Create a file in the named container
	"""
	use_fixture(container_file, context, path, container)


@fixture
def container_file(context: Context, path: str, container_name: str) -> Iterator[None]:
	"""
	Create a file in a named container as a fixture
	"""
	container = getattr(context.site, container_name)
	run = Cli(container)
	run("tee", path, input=getattr(context, "text", "This is a data file!"))
	yield
	run("rm", path)