From bbfa1388490fa85cb972ba301fce374a341073b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 30 Mar 2020 21:36:26 +0200 Subject: [PATCH] tests now run --- app.py | 2 +- consumerlocator.py | 2 +- test.py | 32 ++++++++++---------------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/app.py b/app.py index b121b33..bbb6f7c 100644 --- a/app.py +++ b/app.py @@ -23,7 +23,7 @@ sentry_sdk.init("https://3fa5ae886ba1489092ad49a93cb419c1@sentry.kmlabz.com/9") logging.basicConfig(level=logging.INFO) LOGGER = logging.getLogger(__name__) -KNOWNCONSUMER= os.environ["PRODUCER_KNOWNCONSUMER"] +KNOWNCONSUMER = os.getenv("PRODUCER_KNOWNCONSUMER",'10.69.42.1') if __name__ == "__main__": LOGGER.info("Producer started") diff --git a/consumerlocator.py b/consumerlocator.py index cababe3..83988b4 100644 --- a/consumerlocator.py +++ b/consumerlocator.py @@ -13,7 +13,7 @@ __copyright__ = "Copyright 2020, GoldenPogácsa Team" __module_name__ = "consumerlocator" __version__text__ = "1" -KNOWNCONSUMER= os.environ["PRODUCER_KNOWNCONSUMER"] +KNOWNCONSUMER = os.getenv("PRODUCER_KNOWNCONSUMER",'10.69.42.1') class ConsumerLocator: diff --git a/test.py b/test.py index 035e8c6..2b93933 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import os import re import consumerlocator import communicator @@ -16,7 +15,6 @@ __module_name__ = "test" __version__text__ = "1" generateduuid = 'c959ad81-58f9-4445-aab4-8f3d68aee1ad' -os.environ["PRODUCER_KNOWNCONSUMER"] = "10.1.2.3" def test_generate_string(mocker): @@ -139,16 +137,18 @@ def test_setcurrentconsumer(): def test_learnconsumerlist(httpserver): - httpserver.expect_oneshot_request( + httpserver.expect_request( uri="/consumer", method='GET', - data="").respond_with_json( + data="", + handler_type='permanent').respond_with_json( ["10.69.42.1", "10.10.10.10", "10.20.30.40"]) url = httpserver.url_for("/") port = re.match(r"\W*http[^:]*\D*(\d+)", url).group(1) comm = communicator.Communicator( currentconsumer=f"127.0.0.1:{port}", uuid=generateduuid) + consumerlocator.KNOWNCONSUMER = f"127.0.0.1:{port}" locator = consumerlocator.ConsumerLocator( uuid=generateduuid, communicator=comm) ret = locator.learnconsumerlist() @@ -162,7 +162,7 @@ def test_getcurrentconsumer(mocker): uuid=generateduuid) locator = consumerlocator.ConsumerLocator( uuid=generateduuid, communicator=comm) - assert locator.getcurrentconsumer() == "10.1.2.3" + assert locator.getcurrentconsumer() == consumerlocator.KNOWNCONSUMER def test_checkcurrentconsumer(httpserver): @@ -176,10 +176,11 @@ def test_checkcurrentconsumer(httpserver): comm = communicator.Communicator( currentconsumer=f"127.0.0.1:{port}", uuid=generateduuid) + consumerlocator.KNOWNCONSUMER = f"127.0.0.1:{port}" locator = consumerlocator.ConsumerLocator( uuid=generateduuid, communicator=comm) ret = locator.checkcurrentconsumer() - assert ret == False + assert ret == True def test_updateconsumer(httpserver): @@ -193,25 +194,11 @@ def test_updateconsumer(httpserver): comm = communicator.Communicator( currentconsumer=f"127.0.0.1:{port}", uuid=generateduuid) + consumerlocator.KNOWNCONSUMER = f"127.0.0.1:{port}" locator = consumerlocator.ConsumerLocator( uuid=generateduuid, communicator=comm) ret = locator.updateconsumer() - assert ret == "10.69.42.1" - - httpserver.expect_oneshot_request( - uri="/consumer", - method='GET', - data="").respond_with_json( - []) - url2 = httpserver.url_for("/") - port2 = re.match(r"\W*http[^:]*\D*(\d+)", url2).group(1) - comm2 = communicator.Communicator( - currentconsumer=f"127.0.0.1:{port2}", - uuid=generateduuid) - locator2 = consumerlocator.ConsumerLocator( - uuid=generateduuid, communicator=comm2) - ret2 = locator2.updateconsumer() - assert ret2 is None + assert ret == f"127.0.0.1:{port}" def test_updateconsumerlist(httpserver): @@ -225,6 +212,7 @@ def test_updateconsumerlist(httpserver): comm = communicator.Communicator( currentconsumer=f"127.0.0.1:{port}", uuid=generateduuid) + consumerlocator.KNOWNCONSUMER = f"127.0.0.1:{port}" locator = consumerlocator.ConsumerLocator( uuid=generateduuid, communicator=comm) ret = locator.updateconsumerlist()