|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import docker |
| 4 | +import pytest |
| 5 | + |
| 6 | +from ..helpers import force_leave_swarm, requires_api_version |
| 7 | +from .base import BaseAPIIntegrationTest |
| 8 | + |
| 9 | + |
| 10 | +@requires_api_version('1.30') |
| 11 | +class ConfigAPITest(BaseAPIIntegrationTest): |
| 12 | + def setUp(self): |
| 13 | + super(ConfigAPITest, self).setUp() |
| 14 | + self.init_swarm() |
| 15 | + |
| 16 | + def tearDown(self): |
| 17 | + super(ConfigAPITest, self).tearDown() |
| 18 | + force_leave_swarm(self.client) |
| 19 | + |
| 20 | + def test_create_config(self): |
| 21 | + config_id = self.client.create_config( |
| 22 | + 'favorite_character', 'sakuya izayoi' |
| 23 | + ) |
| 24 | + self.tmp_configs.append(config_id) |
| 25 | + assert 'ID' in config_id |
| 26 | + data = self.client.inspect_config(config_id) |
| 27 | + assert data['Spec']['Name'] == 'favorite_character' |
| 28 | + |
| 29 | + def test_create_config_unicode_data(self): |
| 30 | + config_id = self.client.create_config( |
| 31 | + 'favorite_character', u'いざよいさくや' |
| 32 | + ) |
| 33 | + self.tmp_configs.append(config_id) |
| 34 | + assert 'ID' in config_id |
| 35 | + data = self.client.inspect_config(config_id) |
| 36 | + assert data['Spec']['Name'] == 'favorite_character' |
| 37 | + |
| 38 | + def test_inspect_config(self): |
| 39 | + config_name = 'favorite_character' |
| 40 | + config_id = self.client.create_config( |
| 41 | + config_name, 'sakuya izayoi' |
| 42 | + ) |
| 43 | + self.tmp_configs.append(config_id) |
| 44 | + data = self.client.inspect_config(config_id) |
| 45 | + assert data['Spec']['Name'] == config_name |
| 46 | + assert 'ID' in data |
| 47 | + assert 'Version' in data |
| 48 | + |
| 49 | + def test_remove_config(self): |
| 50 | + config_name = 'favorite_character' |
| 51 | + config_id = self.client.create_config( |
| 52 | + config_name, 'sakuya izayoi' |
| 53 | + ) |
| 54 | + self.tmp_configs.append(config_id) |
| 55 | + |
| 56 | + assert self.client.remove_config(config_id) |
| 57 | + with pytest.raises(docker.errors.NotFound): |
| 58 | + self.client.inspect_config(config_id) |
| 59 | + |
| 60 | + def test_list_configs(self): |
| 61 | + config_name = 'favorite_character' |
| 62 | + config_id = self.client.create_config( |
| 63 | + config_name, 'sakuya izayoi' |
| 64 | + ) |
| 65 | + self.tmp_configs.append(config_id) |
| 66 | + |
| 67 | + data = self.client.configs(filters={'name': ['favorite_character']}) |
| 68 | + assert len(data) == 1 |
| 69 | + assert data[0]['ID'] == config_id['ID'] |
0 commit comments