Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Update mozapk top level abstractions #97

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.2.0] - 2019-07-??

### Changes
* Updates `push_apk(...)` usage to provide typed config, rather than just primitive values

## [3.1.0] - 2019-07-10

### Changes
Expand Down
39 changes: 24 additions & 15 deletions pushapkscript/googleplay.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from mozapkpublisher.common.googleplay import GooglePlayConnection, MockGooglePlayConnection, RolloutTrack, StaticTrack
from mozapkpublisher.push_apk import push_apk

log = logging.getLogger(__name__)
Expand All @@ -8,22 +9,30 @@


def publish_to_googleplay(payload, product_config, publish_config, apk_files, contact_google_play):
with open(publish_config['google_credentials_file'], 'rb') as certificate:
push_apk(
apks=apk_files,
service_account=publish_config['service_account'],
google_play_credentials_file=certificate,
track=publish_config['google_play_track'],
expected_package_names=publish_config['package_names'],
rollout_percentage=publish_config.get('rollout_percentage'), # may be None
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')),
if contact_google_play:
connection = GooglePlayConnection.open(
publish_config['service_account'],
publish_config['google_credentials_file']
)
else:
connection = MockGooglePlayConnection()

if publish_config['google_play_track'] == 'rollout':
track = RolloutTrack(publish_config['rollout_percentage'] / 100.0)
else:
track = StaticTrack(publish_config['google_play_track'])

push_apk(
apks=apk_files,
connection=connection,
track=track,
expected_package_names=publish_config['package_names'],
commit=should_commit_transaction(payload),
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')),
)


def should_commit_transaction(task_payload):
Expand Down
46 changes: 15 additions & 31 deletions pushapkscript/test/integration/test_integration_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import tempfile
import unittest

from mozapkpublisher.common.googleplay import StaticTrack, RolloutTrack

from pushapkscript.script import main
from pushapkscript.test.helpers.mock_file import mock_open, MockFile
from pushapkscript.test.helpers.task_generator import TaskGenerator
Expand Down Expand Up @@ -152,7 +154,7 @@ def generate_fenix_config(self):


@unittest.mock.patch('pushapkscript.script.open', new=mock_open)
@unittest.mock.patch('pushapkscript.googleplay.open', new=mock_open)
@unittest.mock.patch('pushapkscript.googleplay.GooglePlayConnection.open', new=lambda account, creds: (account, creds))
class MainTest(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -208,13 +210,10 @@ def test_main_fennec_style(self, push_apk):
MockFile(
'{}/work/cot/{}/public/build/target.apk'.format(self.test_temp_dir, task_generator.x86_task_id)),
],
service_account='[email protected]',
google_play_credentials_file=MockFile('/firefox-nightly.p12'),
track='beta',
connection=('[email protected]', '/firefox-nightly.p12'),
track=StaticTrack('beta'),
expected_package_names=['org.mozilla.fennec_aurora'],
rollout_percentage=None,
commit=False,
contact_google_play=True,
skip_check_multiple_locales=False,
skip_check_ordered_version_codes=False,
skip_check_same_locales=False,
Expand All @@ -237,13 +236,10 @@ def test_main_focus_style(self, push_apk):
MockFile(
'{}/work/cot/{}/public/build/target.apk'.format(self.test_temp_dir, task_generator.x86_task_id)),
],
service_account='[email protected]',
google_play_credentials_file=MockFile('/focus.p12'),
track='production',
connection=('[email protected]', '/focus.p12'),
track=StaticTrack('production'),
expected_package_names=['org.mozilla.focus', 'org.mozilla.klar'],
rollout_percentage=None,
commit=False,
contact_google_play=True,
skip_check_multiple_locales=False,
skip_check_ordered_version_codes=True,
skip_check_same_locales=False,
Expand All @@ -266,13 +262,10 @@ def test_main_fenix_style(self, push_apk):
MockFile(
'{}/work/cot/{}/public/build/target.apk'.format(self.test_temp_dir, task_generator.x86_task_id)),
],
service_account='[email protected]',
google_play_credentials_file=MockFile('/fenix-nightly.p12'),
track='beta',
connection=('[email protected]', '/fenix-nightly.p12'),
track=StaticTrack('beta'),
expected_package_names=['org.mozilla.fenix.nightly'],
rollout_percentage=None,
commit=False,
contact_google_play=True,
skip_check_multiple_locales=True,
skip_check_ordered_version_codes=False,
skip_check_same_locales=True,
Expand All @@ -295,13 +288,10 @@ def test_main_downloads_verifies_signature_and_gives_the_right_config_to_mozapkp
MockFile(
'{}/work/cot/{}/public/build/target.apk'.format(self.test_temp_dir, task_generator.x86_task_id)),
],
service_account='[email protected]',
google_play_credentials_file=MockFile('/firefox-nightly.p12'),
track='beta',
connection=('[email protected]', '/firefox-nightly.p12'),
track=StaticTrack('beta'),
expected_package_names=['org.mozilla.fennec_aurora'],
rollout_percentage=None,
commit=False,
contact_google_play=True,
skip_check_multiple_locales=False,
skip_check_ordered_version_codes=False,
skip_check_same_locales=False,
Expand All @@ -324,13 +314,10 @@ def test_main_allows_rollout_percentage(self, push_apk):
MockFile(
'{}/work/cot/{}/public/build/target.apk'.format(self.test_temp_dir, task_generator.x86_task_id)),
],
service_account='[email protected]',
google_play_credentials_file=MockFile('/firefox-nightly.p12'),
track='rollout',
connection=('[email protected]', '/firefox-nightly.p12'),
track=RolloutTrack(0.25),
expected_package_names=['org.mozilla.fennec_aurora'],
rollout_percentage=25,
commit=False,
contact_google_play=True,
skip_check_multiple_locales=False,
skip_check_ordered_version_codes=False,
skip_check_same_locales=False,
Expand All @@ -354,13 +341,10 @@ def test_main_allows_commit_transaction(self, push_apk):
MockFile(
'{}/work/cot/{}/public/build/target.apk'.format(self.test_temp_dir, task_generator.x86_task_id)),
],
service_account='[email protected]',
google_play_credentials_file=MockFile('/firefox-nightly.p12'),
track='beta',
connection=('[email protected]', '/firefox-nightly.p12'),
track=StaticTrack('beta'),
expected_package_names=['org.mozilla.fennec_aurora'],
rollout_percentage=None,
commit=True,
contact_google_play=True,
skip_check_multiple_locales=False,
skip_check_ordered_version_codes=False,
skip_check_same_locales=False,
Expand Down
41 changes: 22 additions & 19 deletions pushapkscript/test/test_googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from unittest.mock import patch

from mozapkpublisher.common.googleplay import MockGooglePlayConnection, RolloutTrack, StaticTrack

from pushapkscript.googleplay import publish_to_googleplay, should_commit_transaction
from pushapkscript.test.helpers.mock_file import mock_open, MockFile
from pushapkscript.test.helpers.mock_file import MockFile


# TODO: refactor to pytest instead of unittest
@patch('pushapkscript.googleplay.open', new=mock_open)
@patch('pushapkscript.googleplay.GooglePlayConnection.open')
@patch('pushapkscript.googleplay.push_apk')
class GooglePlayTest(unittest.TestCase):
def setUp(self):
Expand All @@ -19,25 +21,23 @@ def setUp(self):
}
self.apks = [MockFile('/path/to/x86.apk'), MockFile('/path/to/arm_v15.apk')]

def test_publish_config(self, mock_push_apk):
def test_publish_config(self, mock_push_apk, mock_open):
mock_open.return_value = 'GooglePlayConnection'
publish_to_googleplay({}, {}, self.publish_config, self.apks, contact_google_play=True)

mock_push_apk.assert_called_with(
apks=[MockFile('/path/to/x86.apk'), MockFile('/path/to/arm_v15.apk')],
service_account='service_account',
google_play_credentials_file=MockFile('/google_credentials.p12'),
track='beta',
connection='GooglePlayConnection',
track=StaticTrack('beta'),
expected_package_names=['org.mozilla.fennec_aurora'],
rollout_percentage=None,
commit=False,
contact_google_play=True,
skip_check_multiple_locales=False,
skip_check_ordered_version_codes=False,
skip_check_same_locales=False,
skip_checks_fennec=False,
)

def test_publish_allows_rollout_percentage(self, mock_push_apk):
def test_publish_allows_rollout_percentage(self, mock_push_apk, _):
publish_config = {
'google_play_track': 'rollout',
'rollout_percentage': 10,
Expand All @@ -47,35 +47,38 @@ def test_publish_allows_rollout_percentage(self, mock_push_apk):
}
publish_to_googleplay({}, {}, publish_config, self.apks, contact_google_play=True)
_, args = mock_push_apk.call_args
assert args['track'] == 'rollout'
assert args['rollout_percentage'] == 10
assert args['track'] == RolloutTrack(0.10)

def test_craft_push_config_allows_to_contact_google_play_or_not(self, mock_push_apk):
def test_craft_push_config_allows_to_contact_google_play(self, mock_push_apk, mock_open):
mock_open.return_value = 'GooglePlayConnection'
publish_to_googleplay({}, {}, self.publish_config, self.apks, contact_google_play=True)
_, args = mock_push_apk.call_args
assert args['contact_google_play'] is True
mock_open.assert_called_once()
assert args['connection'] == 'GooglePlayConnection'

publish_to_googleplay({}, {}, self.publish_config, self.apks, False)
def test_craft_push_config_allows_to_not_contact_google_play(self, mock_push_apk, mock_open):
publish_to_googleplay({}, {}, self.publish_config, self.apks, contact_google_play=False)
_, args = mock_push_apk.call_args
assert args['contact_google_play'] is False
mock_open.assert_not_called()
assert isinstance(args['connection'], MockGooglePlayConnection)

def test_craft_push_config_skip_checking_multiple_locales(self, mock_push_apk):
def test_craft_push_config_skip_checking_multiple_locales(self, mock_push_apk, _):
product_config = {
'skip_check_multiple_locales': True,
}
publish_to_googleplay({}, product_config, self.publish_config, self.apks, contact_google_play=True)
_, args = mock_push_apk.call_args
assert args['skip_check_multiple_locales'] is True

def test_craft_push_config_skip_checking_same_locales(self, mock_push_apk):
def test_craft_push_config_skip_checking_same_locales(self, mock_push_apk, _):
product_config = {
'skip_check_same_locales': True,
}
publish_to_googleplay({}, product_config, self.publish_config, self.apks, contact_google_play=True)
_, args = mock_push_apk.call_args
assert args['skip_check_same_locales'] is True

def test_craft_push_config_expect_package_names(self, mock_push_apk):
def test_craft_push_config_expect_package_names(self, mock_push_apk, _):
publish_config = {
'google_play_track': 'beta',
'package_names': ['org.mozilla.focus', 'org.mozilla.klar'],
Expand All @@ -86,7 +89,7 @@ def test_craft_push_config_expect_package_names(self, mock_push_apk):
_, args = mock_push_apk.call_args
assert args['expected_package_names'] == ['org.mozilla.focus', 'org.mozilla.klar']

def test_craft_push_config_allows_committing_apks(self, mock_push_apk):
def test_craft_push_config_allows_committing_apks(self, mock_push_apk, _):
task_payload = {
'commit': True
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.2.0