Beispiel #1
0
def test_release_with_resources(client_mock, config):
    """Releasing with resources attached."""
    store = Store(config.charmhub)
    r1 = ResourceOption(name='foo', revision=3)
    r2 = ResourceOption(name='bar', revision=17)
    store.release('testname', 123, ['channel1', 'channel2'], [r1, r2])

    expected_body = [
        {
            'revision': 123,
            'channel': 'channel1',
            'resources': [
                {'name': 'foo', 'revision': 3},
                {'name': 'bar', 'revision': 17},
            ]
        }, {
            'revision': 123,
            'channel': 'channel2',
            'resources': [
                {'name': 'foo', 'revision': 3},
                {'name': 'bar', 'revision': 17},
            ]
        }
    ]
    assert client_mock.mock_calls == [
        call.post('/v1/charm/testname/releases', expected_body),
    ]
Beispiel #2
0
def test_release_with_resources(client_mock, config):
    """Releasing with resources attached."""
    store = Store(config.charmhub)
    r1 = ResourceOption(name="foo", revision=3)
    r2 = ResourceOption(name="bar", revision=17)
    store.release("testname", 123, ["channel1", "channel2"], [r1, r2])

    expected_body = [
        {
            "revision": 123,
            "channel": "channel1",
            "resources": [
                {"name": "foo", "revision": 3},
                {"name": "bar", "revision": 17},
            ],
        },
        {
            "revision": 123,
            "channel": "channel2",
            "resources": [
                {"name": "foo", "revision": 3},
                {"name": "bar", "revision": 17},
            ],
        },
    ]
    assert client_mock.mock_calls == [
        call.post("/v1/charm/testname/releases", expected_body),
    ]
Beispiel #3
0
def test_resourceoption_convert_error(value):
    """Error while converting."""
    with pytest.raises(ValueError) as cm:
        ResourceOption()(value)
    assert str(cm.value) == (
        "the resource format must be <name>:<revision> (revision being a positive integer)"
    )
Beispiel #4
0
 def fill_parser(self, parser):
     """Add own parameters to the general parser."""
     parser.add_argument('name', help="The name of charm or bundle")
     parser.add_argument(
         '-r', '--revision', type=SingleOptionEnsurer(int), required=True,
         help='The revision to release')
     parser.add_argument(
         '-c', '--channel', action='append', required=True,
         help="The channel(s) to release to (this option can be indicated multiple times)")
     parser.add_argument(
         '--resource', action='append', type=ResourceOption(), default=[],
         help=(
             "The resource(s) to attach to the release, in the <name>:<revision> format "
             "(this option can be indicated multiple times)"))
Beispiel #5
0
def test_resourceoption_convert_ok():
    """Convert as expected."""
    r = ResourceOption()("foo:13")
    assert r.name == "foo"
    assert r.revision == 13