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 secret repr #2470

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions docker/models/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

class Secret(Model):
"""A secret."""
id_attribute = 'ID'
id_attribute = 'Id'

def __repr__(self):
return "<%s: '%s'>" % (self.__class__.__name__, self.name)
return "<%s: '%s'>" % (self.__class__.__name__, self.id)

@property
def name(self):
return self.attrs['Spec']['Name']
return self.attrs.get('Spec', {}).get('Name')

def remove(self):
"""
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 @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
}
1 change: 1 addition & 0 deletions tests/unit/fake_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/models_secrets_test.py
Original file line number Diff line number Diff line change
@@ -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__() == "<Secret: '{}'>".format(FAKE_SECRET_ID)