def _build_revision(revno, version): """Helper to build a revision.""" return Revision(revision=revno, version=version, created_at=datetime.datetime(2020, 7, 3, 20, 30, 40), status='accepted', errors=[])
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]
def test_release_revision_guessing_ok(caplog, store_mock): """Release after guessing the revision.""" caplog.set_level(logging.INFO, logger="charmcraft.commands") # make the store to return some revisions badly ordered so we're sure we're getting the max 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 channels = ['somechannel'] args = Namespace(name='testcharm', revision=None, channels=channels) ReleaseCommand('group').run(args) assert store_mock.mock_calls == [ call.list_revisions('testcharm'), call.release('testcharm', 3, channels), ] expected = "Revision 3 of charm 'testcharm' released to somechannel" assert [expected] == [rec.message for rec in caplog.records]
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]
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]
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]