def test_amazon_with_rollout():
    with pytest.raises(WrongArgumentGiven):
        push_apk(APKS,
                 'amazon',
                 CLIENT_ID,
                 CLIENT_SECRET, [],
                 rollout_percentage=50)
Exemplo n.º 2
0
def test_upload_apk_without_locales_updated(edit_service_mock, monkeypatch):
    set_up_mocks(monkeypatch, edit_service_mock)

    push_apk(APKS, SERVICE_ACCOUNT, credentials, 'alpha',
             AnyPackageNamesCheck())

    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
Exemplo n.º 3
0
def test_upload_apk(edit_service_mock, monkeypatch):
    set_up_mocks(monkeypatch, edit_service_mock)

    push_apk(APKS, SERVICE_ACCOUNT, credentials, 'alpha',
             AnyPackageNamesCheck())

    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()
Exemplo n.º 4
0
def test_valid_rollout_percentage(edit_service_mock, monkeypatch):
    set_up_mocks(monkeypatch, edit_service_mock)
    valid_percentage = 50

    push_apk(APKS,
             SERVICE_ACCOUNT,
             credentials,
             'rollout',
             AnyPackageNamesCheck(),
             rollout_percentage=valid_percentage)
    edit_service_mock.update_track.assert_called_once_with(
        'rollout', ['0', '1'], valid_percentage)
    edit_service_mock.update_track.reset_mock()
def test_amazon(monkeypatch):
    mock_metadata = patch_extract_metadata(monkeypatch)
    mock_edit = patch_store_transaction(monkeypatch, store.AmazonStoreEdit)

    push_apk(APKS,
             'amazon',
             CLIENT_ID,
             CLIENT_SECRET, [],
             contact_server=False)
    mock_edit.update_app.assert_called_once_with([
        (apk_arm, mock_metadata[apk_arm]),
        (apk_x86, mock_metadata[apk_x86]),
    ])
Exemplo n.º 6
0
def test_push_apk_tunes_down_logs(monkeypatch):
    main_logging_mock = MagicMock()
    monkeypatch.setattr('mozapkpublisher.push_apk.main_logging',
                        main_logging_mock)
    monkeypatch.setattr('mozapkpublisher.push_apk.PushAPK', MagicMock())

    push_apk(APKS,
             SERVICE_ACCOUNT,
             credentials,
             'alpha',
             AnyPackageNamesCheck(),
             contact_google_play=False)

    main_logging_mock.init.assert_called_once_with()
def test_google(monkeypatch):
    mock_metadata = patch_extract_metadata(monkeypatch)
    edit_mock = patch_store_transaction(monkeypatch, store.GooglePlayEdit)
    push_apk(APKS,
             'google',
             SERVICE_ACCOUNT,
             credentials, [],
             'rollout',
             rollout_percentage=50,
             contact_server=False)
    edit_mock.update_app.assert_called_once_with([
        (apk_arm, mock_metadata[apk_arm]),
        (apk_x86, mock_metadata[apk_x86]),
    ], 'rollout', 50)
Exemplo n.º 8
0
def test_invalid_rollout_percentage(edit_service_mock, monkeypatch):
    with pytest.raises(WrongArgumentGiven):
        # missing percentage
        push_apk(APKS, SERVICE_ACCOUNT, credentials, 'rollout',
                 AnyPackageNamesCheck())

    valid_percentage = 1
    invalid_track = 'production'
    with pytest.raises(WrongArgumentGiven):
        push_apk(APKS,
                 SERVICE_ACCOUNT,
                 credentials,
                 invalid_track,
                 AnyPackageNamesCheck(),
                 rollout_percentage=valid_percentage)
Exemplo n.º 9
0
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)

    push_apk(APKS,
             SERVICE_ACCOUNT,
             credentials,
             'alpha',
             AnyPackageNamesCheck(),
             contact_google_play=False)
def publish_to_googleplay(payload,
                          product_config,
                          apk_files,
                          contact_google_play,
                          google_play_strings_file=None):
    track = payload['google_play_track']
    valid_track_values = craft_valid_track_values(
        product_config['has_nightly_track'])
    if track not in valid_track_values:
        raise TaskVerificationError(
            'Track name "{}" not valid. Allowed values: {}'.format(
                track, valid_track_values))

    if product_config.get('skip_check_package_names'):
        package_names_check = AnyPackageNamesCheck()
    elif product_config.get('expected_package_names'):
        package_names_check = ExpectedPackageNamesCheck(
            product_config['expected_package_names'])
    else:
        raise ConfigValidationError(
            'Expected product config to either have "skip_check_package_names" or '
            '"expected_package_names"')

    with open(product_config['certificate'], 'rb') as certificate:
        push_apk(
            apks=apk_files,
            service_account=product_config['service_account'],
            google_play_credentials_file=certificate,
            track=track,
            package_names_check=package_names_check,
            rollout_percentage=payload.get(
                'rollout_percentage'),  # may be None
            google_play_strings=NoGooglePlayStrings()
            if google_play_strings_file is None else
            FileGooglePlayStrings(google_play_strings_file),
            commit=should_commit_transaction(payload),
            # Only allowed to connect to Google Play if the configuration of the pushapkscript instance allows it
            contact_google_play=contact_google_play,
            skip_check_ordered_version_codes=bool(
                product_config.get('skip_check_ordered_version_codes')),
            skip_check_multiple_locales=bool(
                product_config.get('skip_check_multiple_locales')),
            skip_check_same_locales=bool(
                product_config.get('skip_check_same_locales')),
            skip_checks_fennec=bool(product_config.get('skip_checks_fennec')),
        )
Exemplo n.º 11
0
def publish(product_config, publish_config, apk_files, contact_server):
    push_apk(
        apks=apk_files,
        target_store=publish_config['target_store'],
        username=publish_config['username'],
        secret=publish_config['secret'],
        expected_package_names=publish_config['package_names'],
        track=publish_config.get('google_track'),
        rollout_percentage=publish_config.get('google_rollout_percentage'),
        dry_run=publish_config['dry_run'],
        # Only allowed to connect to store server if the configuration of the pushapkscript
        # instance allows it
        contact_server=contact_server,
        skip_check_ordered_version_codes=bool(product_config.get('skip_check_ordered_version_codes')),
        skip_check_multiple_locales=bool(product_config.get('skip_check_multiple_locales')),
        skip_check_same_locales=bool(product_config.get('skip_check_same_locales')),
        skip_checks_fennec=bool(product_config.get('skip_checks_fennec')),
    )
Exemplo n.º 12
0
def test_push_apk_tunes_down_logs(monkeypatch):
    main_logging_mock = MagicMock()
    monkeypatch.setattr('mozapkpublisher.push_apk.main_logging',
                        main_logging_mock)
    monkeypatch.setattr(
        'mozapkpublisher.push_apk.extract_and_check_apks_metadata',
        MagicMock())
    monkeypatch.setattr('mozapkpublisher.push_apk._apks_by_package_name',
                        MagicMock())

    push_apk(APKS,
             'google',
             SERVICE_ACCOUNT,
             credentials, [],
             'alpha',
             contact_server=False)

    main_logging_mock.init.assert_called_once_with()
Exemplo n.º 13
0
def test_upload_apk_with_locales_updated_from_file(edit_service_mock,
                                                   monkeypatch):
    set_up_mocks(monkeypatch, edit_service_mock)

    with NamedTemporaryFile('r+') as f:
        json.dump(DUMMY_TRANSLATIONS_PER_GOOGLE_PLAY_LOCALE, f)
        f.seek(0)
        push_apk(APKS,
                 SERVICE_ACCOUNT,
                 credentials,
                 'alpha',
                 AnyPackageNamesCheck(),
                 google_play_strings=FileGooglePlayStrings(f))

    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
Exemplo n.º 14
0
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)

    push_apk(APKS,
             SERVICE_ACCOUNT,
             credentials,
             'alpha',
             AnyPackageNamesCheck(),
             google_play_strings=StoreGooglePlayStrings())

    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()
Exemplo n.º 15
0
def test_amazon_with_track():
    with pytest.raises(WrongArgumentGiven):
        push_apk(APKS, 'amazon', CLIENT_ID, CLIENT_SECRET, [], 'alpha')
Exemplo n.º 16
0
def test_google_no_track():
    with pytest.raises(WrongArgumentGiven):
        push_apk(APKS, 'google', SERVICE_ACCOUNT, credentials, [])