From 8b5a34ad5baf367009caa61aa3259888f9ad6168 Mon Sep 17 00:00:00 2001 From: Felipe Ruhland Date: Thu, 28 Nov 2019 14:03:21 -0300 Subject: [PATCH] Create a unit test to reproduce the repr issue - a post fake secret - added to fake api - create a unit test Signed-off-by: Felipe Ruhland --- tests/unit/fake_api.py | 9 +++++++++ tests/unit/fake_api_client.py | 1 + tests/unit/models_secrets_test.py | 11 +++++++++++ 3 files changed, 21 insertions(+) create mode 100644 tests/unit/models_secrets_test.py diff --git a/tests/unit/fake_api.py b/tests/unit/fake_api.py index e609b64edd..4cb7592ecb 100644 --- a/tests/unit/fake_api.py +++ b/tests/unit/fake_api.py @@ -16,6 +16,7 @@ FAKE_PATH = '/path' FAKE_VOLUME_NAME = 'perfectcherryblossom' FAKE_NODE_ID = '24ifsmvkjbyhk' +FAKE_SECRET_ID = 'epdyrw4tsi03xy3deu8g8ly6o' # Each method is prefixed with HTTP method (get, post...) # for clarity and readability @@ -511,6 +512,12 @@ def post_fake_network_disconnect(): return 200, None +def post_fake_secret(): + status_code = 200 + response = {'Id': FAKE_SECRET_ID} + return status_code, response + + # Maps real api url to fake response callback prefix = 'http+docker://localhost' if constants.IS_WINDOWS_PLATFORM: @@ -642,4 +649,6 @@ def post_fake_network_disconnect(): CURRENT_VERSION, prefix, FAKE_NETWORK_ID ), 'POST'): post_fake_network_disconnect, + '{1}/{0}/secrets/create'.format(CURRENT_VERSION, prefix): + post_fake_secret, } diff --git a/tests/unit/fake_api_client.py b/tests/unit/fake_api_client.py index 2147bfdfa1..fb71b41316 100644 --- a/tests/unit/fake_api_client.py +++ b/tests/unit/fake_api_client.py @@ -39,6 +39,7 @@ def make_fake_api_client(overrides=None): fake_api.post_fake_create_container()[1], 'create_host_config.side_effect': api_client.create_host_config, 'create_network.return_value': fake_api.post_fake_network()[1], + 'create_secret.return_value': fake_api.post_fake_secret()[1], 'exec_create.return_value': fake_api.post_fake_exec_create()[1], 'exec_start.return_value': fake_api.post_fake_exec_start()[1], 'images.return_value': fake_api.get_fake_images()[1], diff --git a/tests/unit/models_secrets_test.py b/tests/unit/models_secrets_test.py new file mode 100644 index 0000000000..b6cb9500bf --- /dev/null +++ b/tests/unit/models_secrets_test.py @@ -0,0 +1,11 @@ +import unittest + +from .fake_api_client import make_fake_client +from .fake_api import FAKE_SECRET_ID + + +class CreateServiceTest(unittest.TestCase): + def test_secrets_repr(self): + client = make_fake_client() + secret = client.secrets.create(name="test", data="secret") + assert secret.__repr__() == "".format(FAKE_SECRET_ID)