UT: Improve readability of test_app.py

This commit is contained in:
vakarisz 2022-05-23 16:23:16 +03:00
parent dd2aadb4c1
commit 87082f058d
1 changed files with 27 additions and 23 deletions

View File

@ -20,61 +20,65 @@ def get_mock_resource(name, urls):
@pytest.fixture
def resource_mng():
def resource_manager():
container = StubDIContainer()
return mock_flask_resource_manager(container)
def test_duplicate_urls(resource_mng):
def test_duplicate_urls(resource_manager):
resource = get_mock_resource("res1", ["/url"])
resource2 = get_mock_resource("res1", ["/new_url", "/url"])
resource_mng.add_resource(resource)
with pytest.raises(FlaskDIWrapper.URLAlreadyExistsError):
resource_mng.add_resource(resource2)
resource_manager.add_resource(resource)
with pytest.raises(FlaskDIWrapper.DuplicateURLError):
resource_manager.add_resource(resource2)
def test_duplicate_urls__parameters(resource_mng):
def test_duplicate_urls__parameters(resource_manager):
resource1 = get_mock_resource("res1", ["/url/<string:param1>"])
resource2 = get_mock_resource("res2", ["/url/<string:param2>"])
resource_mng.add_resource(resource1)
with pytest.raises(FlaskDIWrapper.URLAlreadyExistsError):
resource_mng.add_resource(resource2)
resource_manager.add_resource(resource1)
with pytest.raises(FlaskDIWrapper.DuplicateURLError):
resource_manager.add_resource(resource2)
def test_duplicate_urls__multiple_parameters(resource_mng):
def test_duplicate_urls__multiple_parameters(resource_manager):
resource1 = get_mock_resource("res1", ["/url/<string:agent_name>/<string:param>"])
resource2 = get_mock_resource("res2", ["/url/<int:agent_id>/<string:param>"])
resource_mng.add_resource(resource1)
with pytest.raises(FlaskDIWrapper.URLAlreadyExistsError):
resource_mng.add_resource(resource2)
resource_manager.add_resource(resource1)
with pytest.raises(FlaskDIWrapper.DuplicateURLError):
resource_manager.add_resource(resource2)
def test_adding_resources(resource_mng):
def test_adding_resources(resource_manager):
resource = get_mock_resource("res1", ["/url"])
resource2 = get_mock_resource("res2", ["/different_url", "/another_different"])
resource3 = get_mock_resource("res3", ["/yet_another/<string:something>"])
resource_mng.add_resource(resource)
resource_mng.add_resource(resource2)
resource_mng.add_resource(resource3)
# Following shouldn't raise an exception
resource_manager.add_resource(resource)
resource_manager.add_resource(resource2)
resource_manager.add_resource(resource3)
def test_url_check_slash_stripping(resource_mng):
def test_url_check_slash_stripping__trailing_slash(resource_manager):
resource = get_mock_resource("res", ["/url"])
resource2 = get_mock_resource("res2", ["/url/"])
resource_mng.add_resource(resource)
with pytest.raises(FlaskDIWrapper.URLAlreadyExistsError):
resource_mng.add_resource(resource2)
resource_manager.add_resource(resource)
with pytest.raises(FlaskDIWrapper.DuplicateURLError):
resource_manager.add_resource(resource2)
def test_url_check_slash_stripping__path_separation(resource_manager):
resource3 = get_mock_resource("res3", ["/beef/face/"])
resource4 = get_mock_resource("res4", ["/beefface"])
resource_mng.add_resource(resource3)
resource_mng.add_resource(resource4)
# Following shouldn't raise and exception
resource_manager.add_resource(resource3)
resource_manager.add_resource(resource4)