From 87082f058d488ebcf4fcc6bc4e3d43f17e67c3ea Mon Sep 17 00:00:00 2001 From: vakarisz Date: Mon, 23 May 2022 16:23:16 +0300 Subject: [PATCH] UT: Improve readability of test_app.py --- .../unit_tests/monkey_island/cc/test_app.py | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/test_app.py b/monkey/tests/unit_tests/monkey_island/cc/test_app.py index ddb20c83b..8befc3b22 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/test_app.py +++ b/monkey/tests/unit_tests/monkey_island/cc/test_app.py @@ -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/"]) resource2 = get_mock_resource("res2", ["/url/"]) - 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//"]) resource2 = get_mock_resource("res2", ["/url//"]) - 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/"]) - 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)