def publish_to_googleplay(context, apks, google_play_strings_path=None): from mozapkpublisher.push_apk import PushAPK push_apk = PushAPK(config=craft_push_apk_config( context, apks, google_play_strings_path, )) push_apk.run()
def test_tracks(): config = copy(VALID_CONFIG) config['track'] = 'fake' with pytest.raises(WrongArgumentGiven): PushAPK(config) for track in ('alpha', 'beta', 'production'): config['track'] = track PushAPK(config)
def test_upload_apk_with_locales_updated_from_l10n_store( edit_service_mock, monkeypatch): set_up_mocks(monkeypatch, edit_service_mock) monkeypatch.setattr( store_l10n, '_translate_moz_locate_into_google_play_one', lambda locale: 'es-US' if locale == 'es-MX' else locale) config = copy(VALID_CONFIG) PushAPK(config).run() expected_locales = ( ('es-US', 'Navegador web Firefox', 'Corto', 'Descripcion larga', 'Mire a esta caracteristica'), ('en-GB', 'Firefox for Android', 'Short', 'Long description', 'Check out this cool feature!'), ('en-US', 'Firefox for Android', 'Short', 'Long description', 'Check out this cool feature!'), ) for (locale, title, short_description, full_description, whats_new) in expected_locales: edit_service_mock.update_listings.assert_any_call( locale, full_description=full_description, short_description=short_description, title=title) for version_code in range(2): edit_service_mock.update_whats_new.assert_any_call( locale, str(version_code), whats_new=whats_new) assert edit_service_mock.update_listings.call_count == 3 assert edit_service_mock.update_whats_new.call_count == 6 edit_service_mock.commit_transaction.assert_called_once_with()
def test_invalid_rollout_percentage(edit_service_mock, monkeypatch): config = copy(VALID_CONFIG) config['track'] = 'rollout' with pytest.raises(WrongArgumentGiven): # missing percentage PushAPK(config) for invalid_percentage in (-1, 0.5, 101): config['rollout_percentage'] = invalid_percentage with pytest.raises(WrongArgumentGiven): PushAPK(config) valid_percentage = 1 invalid_track = 'production' config['rollout_percentage'] = valid_percentage config['track'] = invalid_track with pytest.raises(WrongArgumentGiven): PushAPK(config)
def test_upload_apk(edit_service_mock, monkeypatch): set_up_mocks(monkeypatch, edit_service_mock) PushAPK(VALID_CONFIG).run() for apk_file in (apk_arm, apk_x86): edit_service_mock.upload_apk.assert_any_call(apk_file.name) edit_service_mock.update_track.assert_called_once_with( 'alpha', ['0', '1'], None) edit_service_mock.commit_transaction.assert_called_once_with()
def test_upload_apk(monkeypatch): edit_service_mock = craft_service_mock(monkeypatch) monkeypatch.setattr(apk, 'check_if_apk_is_multilocale', lambda _: None) PushAPK(VALID_CONFIG).run() for apk_file in (apk_arm, apk_x86): edit_service_mock.upload_apk.assert_any_call(apk_file.name) edit_service_mock.update_track.assert_called_once_with('alpha', {u'versionCodes': ['0', '1']}) edit_service_mock.commit_transaction.assert_called_once_with()
def test_one_missing_file(): config = copy(VALID_CONFIG) for field in ('credentials', 'apk_x86', 'apk_armv7_v15'): old_value = config[field] del config[field] with pytest.raises(WrongArgumentGiven): PushAPK(config) config[field] = old_value
def test_do_not_contact_google_play_flag_does_not_request_google_play( monkeypatch): monkeypatch.setattr(apk, 'check_if_apk_is_multilocale', lambda _: None) monkeypatch.setattr(apk, 'check_if_apk_has_claimed_architecture', lambda _, __: None) set_translations_per_google_play_locale_code(monkeypatch) config = copy(VALID_CONFIG) config['do_not_contact_google_play'] = True PushAPK(config).run()
def test_valid_rollout_percentage(edit_service_mock, monkeypatch): config = copy(VALID_CONFIG) config['track'] = 'rollout' set_up_mocks(monkeypatch, edit_service_mock) for i in range(0, 101): valid_percentage = i config['rollout_percentage'] = valid_percentage PushAPK(config).run() edit_service_mock.update_track.assert_called_once_with( 'rollout', ['0', '1'], valid_percentage) edit_service_mock.update_track.reset_mock()
def test_do_not_contact_google_play_flag_does_not_request_google_play( monkeypatch): monkeypatch.setattr( extractor, 'extract_metadata', lambda _: { 'package_name': 'org.mozilla.firefox', 'version_code': '1', }) monkeypatch.setattr(checker, 'cross_check_apks', lambda _: None) set_translations_per_google_play_locale_code(monkeypatch) config = copy(VALID_CONFIG) config['do_not_contact_google_play'] = True PushAPK(config).run()
def test_upload_apk_without_locales_updated(edit_service_mock, monkeypatch): set_up_mocks(monkeypatch, edit_service_mock) config = copy(VALID_CONFIG) del config['update_gp_strings_from_l10n_store'] config['no_gp_string_update'] = True PushAPK(config).run() assert edit_service_mock.upload_apk.call_count == 2 assert edit_service_mock.update_track.call_count == 1 assert edit_service_mock.commit_transaction.call_count == 1 assert edit_service_mock.update_listings.call_count == 0 assert edit_service_mock.update_whats_new.call_count == 0
def test_rollout_percentage(monkeypatch): config = copy(VALID_CONFIG) config['track'] = 'rollout' with pytest.raises(WrongArgumentGiven): PushAPK(config) for invalid_percentage in (-1, 0.5, 101): config['rollout_percentage'] = invalid_percentage with pytest.raises(WrongArgumentGiven): PushAPK(config) edit_service_mock = craft_service_mock(monkeypatch) monkeypatch.setattr(apk, 'check_if_apk_is_multilocale', lambda _: None) for i in range(0, 101): valid_percentage = i config['rollout_percentage'] = valid_percentage PushAPK(config).run() edit_service_mock.update_track.assert_called_once_with('rollout', { u'versionCodes': [str(2*i), str(2*i+1)], # Doesn't provide much value to test, only here to fill gaps u'userFraction': valid_percentage / 100.0 # Ensure float in Python 2 }) edit_service_mock.update_track.reset_mock()
def test_upload_apk_with_locales_updated_from_file(edit_service_mock, monkeypatch): set_up_mocks(monkeypatch, edit_service_mock) config = copy(VALID_CONFIG) del config['update_gp_strings_from_l10n_store'] with NamedTemporaryFile('w') as f: json.dump(DUMMY_TRANSLATIONS_PER_GOOGLE_PLAY_LOCALE, f) f.seek(0) config['update_gp_strings_from_file'] = f.name PushAPK(config).run() assert edit_service_mock.upload_apk.call_count == 2 assert edit_service_mock.update_track.call_count == 1 assert edit_service_mock.commit_transaction.call_count == 1 assert edit_service_mock.update_listings.call_count == 3
def test_upload_apk_with_whats_new(monkeypatch): edit_service_mock = craft_service_mock(monkeypatch) monkeypatch.setattr(apk, 'check_if_apk_is_multilocale', lambda _: None) monkeypatch.setattr(store_l10n, 'get_list_locales', lambda _: [u'en-GB', u'es-MX']) monkeypatch.setattr(store_l10n, 'get_translation', lambda _, locale: { 'title': 'Navegador web Firefox', 'long_desc': 'descripcion larga', 'short_desc': 'corto', 'whatsnew': 'Mire a esta caracteristica', } if locale == 'es-MX' else { 'title': 'Firefox for Android', 'long_desc': 'Long description', 'short_desc': 'Short', 'whatsnew': 'Check out this cool feature!', }) monkeypatch.setattr(store_l10n, 'locale_mapping', lambda locale: 'es-US' if locale == 'es-MX' else locale) config = copy(VALID_CONFIG) config['package_name'] = 'org.mozilla.firefox_beta' PushAPK(config).run() expected_locales = ( ('es-US', 'Mire a esta caracteristica'), # Unlike what we could infer from the data input, en-GB is NOT converted into en-US. # en-GB is not meant to be updated and en-US is added to list_locales ('en-US', 'Check out this cool feature!'), ) for (locale, whats_new) in expected_locales: for version_code in range(2): edit_service_mock.update_apk_listings.assert_any_call(locale, str(version_code), body={ 'recentChanges': whats_new }) assert edit_service_mock.update_apk_listings.call_count == 4 edit_service_mock.commit_transaction.assert_called_once_with()
def test_credentials_are_missing(): config = copy(VALID_CONFIG) del config['credentials'] with pytest.raises(WrongArgumentGiven): PushAPK(config)