Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Ignore empty relationships on App Store Connect resources #401

Merged
merged 4 commits into from
Apr 24, 2024
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
UNRELEASED
-------------

**Bugfixes**
- Fix App Store Connect API responses deserialization for cases when resource contains an empty relationship. [PR #401](https://github.com/codemagic-ci-cd/cli-tools/pull/401)

Version 0.50.7
-------------

Expand Down
11 changes: 8 additions & 3 deletions src/codemagic/apple/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ class Attributes(DictSerializable, GracefulDataclassMixin):
class Relationships(DictSerializable, GracefulDataclassMixin):
def __post_init__(self):
for field in self.__dict__:
value = getattr(self, field)
if not isinstance(value, (Relationship, type(None))):
setattr(self, field, Relationship(**value))
current_value = getattr(self, field)
if current_value is None or isinstance(current_value, Relationship):
continue

# Relationships should have at least 'links' attribute.
# Set the value to none for empty relationships.
updated_value = Relationship(**current_value) if current_value else None
setattr(self, field, updated_value)

@classmethod
def _create_attributes(cls, api_response) -> Attributes:
Expand Down
6 changes: 6 additions & 0 deletions tests/apple/resources/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def api_app_store_version() -> Dict:
return json.loads(mock_path.read_text())


@pytest.fixture
def api_app() -> Dict:
mock_path = pathlib.Path(__file__).parent / "mocks" / "app.json"
return json.loads(mock_path.read_text())


@pytest.fixture
def api_build() -> Dict:
mock_path = pathlib.Path(__file__).parent / "mocks" / "build.json"
Expand Down
223 changes: 223 additions & 0 deletions tests/apple/resources/mocks/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
{
"attributes": {
"bundleId": "io.codemagic.banaan",
"contentRightsDeclaration": "DOES_NOT_USE_THIRD_PARTY_CONTENT",
"isOrEverWasMadeForKids": false,
"name": "Banaan Codemagic",
"primaryLocale": "en-GB",
"sku": "banaanike",
"subscriptionStatusUrl": null,
"subscriptionStatusUrlForSandbox": null,
"subscriptionStatusUrlVersion": null,
"subscriptionStatusUrlVersionForSandbox": null
},
"id": "1481211155",
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155"
},
"relationships": {
"alternativeDistributionKey": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/alternativeDistributionKey",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/alternativeDistributionKey"
}
},
"analyticsReportRequests": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/analyticsReportRequests",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/analyticsReportRequests"
}
},
"appAvailability": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appAvailability",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appAvailability"
}
},
"appAvailabilityV2": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appAvailabilityV2",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appAvailabilityV2"
}
},
"appClips": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appClips",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appClips"
}
},
"appCustomProductPages": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appCustomProductPages",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appCustomProductPages"
}
},
"appEvents": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appEvents",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appEvents"
}
},
"appInfos": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appInfos",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appInfos"
}
},
"appPricePoints": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appPricePoints",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appPricePoints"
}
},
"appPriceSchedule": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appPriceSchedule",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appPriceSchedule"
}
},
"appStoreVersionExperimentsV2": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appStoreVersionExperimentsV2",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appStoreVersionExperimentsV2"
}
},
"appStoreVersions": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/appStoreVersions",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/appStoreVersions"
}
},
"betaAppLocalizations": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/betaAppLocalizations",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/betaAppLocalizations"
}
},
"betaAppReviewDetail": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/betaAppReviewDetail",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/betaAppReviewDetail"
}
},
"betaGroups": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/betaGroups",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/betaGroups"
}
},
"betaLicenseAgreement": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/betaLicenseAgreement",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/betaLicenseAgreement"
}
},
"betaTesters": {
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/betaTesters"
}
},
"builds": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/builds",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/builds"
}
},
"ciProduct": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/ciProduct",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/ciProduct"
}
},
"customerReviews": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/customerReviews",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/customerReviews"
}
},
"endUserLicenseAgreement": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/endUserLicenseAgreement",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/endUserLicenseAgreement"
}
},
"gameCenterDetail": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/gameCenterDetail",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/gameCenterDetail"
}
},
"gameCenterEnabledVersions": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/gameCenterEnabledVersions",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/gameCenterEnabledVersions"
}
},
"inAppPurchases": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/inAppPurchases",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/inAppPurchases"
}
},
"inAppPurchasesV2": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/inAppPurchasesV2",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/inAppPurchasesV2"
}
},
"marketplaceSearchDetail": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/marketplaceSearchDetail",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/marketplaceSearchDetail"
}
},
"perfPowerMetrics": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/perfPowerMetrics"
}
},
"preOrder": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/preOrder",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/preOrder"
}
},
"preReleaseVersions": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/preReleaseVersions",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/preReleaseVersions"
}
},
"pricePoints": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/pricePoints",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/pricePoints"
}
},
"promotedPurchases": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/promotedPurchases",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/promotedPurchases"
}
},
"reviewSubmissions": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/reviewSubmissions",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/reviewSubmissions"
}
},
"subscriptionGracePeriod": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/subscriptionGracePeriod",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/subscriptionGracePeriod"
}
},
"subscriptionGroups": {
"links": {
"related": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/subscriptionGroups",
"self": "https://api.appstoreconnect.apple.com/v1/apps/1481211155/relationships/subscriptionGroups"
}
}
},
"type": "apps"
}
10 changes: 10 additions & 0 deletions tests/apple/resources/test_app_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

from codemagic.apple.resources import App


def test_app_with_empty_relationship(api_app):
api_app["relationships"]["ciProduct"] = {}
app = App(api_app)
assert app.relationships.ciProduct is None
assert "ciProduct" not in app.dict()["relationships"]
Loading