28
28
from quickstart.tests import helpers
31
class TestGetApiUrl(unittest.TestCase):
33
def test_new_url(self):
34
# The new Juju API endpoint is returned if a recent Juju is used.
35
url = jujutools.get_api_url('1.2.3.4:17070', (1, 22, 0), 'env-uuid')
36
self.assertEqual('wss://1.2.3.4:17070/environment/env-uuid/api', url)
38
def test_new_url_with_prefix(self):
39
# The new Juju API endpoint is returned with the given path prefix.
40
url = jujutools.get_api_url(
41
'1.2.3.4:17070', (1, 22, 0), 'env-uuid', prefix='/my/path/')
43
'wss://1.2.3.4:17070/my/path/environment/env-uuid/api', url)
45
def test_old_juju(self):
46
# The old Juju API endpoint is returned if the Juju in use is not a
48
url = jujutools.get_api_url('1.2.3.4:17070', (1, 21, 7), 'env-uuid')
49
self.assertEqual('wss://1.2.3.4:17070', url)
51
def test_old_juju_with_prefix(self):
52
# The old Juju API endpoint is returned with the given path prefix.
53
url = jujutools.get_api_url(
54
'1.2.3.4:8888', (1, 21, 7), 'env-uuid', 'proxy/')
55
self.assertEqual('wss://1.2.3.4:8888/proxy', url)
57
def test_no_env_uuid(self):
58
# The old Juju API endpoint is returned if the environment unique
59
# identifier is unreachable.
60
url = jujutools.get_api_url('1.2.3.4:17070', (1, 23, 42), None)
61
self.assertEqual('wss://1.2.3.4:17070', url)
63
def test_no_env_uuid_with_prefix(self):
64
# The old Juju API endpoint is returned with the given path prefix.
65
url = jujutools.get_api_url(
66
'1.2.3.4:17070', (1, 23, 42), None, 'my/prefix')
67
self.assertEqual('wss://1.2.3.4:17070/my/prefix', url)
69
def test_new_charm_old_juju(self):
70
# The old Juju API endpoints are used if and old version of Juju is in
71
# use, even if the Juju GUI charm is recent.
72
charm = charms.Charm.from_url('cs:trusty/juju-gui-42')
73
url = jujutools.get_api_url(
74
'1.2.3.4:5678', (1, 21, 7), 'env-uuid', charm=charm)
75
self.assertEqual('wss://1.2.3.4:5678', url)
77
def test_customized_charm_unexpected_name(self):
78
# If a customized Juju GUI charm is used, then we assume it supports
79
# the new Juju Login API endpoint (unexpected charm name).
80
charm = charms.Charm.from_url('cs:trusty/the-amazing-gui-0')
81
url = jujutools.get_api_url(
82
'example.com:17070', (1, 22, 2), 'uuid', charm=charm)
83
self.assertEqual('wss://example.com:17070/environment/uuid/api', url)
85
def test_customized_charm_unexpected_user(self):
86
# If a customized Juju GUI charm is used, then we assume it supports
87
# the new Juju Login API endpoint (unexpected charm user).
88
charm = charms.Charm.from_url('cs:~who/trusty/juju-gui-0')
89
url = jujutools.get_api_url(
90
'example.com:17070', (1, 22, 2), 'uuid', charm=charm)
91
self.assertEqual('wss://example.com:17070/environment/uuid/api', url)
93
def test_customized_charm_unexpected_schema(self):
94
# If a customized Juju GUI charm is used, then we assume it supports
95
# the new Juju Login API endpoint (local charm).
96
charm = charms.Charm.from_url('local:precise/juju-gui-0')
97
url = jujutools.get_api_url(
98
'example.com:17070', (1, 22, 2), 'uuid', prefix='/', charm=charm)
99
self.assertEqual('wss://example.com:17070/environment/uuid/api', url)
101
def test_customized_charm_unexpected_series(self):
102
# If a customized Juju GUI charm is used, then we assume it supports
103
# the new Juju Login API endpoint (unsupported charm series).
104
charm = charms.Charm.from_url('cs:vivid/juju-gui-0')
105
url = jujutools.get_api_url(
106
'example.com:22', (1, 22, 2), 'uuid', prefix='ws', charm=charm)
107
self.assertEqual('wss://example.com:22/ws/environment/uuid/api', url)
109
def test_recent_precise_charm(self):
110
# The new API endpoints are used if a recent precise charm is in use.
111
charm = charms.Charm.from_url('cs:precise/juju-gui-107')
112
url = jujutools.get_api_url(
113
'1.2.3.4:4747', (1, 42, 0), 'env-id', charm=charm)
114
self.assertEqual('wss://1.2.3.4:4747/environment/env-id/api', url)
116
def test_recent_trusty_charm(self):
117
# The new API endpoints are used if a recent trusty charm is in use.
118
charm = charms.Charm.from_url('cs:trusty/juju-gui-19')
119
url = jujutools.get_api_url(
120
'1.2.3.4:4747', (1, 42, 0), 'env-id', charm=charm)
121
self.assertEqual('wss://1.2.3.4:4747/environment/env-id/api', url)
123
def test_old_precise_charm(self):
124
# The old API endpoint is returned if the precise Juju GUI charm in use
126
charm = charms.Charm.from_url('cs:precise/juju-gui-106')
127
url = jujutools.get_api_url(
128
'1.2.3.4:4747', (1, 42, 0), 'env-uuid', charm=charm)
129
self.assertEqual('wss://1.2.3.4:4747', url)
131
def test_old_trusty_charm(self):
132
# The old API endpoint is returned if the trusty Juju GUI charm in use
134
charm = charms.Charm.from_url('cs:trusty/juju-gui-18')
135
url = jujutools.get_api_url(
136
'1.2.3.4:4747', (1, 42, 0), 'env-uuid', prefix='ws', charm=charm)
137
self.assertEqual('wss://1.2.3.4:4747/ws', url)
139
def test_recent_charm_and_prefix(self):
140
# The new API endpoint is returned if a recent charm and a prefix are
141
# both provided. This test exercises the real case in which the GUI
142
# server API endpoint is returned.
143
charm = charms.Charm.from_url('cs:trusty/juju-gui-42')
144
url = jujutools.get_api_url(
145
'1.2.3.4:17070', (1, 22, 0), 'env-id', prefix='ws', charm=charm)
146
self.assertEqual('wss://1.2.3.4:17070/ws/environment/env-id/api', url)
31
149
class TestGetServiceInfo(helpers.WatcherDataTestsMixin, unittest.TestCase):
33
151
def test_service_and_unit(self):