Skip to content

Commit 1a2c2a0

Browse files
Unit test fixes
The following updates the bundle unit tests changes fixes. These should ensure that we're at least compatible with what was previously written.
1 parent 3d7af12 commit 1a2c2a0

3 files changed

Lines changed: 82 additions & 23 deletions

File tree

juju/bundle.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ class AddApplicationChange(ChangeInfo):
389389
'devices': 'devices',
390390
'endpoint-bindings': 'endpoint_bindings',
391391
'resources': 'resources',
392-
'num-units': 'num_units'}
392+
'num-units': 'num_units',
393+
'channel': 'channel'}
393394

394395
"""AddApplicationChange holds a change for deploying a Juju application.
395396
@@ -478,7 +479,7 @@ async def run(self, context):
478479

479480
origin = context.origins.get(str(url), {}).get(str(channel), None)
480481
if origin is None:
481-
raise JujuError("expected origin to be valid for application {} and charm {}".format(self.application, self.charm))
482+
raise JujuError("expected origin to be valid for application {} and charm {} with channel {}".format(self.application, str(url), str(channel)))
482483

483484
await context.model._deploy(
484485
charm_url=charm,
@@ -514,7 +515,8 @@ def __str__(self):
514515
class AddCharmChange(ChangeInfo):
515516
_toPy = {'charm': 'charm',
516517
'series': 'series',
517-
'channel': 'channel'}
518+
'channel': 'channel',
519+
'architecture': 'architecture'}
518520

519521
"""AddCharmChange holds a change for adding a charm to the environment.
520522

tests/unit/test_bundle.py

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def test_list_params_juju_2_4(self):
7777
"endpoint_bindings": "endpoint_bindings",
7878
"resources": "resources",
7979
"devices": None,
80-
"num_units": None}, change.__dict__)
80+
"num_units": None,
81+
"channel": None}, change.__dict__)
8182

8283
def test_list_params_juju_2_5(self):
8384
change = AddApplicationChange(1, [], params=["charm",
@@ -101,7 +102,8 @@ def test_list_params_juju_2_5(self):
101102
"endpoint_bindings": "endpoint_bindings",
102103
"resources": "resources",
103104
"devices": {"gpu": {"type": "gpu", "count": 1, "attributes": {"attr1": "a", "attr2": "b"}}},
104-
"num_units": "num_units"}, change.__dict__)
105+
"num_units": "num_units",
106+
"channel": None}, change.__dict__)
105107

106108
def test_dict_params(self):
107109
change = AddApplicationChange(1, [], params={"charm": "charm",
@@ -113,7 +115,8 @@ def test_dict_params(self):
113115
"endpoint-bindings": "endpoint_bindings",
114116
"resources": "resources",
115117
"devices": "devices",
116-
"num-units": "num_units"})
118+
"num-units": "num_units",
119+
"channel": "channel"})
117120
self.assertEqual({"change_id": 1,
118121
"requires": [],
119122
"charm": "charm",
@@ -125,7 +128,8 @@ def test_dict_params(self):
125128
"endpoint_bindings": "endpoint_bindings",
126129
"resources": "resources",
127130
"devices": "devices",
128-
"num_units": "num_units"}, change.__dict__)
131+
"num_units": "num_units",
132+
"channel": "channel"}, change.__dict__)
129133

130134
def test_dict_params_missing_data(self):
131135
change = AddApplicationChange(1, [], params={"charm": "charm",
@@ -145,14 +149,15 @@ def test_dict_params_missing_data(self):
145149
"endpoint_bindings": None,
146150
"resources": None,
147151
"devices": None,
148-
"num_units": None}, change.__dict__)
152+
"num_units": None,
153+
"channel": None}, change.__dict__)
149154

150155

151156
class TestAddApplicationChangeRun:
152157

153158
@pytest.mark.asyncio
154-
async def test_run(self, event_loop):
155-
change = AddApplicationChange(1, [], params={"charm": "charm",
159+
async def test_run_with_charmstore_charm(self, event_loop):
160+
change = AddApplicationChange(1, [], params={"charm": "cs:charm",
156161
"series": "series",
157162
"application": "application",
158163
"options": "options",
@@ -161,14 +166,16 @@ async def test_run(self, event_loop):
161166
"endpoint-bindings": "endpoint_bindings",
162167
"resources": "resources",
163168
"devices": "devices",
164-
"num-units": "num_units"})
169+
"num-units": "num_units",
170+
"channel": "channel"})
165171

166172
model = mock.Mock()
167173
model._deploy = base.AsyncMock(return_value=None)
168174
model._add_store_resources = base.AsyncMock(return_value=["resource1"])
169175

170176
context = mock.Mock()
171-
context.resolve.return_value = "charm1"
177+
context.resolve.return_value = "cs:charm1"
178+
context.origins = {"cs:charm1": {"channel/stable": {}}}
172179
context.trusted = False
173180
context.model = model
174181

@@ -177,11 +184,11 @@ async def test_run(self, event_loop):
177184

178185
model._add_store_resources.assert_called_once()
179186
model._add_store_resources.assert_called_with("application",
180-
"charm1",
187+
"cs:charm1",
181188
overrides="resources")
182189

183190
model._deploy.assert_called_once()
184-
model._deploy.assert_called_with(charm_url="charm1",
191+
model._deploy.assert_called_with(charm_url="cs:charm1",
185192
application="application",
186193
series="series",
187194
config="options",
@@ -192,6 +199,46 @@ async def test_run(self, event_loop):
192199
devices="devices",
193200
num_units="num_units")
194201

202+
203+
@pytest.mark.asyncio
204+
async def test_run_with_charmhub_charm(self, event_loop):
205+
change = AddApplicationChange(1, [], params={"charm": "charm",
206+
"series": "series",
207+
"application": "application",
208+
"options": "options",
209+
"constraints": "constraints",
210+
"storage": "storage",
211+
"endpoint-bindings": "endpoint_bindings",
212+
"resources": "resources",
213+
"devices": "devices",
214+
"num-units": "num_units",
215+
"channel": "channel"})
216+
217+
model = mock.Mock()
218+
model._deploy = base.AsyncMock(return_value=None)
219+
model._add_store_resources = base.AsyncMock(return_value=["resource1"])
220+
221+
context = mock.Mock()
222+
context.resolve.return_value = "ch:charm1"
223+
context.origins = {"ch:charm1": {"channel/stable": {}}}
224+
context.trusted = False
225+
context.model = model
226+
227+
result = await change.run(context)
228+
assert result == "application"
229+
230+
model._deploy.assert_called_once()
231+
model._deploy.assert_called_with(charm_url="ch:charm1",
232+
application="application",
233+
series="series",
234+
config="options",
235+
constraints="constraints",
236+
endpoint_bindings="endpoint_bindings",
237+
resources={},
238+
storage="storage",
239+
devices="devices",
240+
num_units="num_units")
241+
195242
@pytest.mark.asyncio
196243
async def test_run_local(self, event_loop):
197244
change = AddApplicationChange(1, [], params={"charm": "local:charm",
@@ -240,7 +287,8 @@ def test_list_params_juju_2_6(self):
240287
"requires": [],
241288
"charm": "charm",
242289
"series": "series",
243-
"channel": None}, change.__dict__)
290+
"channel": None,
291+
"architecture": None}, change.__dict__)
244292

245293
def test_list_params_juju_2_7(self):
246294
change = AddCharmChange(1, [], params=["charm",
@@ -250,17 +298,20 @@ def test_list_params_juju_2_7(self):
250298
"requires": [],
251299
"charm": "charm",
252300
"series": "series",
253-
"channel": "channel"}, change.__dict__)
301+
"channel": "channel",
302+
"architecture": None}, change.__dict__)
254303

255304
def test_dict_params(self):
256305
change = AddCharmChange(1, [], params={"charm": "charm",
257306
"series": "series",
258-
"channel": "channel"})
307+
"channel": "channel",
308+
"architecture": "architecture"})
259309
self.assertEqual({"change_id": 1,
260310
"requires": [],
261311
"charm": "charm",
262312
"series": "series",
263-
"channel": "channel"}, change.__dict__)
313+
"channel": "channel",
314+
"architecture": "architecture"}, change.__dict__)
264315

265316
def test_dict_params_missing_data(self):
266317
change = AddCharmChange(1, [], params={"charm": "charm",
@@ -269,14 +320,15 @@ def test_dict_params_missing_data(self):
269320
"requires": [],
270321
"charm": "charm",
271322
"series": "series",
272-
"channel": None}, change.__dict__)
323+
"channel": None,
324+
"architecture": None}, change.__dict__)
273325

274326

275327
class TestAddCharmChangeRun:
276328

277329
@pytest.mark.asyncio
278330
async def test_run(self, event_loop):
279-
change = AddCharmChange(1, [], params={"charm": "charm",
331+
change = AddCharmChange(1, [], params={"charm": "cs:charm",
280332
"series": "series",
281333
"channel": "channel"})
282334

@@ -286,15 +338,20 @@ async def test_run(self, event_loop):
286338
client_facade = mock.Mock()
287339
client_facade.AddCharm = base.AsyncMock(return_value=None)
288340

341+
model = mock.Mock()
342+
model._add_charm = base.AsyncMock(return_value=None)
343+
289344
context = mock.Mock()
290345
context.charmstore = charmstore
291346
context.client_facade = client_facade
347+
context.origins = {}
348+
context.model = model
292349

293350
result = await change.run(context)
294351
assert result == "entity_id"
295352

296353
charmstore.entityId.assert_called_once()
297-
charmstore.entityId.assert_called_with("charm")
354+
charmstore.entityId.assert_called_with("cs:charm")
298355

299356
client_facade.AddCharm.assert_called_once()
300357
client_facade.AddCharm.assert_called_with(channel=None,

tests/unit/test_url.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def test_parse_v1_series(self):
3232
class TestURLV2(unittest.TestCase):
3333
def test_parse_charmhub(self):
3434
u = URL.parse("ch:arm64/bionic/mysql-1")
35-
self.assertEqual(u, URL(Schema.CHARM_HUB, name="mysql", architecture="amd64", series="bionic", revision=1))
35+
self.assertEqual(u, URL(Schema.CHARM_HUB, name="mysql", architecture="arm64", series="bionic", revision=1))
3636

3737
def test_parse_charmhub_with_no_series(self):
3838
u = URL.parse("ch:arm64/mysql")
39-
self.assertEqual(u, URL(Schema.CHARM_HUB, name="mysql", architecture="amd64"))
39+
self.assertEqual(u, URL(Schema.CHARM_HUB, name="mysql", architecture="arm64"))
4040

4141
def test_parse_charmhub_with_no_series_arch(self):
4242
u = URL.parse("ch:mysql")

0 commit comments

Comments
 (0)