Commit 231e9afe authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add unit tests for behave_utils.url

parent 9c0480d0
Loading
Loading
Loading
Loading

tests/unit/test_url.py

0 → 100644
+47 −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/.

"""
Unit tests for behave_utils.url
"""

from behave_utils.url import URL

from . import TestCase


class URLTests(TestCase):
	"""
	Tests for behave_utils.url.URL
	"""

	def test_join(self) -> None:
		"""
		Check that the division operator does a URL join
		"""
		with self.subTest("check type"):
			assert isinstance(URL("https://example.com/foo") / "bar", URL)

		with self.subTest("no slash"):
			assert URL("https://example.com/foo") / "bar" == "https://example.com/bar"

		with self.subTest("slash"):
			assert URL("https://example.com/foo/") / "bar" == "https://example.com/foo/bar"

		with self.subTest("both slash"):
			assert URL("https://example.com/foo/") / "bar/" == "https://example.com/foo/bar/"

		with self.subTest("absolute"):
			assert URL("https://example.com/foo/bar/") / "/bar" == "https://example.com/bar"

	def test_append(self) -> None:
		"""
		Check that the addition operator appends
		"""
		url = URL("https://example.com/foo") + "bar"

		assert url == "https://example.com/foobar"
		assert isinstance(url, URL)