| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame^] | 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 | ann_facade = client.AnnotationsFacade.from_connection(model.connection) |
| 44 | |
| 45 | ann = client.EntityAnnotations( |
| 46 | entity='badtag', |
| 47 | annotations={'gui-x': '1', 'gui-y': '1'}, |
| 48 | ) |
| 49 | with pytest.raises(JujuError): |
| 50 | return await ann_facade.Set([ann]) |
| 51 | |
| 52 | |
| 53 | @base.bootstrapped |
| 54 | @pytest.mark.asyncio |
| 55 | async def test_juju_error_in_result(event_loop): |
| 56 | ''' |
| 57 | Verify that we raise a JujuError when appropraite when we are |
| 58 | looking at a single result coming back. |
| 59 | |
| 60 | ''' |
| 61 | from juju.errors import JujuError |
| 62 | from juju.client import client |
| 63 | |
| 64 | async with base.CleanModel() as model: |
| 65 | app_facade = client.ApplicationFacade.from_connection(model.connection) |
| 66 | |
| 67 | with pytest.raises(JujuError): |
| 68 | return await app_facade.GetCharmURL('foo') |