Skip to content

Commit

Permalink
Bug 1562465 - Support new GP error when an APK is uploaded (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLorenzo authored Jul 3, 2019
1 parent 6381014 commit dfd757f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
7 changes: 6 additions & 1 deletion mozapkpublisher/common/googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ def upload_apk(self, apk_path):
# XXX This is really how data is returned by the googleapiclient.
error_content = json.loads(e.content)
errors = error_content['error']['errors']
if len(errors) == 1 and errors[0]['reason'] == 'apkUpgradeVersionConflict':
if (
len(errors) == 1 and
errors[0]['reason'] in (
'apkUpgradeVersionConflict', 'apkNotificationMessageKeyUpgradeVersionConflict'
)
):
logger.warning(
'APK "{}" has already been uploaded on Google Play. Skipping...'.format(apk_path)
)
Expand Down
6 changes: 6 additions & 0 deletions mozapkpublisher/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from contextlib import contextmanager


@contextmanager
def does_not_raise():
yield
28 changes: 23 additions & 5 deletions mozapkpublisher/test/common/test_googleplay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import json
import pytest
import random
import tempfile
Expand All @@ -8,6 +9,7 @@

from mozapkpublisher.common.exceptions import NoTransactionError, WrongArgumentGiven
from mozapkpublisher.common.googleplay import add_general_google_play_arguments, EditService
from mozapkpublisher.test import does_not_raise


def test_add_general_google_play_arguments():
Expand Down Expand Up @@ -122,17 +124,33 @@ def test_upload_apk_errors_out(monkeypatch, http_status_code):
edit_service.upload_apk(apk_path='/path/to/dummy.apk')


def test_upload_apk_does_not_error_out_when_apk_is_already_published(monkeypatch):
@pytest.mark.parametrize('reason, expectation', (
('apkUpgradeVersionConflict', does_not_raise()),
('apkNotificationMessageKeyUpgradeVersionConflict', does_not_raise()),
('someRandomReason', pytest.raises(HttpError)),
))
def test_upload_apk_does_not_error_out_when_apk_is_already_published(monkeypatch, reason, expectation):
edit_mock = set_up_edit_service_mock(monkeypatch)
content = {
'error': {
'errors': [{
'reason': reason
}],
},
}
# XXX content must be bytes
# https://github.com/googleapis/google-api-python-client/blob/ffea1a7fe9d381d23ab59048263c631cc2b45323/googleapiclient/errors.py#L41
content_bytes = json.dumps(content).encode('ascii')

edit_mock.apks().upload().execute.side_effect = HttpError(
# XXX status is presented as a string by googleapiclient
resp={'status': '403'},
# XXX content must be bytes
# https://github.com/googleapis/google-api-python-client/blob/ffea1a7fe9d381d23ab59048263c631cc2b45323/googleapiclient/errors.py#L41
content=b'{"error": {"errors": [{"reason": "apkUpgradeVersionConflict"}] } }',
content=content_bytes,
)
edit_service = EditService('service_account', 'credentials_file_path', 'dummy_package_name')
edit_service.upload_apk(apk_path='/path/to/dummy.apk')

with expectation:
edit_service.upload_apk(apk_path='/path/to/dummy.apk')


def test_update_track(monkeypatch):
Expand Down

0 comments on commit dfd757f

Please sign in to comment.