Beispiel #1
0
def test_revisions_name_from_metadata_problem(store_mock):
    """The metadata wasn't there to get the name."""
    args = Namespace(name=None)
    with patch('charmcraft.commands.store.get_name_from_metadata') as mock:
        mock.return_value = None
        with pytest.raises(CommandError) as cm:
            ListRevisionsCommand('group').run(args)
        assert str(cm.value) == (
            "Can't access name in 'metadata.yaml' file. The 'revisions' command needs to "
            "be executed in a valid project's directory, or indicate the charm name with "
            "the --name option.")
Beispiel #2
0
def test_revisions_name_from_metadata_ok(store_mock):
    """The charm name is retrieved succesfully from the metadata."""
    store_mock.list_revisions.return_value = []
    args = Namespace(name=None)
    with patch('charmcraft.commands.store.get_name_from_metadata') as mock:
        mock.return_value = 'test-name'
        ListRevisionsCommand('group').run(args)

    assert store_mock.mock_calls == [
        call.list_revisions('test-name'),
    ]
Beispiel #3
0
def test_revisions_empty(caplog, store_mock):
    """No results from the store."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    store_response = []
    store_mock.list_revisions.return_value = store_response

    args = Namespace(name='testcharm')
    ListRevisionsCommand('group').run(args)

    expected = [
        "Nothing found",
    ]
    assert expected == [rec.message for rec in caplog.records]
Beispiel #4
0
def test_revisions_errors_simple(caplog, store_mock):
    """Support having one case with a simple error."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    store_response = [
        Revision(
            revision=1, version=None, created_at=datetime.datetime(2020, 7, 3, 20, 30, 40),
            status='rejected', errors=[Error(message="error text", code='broken')]),
    ]
    store_mock.list_revisions.return_value = store_response

    args = Namespace(name='testcharm')
    ListRevisionsCommand('group').run(args)

    expected = [
        "Revision    Version    Created at    Status",
        "1                      2020-07-03    rejected: error text [broken]",
    ]
    assert expected == [rec.message for rec in caplog.records]
Beispiel #5
0
def test_revisions_version_null(caplog, store_mock):
    """Support the case of version being None."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    store_response = [
        Revision(
            revision=1, version=None, created_at=datetime.datetime(2020, 7, 3, 20, 30, 40),
            status='accepted', errors=[]),
    ]
    store_mock.list_revisions.return_value = store_response

    args = Namespace(name='testcharm')
    ListRevisionsCommand('group').run(args)

    expected = [
        "Revision    Version    Created at    Status",
        "1                      2020-07-03    accepted",
    ]
    assert expected == [rec.message for rec in caplog.records]
Beispiel #6
0
def test_revisions_simple(caplog, store_mock):
    """Happy path of one result from the Store."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    store_response = [
        Revision(
            revision=1, version='v1', created_at=datetime.datetime(2020, 7, 3, 20, 30, 40),
            status='accepted', errors=[]),
    ]
    store_mock.list_revisions.return_value = store_response

    args = Namespace(name='testcharm')
    ListRevisionsCommand('group').run(args)

    assert store_mock.mock_calls == [
        call.list_revisions('testcharm'),
    ]
    expected = [
        "Revision    Version    Created at    Status",
        "1           v1         2020-07-03    accepted",
    ]
    assert expected == [rec.message for rec in caplog.records]
Beispiel #7
0
def test_revisions_ordered_by_revision(caplog, store_mock):
    """Results are presented ordered by revision in the table."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    # three Revisions with all values weirdly similar, the only difference is revision, so
    # we really assert later that it was used for ordering
    tstamp = datetime.datetime(2020, 7, 3, 20, 30, 40)
    store_response = [
        Revision(revision=1, version='v1', created_at=tstamp, status='accepted', errors=[]),
        Revision(revision=3, version='v1', created_at=tstamp, status='accepted', errors=[]),
        Revision(revision=2, version='v1', created_at=tstamp, status='accepted', errors=[]),
    ]
    store_mock.list_revisions.return_value = store_response

    args = Namespace(name='testcharm')
    ListRevisionsCommand('group').run(args)

    expected = [
        "Revision    Version    Created at    Status",
        "3           v1         2020-07-03    accepted",
        "2           v1         2020-07-03    accepted",
        "1           v1         2020-07-03    accepted",
    ]
    assert expected == [rec.message for rec in caplog.records]