|
1 | 1 | import unittest |
2 | 2 |
|
3 | | -from juju.utils import juju_config_dir, juju_ssh_key_paths |
| 3 | +from juju import utils |
| 4 | +from juju.client import client |
4 | 5 |
|
5 | 6 |
|
6 | 7 | class TestDirResolve(unittest.TestCase): |
7 | 8 | def test_config_dir(self): |
8 | | - config_dir = juju_config_dir() |
| 9 | + config_dir = utils.juju_config_dir() |
9 | 10 | assert 'local/share/juju' in config_dir |
10 | 11 |
|
11 | 12 | def test_juju_ssh_key_paths(self): |
12 | | - public, private = juju_ssh_key_paths() |
| 13 | + public, private = utils.juju_ssh_key_paths() |
13 | 14 | assert public.endswith('ssh/juju_id_rsa.pub') |
14 | 15 | assert private.endswith('ssh/juju_id_rsa') |
| 16 | + |
| 17 | + |
| 18 | +class TestShouldUpgradeResource(unittest.TestCase): |
| 19 | + def test_should_upgrade_resource_no_same_rev(self): |
| 20 | + # fields are trimmed for readability |
| 21 | + res = {'created-at': '2019-10-24T20:45:19.201000', |
| 22 | + 'description': 'The policy.d overrides file', |
| 23 | + 'download': {'hash-sha-256': 'e3b0c4', 'hash-sha-384': '38b060a751ac914898b95b', |
| 24 | + 'hash-sha-512': 'cf83e1357eef1a538327af927da3e', |
| 25 | + 'hash-sha3-384': '0c63a75b1bbed1e058d5f004', |
| 26 | + 'size': 0, |
| 27 | + 'url': 'https://api.charmhub.io/api/v1/resMGU0L516cGTTwNam.policyd-override_0'}, |
| 28 | + 'filename': 'policyd-override.zip', 'name': 'policyd-override', 'revision': 0, 'type': 'file'} |
| 29 | + |
| 30 | + existing = { |
| 31 | + 'policyd-override': |
| 32 | + client.Resource(charmresource=None, |
| 33 | + application='keystone', id_='keystone/policyd-override', pending_id='', |
| 34 | + timestamp='0001-01-01T00:00:00Z', username='', name='policyd-override', |
| 35 | + origin='store', type='file', path='policyd-override.zip', |
| 36 | + description='The policy.doverrides file', |
| 37 | + revision=0, fingerprint='OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb', |
| 38 | + size=0)} |
| 39 | + assert not utils.should_upgrade_resource(res, existing) |
| 40 | + |
| 41 | + def test_should_upgrade_resource_no_local_upload(self): |
| 42 | + # fields are trimmed for readability |
| 43 | + res = {'created-at': '2019-10-24T20:45:19.201000', |
| 44 | + 'description': 'The policy.d overrides file', |
| 45 | + 'download': {'hash-sha-256': 'e3b0c4', 'hash-sha-384': '38b060a751ac914898b95b', |
| 46 | + 'hash-sha-512': 'cf83e1357eef1a538327af927da3e', |
| 47 | + 'hash-sha3-384': '0c63a75b1bbed1e058d5f004', |
| 48 | + 'size': 0, |
| 49 | + 'url': 'https://api.charmhub.io/api/v1/resMGU0L516cGTTwNam.policyd-override_0'}, |
| 50 | + 'filename': 'policyd-override.zip', 'name': 'local_res', 'revision': 0, |
| 51 | + 'type': 'file'} |
| 52 | + |
| 53 | + existing = { |
| 54 | + 'local_res': |
| 55 | + client.Resource(charmresource=None, |
| 56 | + application='keystone', id_='keystone/policyd-override', pending_id='', |
| 57 | + timestamp='0001-01-01T00:00:00Z', username='', name='policyd-override', |
| 58 | + origin='upload', type='file', path='policyd-override.zip', |
| 59 | + description='The policy.doverrides file', |
| 60 | + revision=0, fingerprint='OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb', |
| 61 | + size=0)} |
| 62 | + assert not utils.should_upgrade_resource(res, existing) |
| 63 | + |
| 64 | + def test_should_upgrade_resource_yes_new_revision(self): |
| 65 | + # fields are trimmed for readability |
| 66 | + res = {'created-at': '2019-10-24T20:45:19.201000', |
| 67 | + 'description': 'The policy.d overrides file', |
| 68 | + 'download': {'hash-sha-256': 'e3b0c4', 'hash-sha-384': '38b060a751ac914898b95b', |
| 69 | + 'hash-sha-512': 'cf83e1357eef1a538327af927da3e', |
| 70 | + 'hash-sha3-384': '0c63a75b1bbed1e058d5f004', |
| 71 | + 'size': 0, |
| 72 | + 'url': 'https://api.charmhub.io/api/v1/resMGU0L516cGTTwNam.policyd-override_0'}, |
| 73 | + 'filename': 'policyd-override.zip', 'name': 'policyd-override', 'revision': 1, |
| 74 | + 'type': 'file'} |
| 75 | + |
| 76 | + existing = { |
| 77 | + 'policyd-override': |
| 78 | + client.Resource(charmresource=None, |
| 79 | + application='keystone', id_='keystone/policyd-override', pending_id='', |
| 80 | + timestamp='0001-01-01T00:00:00Z', username='', name='policyd-override', |
| 81 | + origin='store', type='file', path='policyd-override.zip', |
| 82 | + description='The policy.doverrides file', |
| 83 | + revision=0, fingerprint='OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb', |
| 84 | + size=0)} |
| 85 | + assert utils.should_upgrade_resource(res, existing) |
0 commit comments