4a95a271b66b4126407e01fd7c633f93678da2ec
[osm/N2VC.git] / tests / integration / test_errors.py
1 import pytest
2
3 from .. import base
4
5 MB = 1
6 GB = 1024
7
8
9 @base.bootstrapped
10 @pytest.mark.asyncio
11 async def test_juju_api_error(event_loop):
12 '''
13 Verify that we raise a JujuAPIError for responses with an error in
14 a top level key (for completely invalid requests).
15
16 '''
17 from juju.errors import JujuAPIError
18
19 async with base.CleanModel() as model:
20 with pytest.raises(JujuAPIError):
21 await model.add_machine(constraints={'mem': 'foo'})
22
23
24 @base.bootstrapped
25 @pytest.mark.asyncio
26 async def test_juju_error_in_results_list(event_loop):
27 '''
28 Replicate the code that caused
29 https://github.com/juju/python-libjuju/issues/67, and verify that
30 we get a JujuError instead of passing silently by the failure.
31
32 (We don't raise a JujuAPIError, because the request isn't
33 completely invalid -- it's just passing a tag that doesn't exist.)
34
35 This also verifies that we will raise a JujuError any time there
36 is an error in one of a list of results.
37
38 '''
39 from juju.errors import JujuError
40 from juju.client import client
41
42 async with base.CleanModel() as model:
43 # Replicate
44 ann_facade = client.AnnotationsFacade()
45 ann_facade.connect(model.connection)
46
47 ann = client.EntityAnnotations(
48 entity='badtag',
49 annotations={'gui-x': '1', 'gui-y': '1'},
50 )
51 with pytest.raises(JujuError):
52 return await ann_facade.Set([ann])
53
54
55 @base.bootstrapped
56 @pytest.mark.asyncio
57 async def test_juju_error_in_result(event_loop):
58 '''
59 Verify that we raise a JujuError when appropraite when we are
60 looking at a single result coming back.
61
62 # TODO: write this!
63
64 '''
65 pass