From c50b64512f2e93e8f0bcd89827a9f79f32f3e932 Mon Sep 17 00:00:00 2001 From: Mitchell Hentges Date: Mon, 15 Jul 2019 16:08:34 -0700 Subject: [PATCH 1/2] Uses new mozapkpublisher API with types --- pushapkscript/googleplay.py | 39 ++++++++++------ .../integration/test_integration_script.py | 46 ++++++------------- pushapkscript/test/test_googleplay.py | 41 +++++++++-------- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/pushapkscript/googleplay.py b/pushapkscript/googleplay.py index f3aa9b5..2a400c3 100644 --- a/pushapkscript/googleplay.py +++ b/pushapkscript/googleplay.py @@ -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__) @@ -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): diff --git a/pushapkscript/test/integration/test_integration_script.py b/pushapkscript/test/integration/test_integration_script.py index c6381a3..2786e5c 100644 --- a/pushapkscript/test/integration/test_integration_script.py +++ b/pushapkscript/test/integration/test_integration_script.py @@ -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 @@ -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): @@ -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='firefox-aurora@iam.gserviceaccount.com', - google_play_credentials_file=MockFile('/firefox-nightly.p12'), - track='beta', + connection=('firefox-aurora@iam.gserviceaccount.com', '/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, @@ -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='focus@iam.gserviceaccount.com', - google_play_credentials_file=MockFile('/focus.p12'), - track='production', + connection=('focus@iam.gserviceaccount.com', '/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, @@ -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='fenix-nightly@iam.gserviceaccount.com', - google_play_credentials_file=MockFile('/fenix-nightly.p12'), - track='beta', + connection=('fenix-nightly@iam.gserviceaccount.com', '/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, @@ -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='firefox-aurora@iam.gserviceaccount.com', - google_play_credentials_file=MockFile('/firefox-nightly.p12'), - track='beta', + connection=('firefox-aurora@iam.gserviceaccount.com', '/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, @@ -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='firefox-aurora@iam.gserviceaccount.com', - google_play_credentials_file=MockFile('/firefox-nightly.p12'), - track='rollout', + connection=('firefox-aurora@iam.gserviceaccount.com', '/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, @@ -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='firefox-aurora@iam.gserviceaccount.com', - google_play_credentials_file=MockFile('/firefox-nightly.p12'), - track='beta', + connection=('firefox-aurora@iam.gserviceaccount.com', '/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, diff --git a/pushapkscript/test/test_googleplay.py b/pushapkscript/test/test_googleplay.py index f1c5eef..1a915dc 100644 --- a/pushapkscript/test/test_googleplay.py +++ b/pushapkscript/test/test_googleplay.py @@ -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): @@ -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, @@ -47,19 +47,22 @@ 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, } @@ -67,7 +70,7 @@ def test_craft_push_config_skip_checking_multiple_locales(self, mock_push_apk): _, 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, } @@ -75,7 +78,7 @@ def test_craft_push_config_skip_checking_same_locales(self, mock_push_apk): _, 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'], @@ -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 } From d8bf08037bbd47243f7677c0df6408e3fd07b347 Mon Sep 17 00:00:00 2001 From: Mitchell Hentges Date: Mon, 15 Jul 2019 16:16:59 -0700 Subject: [PATCH 2/2] 3.2.0 --- CHANGELOG.md | 5 +++++ version.txt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bfb7ae..97923b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/version.txt b/version.txt index fd2a018..944880f 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.1.0 +3.2.0