Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keyerror when creating new config(#3110) #3200

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/models/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ConfigCollection(Collection):

def create(self, **kwargs):
obj = self.client.api.create_config(**kwargs)
obj.setdefault("Spec", {})["Name"] = kwargs.get("name")
return self.prepare_model(obj)
create.__doc__ = APIClient.create_config.__doc__

Expand Down
9 changes: 9 additions & 0 deletions tests/unit/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
FAKE_NODE_ID = '24ifsmvkjbyhk'
FAKE_SECRET_ID = 'epdyrw4tsi03xy3deu8g8ly6o'
FAKE_SECRET_NAME = 'super_secret'
FAKE_CONFIG_ID = 'sekvs771242jfdjnvfuds8232'
FAKE_CONFIG_NAME = 'super_config'

# Each method is prefixed with HTTP method (get, post...)
# for clarity and readability
Expand Down Expand Up @@ -512,6 +514,11 @@ def post_fake_secret():
response = {'ID': FAKE_SECRET_ID}
return status_code, response

def post_fake_config():
status_code = 200
response = {'ID': FAKE_CONFIG_ID}
return status_code, response


# Maps real api url to fake response callback
prefix = 'http+docker://localhost'
Expand Down Expand Up @@ -630,4 +637,6 @@ def post_fake_secret():
post_fake_network_disconnect,
f'{prefix}/{CURRENT_VERSION}/secrets/create':
post_fake_secret,
f'{prefix}/{CURRENT_VERSION}/configs/create':
post_fake_config,
}
1 change: 1 addition & 0 deletions tests/unit/fake_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def make_fake_api_client(overrides=None):
'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],
'create_config.return_value': fake_api.post_fake_config()[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],
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/models_configs_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import unittest

from .fake_api_client import make_fake_client
from .fake_api import FAKE_CONFIG_NAME

class CreateConfigsTest(unittest.TestCase):
def test_create_config(self):
client = make_fake_client()
config = client.configs.create(name="super_config", data="config")
assert config.__repr__() == "<Config: '{}'>".format(FAKE_CONFIG_NAME)