def test_release_force(clone_from_github_mock, check_output_mock, open_mock, date_mock, expanduser_mock): repo_mock = Mock() repo_mock.latest_tag.return_value = '20.1.0' repo_mock.authors_since.return_value = ['*****@*****.**', '*****@*****.**'] repo_mock.diff_name_status.return_value = [ ('apis/foo/v1.ts', _git.Status.ADDED), ('apis/baz/v1.ts', _git.Status.UPDATED), ] side_effect = common.clone_from_github_mock_side_effect(repo_mock) clone_from_github_mock.side_effect = side_effect check_output_mock.return_value = '20.1.0' open_package_json_mock = mock_open(read_data=('{"version": "20.1.0"}')) open_changelog_md_mock = mock_open(read_data='...\n') open_npmrc_mock = mock_open() open_index_md_mock = mock_open( read_data=('...\n\n' '### ...\n\n' '* [v20.1.0 (latest)](...)\n' '...\n')) open_mock.side_effect = [ open_package_json_mock.return_value, open_package_json_mock.return_value, open_changelog_md_mock.return_value, open_changelog_md_mock.return_value, open_npmrc_mock.return_value, open_index_md_mock.return_value, open_index_md_mock.return_value ] date_mock.today.return_value.strftime.return_value = '1 September 2017' expanduser_mock.side_effect = lambda x: '/home/test' + x[1:] google_api_nodejs_client.release( '/tmp', common.GITHUB_ACCOUNT, _NPM_ACCOUNT, force=True) # We don't bother verifying all calls in this case, since we only want to # verify that the different authors check was passed. assert repo_mock.mock_calls == [ call.latest_tag(), call.authors_since('20.1.0'), call.diff_name_status(rev='20.1.0'), call.commit('20.2.0', 'Alice', '*****@*****.**'), call.tag('20.2.0'), call.push(), call.push(tags=True), call.checkout('gh-pages'), call.add(['latest', '20.2.0']), call.commit('20.2.0', 'Alice', '*****@*****.**'), call.push(branch='gh-pages'), call.checkout('master') ]
def test_release_force(clone_from_github_mock, check_output_mock, open_mock, expanduser_mock, chmod_mock): repo_mock = Mock() repo_mock.latest_tag.return_value = '0.13.6' repo_mock.authors_since.return_value = ['*****@*****.**', '*****@*****.**'] repo_mock.diff_name_status.return_value = [ ('generated/google/apis/foo_v1.rb', _git.Status.ADDED), ('generated/google/apis/baz_v1.rb', _git.Status.UPDATED), ] side_effect = common.clone_from_github_mock_side_effect(repo_mock) clone_from_github_mock.side_effect = side_effect check_output_mock.return_value = 'google-api-client (0.13.6)' open_version_rb_mock = mock_open( read_data=('...\n' 'module Google\n' ' module Apis\n' ' # Client library version\n' ' VERSION = \'0.13.6\'\n' ' ...\n')) open_changelog_md_mock = mock_open(read_data='...\n') open_credentials_mock = mock_open() open_mock.side_effect = [ open_version_rb_mock.return_value, open_version_rb_mock.return_value, open_changelog_md_mock.return_value, open_changelog_md_mock.return_value, open_credentials_mock.return_value ] expanduser_mock.side_effect = lambda x: '/home/test' + x[1:] google_api_ruby_client.release('/tmp', common.GITHUB_ACCOUNT, _RUBYGEMS_ACCOUNT, force=True) # We don't bother verifying all calls in this case, since we only want to # verify that the different authors check was passed. assert repo_mock.mock_calls == [ call.latest_tag(), call.authors_since('0.13.6'), call.diff_name_status(rev='0.13.6'), call.commit('0.13.7', 'Alice', '*****@*****.**'), call.tag('0.13.7'), call.push(), call.push(tags=True), ]
def test_upload_straightforward(client_mock, caplog, config): """The full and successful upload case.""" caplog.set_level(logging.DEBUG, logger="charmcraft.commands") store = Store(config.charmhub) # the first response, for when pushing bytes test_upload_id = 'test-upload-id' client_mock.push.return_value = test_upload_id # the second response, for telling the store it was pushed test_status_url = 'https://store.c.c/status' client_mock.post.return_value = {'status-url': test_status_url} # the third response, status ok (note the patched UPLOAD_ENDING_STATUSES below) test_revision = 123 test_status_ok = 'test-status' status_response = { 'revisions': [{ 'status': test_status_ok, 'revision': test_revision, 'errors': None }] } client_mock.get.return_value = status_response test_status_resolution = 'test-ok-or-not' fake_statuses = {test_status_ok: test_status_resolution} test_charm_name = 'test-name' test_filepath = 'test-filepath' with patch.dict('charmcraft.commands.store.store.UPLOAD_ENDING_STATUSES', fake_statuses): result = store.upload(test_charm_name, test_filepath) # check all client calls assert client_mock.mock_calls == [ call.push(test_filepath), call.post('/v1/charm/{}/revisions'.format(test_charm_name), {'upload-id': test_upload_id}), call.get(test_status_url), ] # check result (build after patched ending struct) assert result.ok == test_status_resolution assert result.status == test_status_ok assert result.revision == test_revision # check logs expected = [ "Upload test-upload-id started, got status url https://store.c.c/status", "Status checked: " + str(status_response), ] assert expected == [rec.message for rec in caplog.records]
def test_upload_straightforward(client_mock, caplog, config): """The full and successful upload case.""" caplog.set_level(logging.DEBUG, logger="charmcraft.commands") store = Store(config.charmhub) # the first response, for when pushing bytes test_upload_id = "test-upload-id" client_mock.push.return_value = test_upload_id # the second response, for telling the store it was pushed test_status_url = "https://store.c.c/status" client_mock.post.return_value = {"status-url": test_status_url} # the third response, status ok (note the patched UPLOAD_ENDING_STATUSES below) test_revision = 123 test_status_ok = "test-status" status_response = { "revisions": [{ "status": test_status_ok, "revision": test_revision, "errors": None }] } client_mock.get.return_value = status_response test_status_resolution = "test-ok-or-not" fake_statuses = {test_status_ok: test_status_resolution} test_filepath = "test-filepath" test_endpoint = "/v1/test/revisions/endpoint/" with patch.dict("charmcraft.commands.store.store.UPLOAD_ENDING_STATUSES", fake_statuses): result = store._upload(test_endpoint, test_filepath) # check all client calls assert client_mock.mock_calls == [ call.push(test_filepath), call.post(test_endpoint, {"upload-id": test_upload_id}), call.get(test_status_url), ] # check result (build after patched ending struct) assert result.ok == test_status_resolution assert result.status == test_status_ok assert result.revision == test_revision # check logs expected = [ "Upload test-upload-id started, got status url https://store.c.c/status", "Status checked: " + str(status_response), ] assert expected == [rec.message for rec in caplog.records]
def test_release_force(clone_from_github_mock, check_output_mock): repo_mock = Mock() repo_mock.latest_tag.return_value = 'v0.1' repo_mock.authors_since.return_value = ['*****@*****.**', '*****@*****.**'] side_effect = common.clone_from_github_mock_side_effect(repo_mock) clone_from_github_mock.side_effect = side_effect google_api_php_client_services.release('/tmp', common.GITHUB_ACCOUNT, force=True) # We don't bother verifying all calls in this case, since we only want to # verify that the different authors check was passed. assert repo_mock.mock_calls == [ call.latest_tag(), call.authors_since('v0.1'), call.tag('v0.2'), call.push(tags=True) ]
def test_upload_including_extra_parameters(client_mock, caplog, config): """Verify that the upload includes extra parameters if given.""" caplog.set_level(logging.DEBUG, logger="charmcraft.commands") store = Store(config.charmhub) # the first response, for when pushing bytes test_upload_id = "test-upload-id" client_mock.push.return_value = test_upload_id # the second response, for telling the store it was pushed test_status_url = "https://store.c.c/status" client_mock.post.return_value = {"status-url": test_status_url} # the third response, status ok (note the patched UPLOAD_ENDING_STATUSES below) test_revision = 123 test_status_ok = "test-status" status_response = { "revisions": [{ "status": test_status_ok, "revision": test_revision, "errors": None }] } client_mock.get.return_value = status_response test_status_resolution = "test-ok-or-not" fake_statuses = {test_status_ok: test_status_resolution} test_filepath = "test-filepath" test_endpoint = "/v1/test/revisions/endpoint/" extra_fields = {"extra-key": "1", "more": "2"} with patch.dict("charmcraft.commands.store.store.UPLOAD_ENDING_STATUSES", fake_statuses): store._upload(test_endpoint, test_filepath, extra_fields=extra_fields) # check all client calls assert client_mock.mock_calls == [ call.push(test_filepath), call.post(test_endpoint, { "upload-id": test_upload_id, "extra-key": "1", "more": "2" }), call.get(test_status_url), ]