Skip to content

Commit

Permalink
Merge branch 'rvinnakota/create-metric-store-mutation' of https://git…
Browse files Browse the repository at this point in the history
…hub.com/codecov/codecov-api into rvinnakota/create-metric-store-mutation
  • Loading branch information
rohitvinnakota-codecov committed Jun 19, 2024
2 parents 9fbd605 + 834785b commit 8e41e12
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 253 deletions.
12 changes: 11 additions & 1 deletion api/internal/owner/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,18 @@ def update_billing_address(self, request, *args, **kwargs):
if not billing_address:
raise ValidationError(detail="No billing_address sent")
owner = self.get_object()

formatted_address = {
"line1": billing_address["line_1"],
"line2": billing_address["line_2"],
"city": billing_address["city"],
"state": billing_address["state"],
"postal_code": billing_address["postal_code"],
"country": billing_address["country"],
}

billing = BillingService(requesting_user=request.current_owner)
billing.update_billing_address(owner, billing_address)
billing.update_billing_address(owner, billing_address=formatted_address)
return Response(self.get_serializer(owner).data)


Expand Down
46 changes: 44 additions & 2 deletions api/internal/tests/views/test_account_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,20 @@ def test_update_billing_address_handles_stripe_error(self, stripe_mock):
assert response.data["detail"] == message

@patch("services.billing.stripe.Subscription.retrieve")
@patch("services.billing.stripe.Customer.retrieve")
@patch("services.billing.stripe.PaymentMethod.modify")
@patch("services.billing.stripe.Customer.modify")
def test_update_billing_address(self, modify_customer_mock, retrieve_mock):
def test_update_billing_address(
self,
modify_customer_mock,
modify_payment_mock,
retrieve_customer_mock,
retrieve_sub_mock,
):
self.current_owner.stripe_customer_id = "flsoe"
self.current_owner.stripe_subscription_id = "djfos"
self.current_owner.save()
f = open("./services/tests/samples/stripe_invoice.json")

billing_address = {
"line_1": "45 Fremont St.",
Expand All @@ -1119,6 +1128,37 @@ def test_update_billing_address(self, modify_customer_mock, retrieve_mock):
"country": "US",
"postal_code": "94105",
}

formatted_address = {
"line1": "45 Fremont St.",
"line2": "",
"city": "San Francisco",
"state": "CA",
"country": "US",
"postal_code": "94105",
}

default_payment_method = {
"id": "pm_123",
"card": {
"brand": "visa",
"exp_month": 12,
"exp_year": 2024,
"last4": "abcd",
},
}

subscription_params = {
"default_payment_method": default_payment_method,
"cancel_at_period_end": False,
"current_period_end": 1633512445,
"latest_invoice": json.load(f)["data"][0],
"schedule_id": None,
"collection_method": "charge_automatically",
}

retrieve_sub_mock.return_value = MockSubscription(subscription_params)

kwargs = {
"service": self.current_owner.service,
"owner_username": self.current_owner.username,
Expand All @@ -1128,8 +1168,10 @@ def test_update_billing_address(self, modify_customer_mock, retrieve_mock):
response = self.client.patch(url, data=data, format="json")
assert response.status_code == status.HTTP_200_OK

retrieve_customer_mock.assert_called_once()
modify_payment_mock.assert_called_once()
modify_customer_mock.assert_called_once_with(
self.current_owner.stripe_customer_id, address=billing_address
self.current_owner.stripe_customer_id, address=formatted_address
)

@patch("api.shared.permissions.get_provider")
Expand Down
77 changes: 13 additions & 64 deletions graphql_api/tests/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def test_fetch_commit_compare_no_parent(self):
query_commit
% """
compareWithParent { __typename ... on Comparison { state } }
bundleAnalysisCompareWithParent { __typename ... on BundleAnalysisComparison { sizeDelta } }
bundleAnalysisCompareWithParent { __typename ... on BundleAnalysisComparison { bundleData { size { uncompress } } } }
"""
)
variables = {
Expand Down Expand Up @@ -818,17 +818,9 @@ def test_bundle_analysis_compare(self, get_storage_service):
bundleAnalysisCompareWithParent {
__typename
... on BundleAnalysisComparison {
sizeDelta
sizeTotal
loadTimeDelta
loadTimeTotal
bundles {
name
changeType
sizeDelta
sizeTotal
loadTimeDelta
loadTimeTotal
bundleData {
size {
uncompress
Expand Down Expand Up @@ -864,58 +856,34 @@ def test_bundle_analysis_compare(self, get_storage_service):
commit = data["owner"]["repository"]["commit"]
assert commit["bundleAnalysisCompareWithParent"] == {
"__typename": "BundleAnalysisComparison",
"sizeDelta": 36555,
"sizeTotal": 201720,
"loadTimeDelta": 0.1,
"loadTimeTotal": 0.5,
"bundles": [
{
"name": "b1",
"changeType": "changed",
"sizeDelta": 5,
"sizeTotal": 20,
"loadTimeDelta": 0.0,
"loadTimeTotal": 0.0,
"bundleData": {"size": {"uncompress": 20}},
"bundleChange": {"size": {"uncompress": 5}},
},
{
"name": "b2",
"changeType": "changed",
"sizeDelta": 50,
"sizeTotal": 200,
"loadTimeDelta": 0.0,
"loadTimeTotal": 0.0,
"bundleData": {"size": {"uncompress": 200}},
"bundleChange": {"size": {"uncompress": 50}},
},
{
"name": "b3",
"changeType": "added",
"sizeDelta": 1500,
"sizeTotal": 1500,
"loadTimeDelta": 0.0,
"loadTimeTotal": 0.0,
"bundleData": {"size": {"uncompress": 1500}},
"bundleChange": {"size": {"uncompress": 1500}},
},
{
"name": "b5",
"changeType": "changed",
"sizeDelta": 50000,
"sizeTotal": 200000,
"loadTimeDelta": 0.1,
"loadTimeTotal": 0.5,
"bundleData": {"size": {"uncompress": 200000}},
"bundleChange": {"size": {"uncompress": 50000}},
},
{
"name": "b4",
"changeType": "removed",
"sizeDelta": -15000,
"sizeTotal": 0,
"loadTimeDelta": -0.0,
"loadTimeTotal": 0.0,
"bundleData": {"size": {"uncompress": 0}},
"bundleChange": {"size": {"uncompress": -15000}},
},
Expand Down Expand Up @@ -958,7 +926,11 @@ def test_bundle_analysis_sqlite_file_deleted(self, get_storage_service):
bundleAnalysisCompareWithParent {
__typename
... on BundleAnalysisComparison {
sizeTotal
bundleData {
size {
uncompress
}
}
}
}
"""
Expand Down Expand Up @@ -1013,7 +985,11 @@ def test_bundle_analysis_sqlite_file_not_deleted(
bundleAnalysisCompareWithParent {
__typename
... on BundleAnalysisComparison {
sizeTotal
bundleData {
size {
uncompress
}
}
}
}
"""
Expand Down Expand Up @@ -1076,21 +1052,17 @@ def test_bundle_analysis_report(self, get_storage_service):
storage.write_file(get_bucket_name(), storage_path, f)

query = """
query FetchCommit($org: String!, $repo: String!, $commit: String!, $filters: BundleAnalysisReportFilters) {
query FetchCommit($org: String!, $repo: String!, $commit: String!) {
owner(username: $org) {
repository(name: $repo) {
... on Repository {
commit(id: $commit) {
bundleAnalysisReport {
__typename
... on BundleAnalysisReport {
sizeTotal
loadTimeTotal
bundles {
name
sizeTotal
loadTimeTotal
assets(filters: $filters) {
assets {
normalizedName
}
asset(name: "not_exist") {
Expand Down Expand Up @@ -1136,20 +1108,15 @@ def test_bundle_analysis_report(self, get_storage_service):
"org": self.org.username,
"repo": self.repo.name,
"commit": self.commit.commitid,
"filters": {"moduleExtensions": []},
}
data = self.gql_request(query, variables=variables)
commit = data["owner"]["repository"]["commit"]

assert commit["bundleAnalysisReport"] == {
"__typename": "BundleAnalysisReport",
"sizeTotal": 201720,
"loadTimeTotal": 0.5,
"bundles": [
{
"name": "b1",
"sizeTotal": 20,
"loadTimeTotal": 0.0,
"assets": [
{"normalizedName": "assets/react-*.svg"},
{"normalizedName": "assets/index-*.css"},
Expand All @@ -1171,8 +1138,6 @@ def test_bundle_analysis_report(self, get_storage_service):
},
{
"name": "b2",
"sizeTotal": 200,
"loadTimeTotal": 0.0,
"assets": [
{"normalizedName": "assets/react-*.svg"},
{"normalizedName": "assets/index-*.css"},
Expand All @@ -1194,8 +1159,6 @@ def test_bundle_analysis_report(self, get_storage_service):
},
{
"name": "b3",
"sizeTotal": 1500,
"loadTimeTotal": 0.0,
"assets": [
{"normalizedName": "assets/react-*.svg"},
{"normalizedName": "assets/index-*.css"},
Expand All @@ -1217,8 +1180,6 @@ def test_bundle_analysis_report(self, get_storage_service):
},
{
"name": "b5",
"sizeTotal": 200000,
"loadTimeTotal": 0.5,
"assets": [
{"normalizedName": "assets/react-*.svg"},
{"normalizedName": "assets/index-*.css"},
Expand Down Expand Up @@ -1280,13 +1241,11 @@ def test_bundle_analysis_asset(self, get_storage_service):
__typename
... on BundleAnalysisReport {
bundle(name: "b5") {
moduleExtensions
moduleCount
asset(name: "assets/LazyComponent-fcbb0922.js") {
name
normalizedName
extension
moduleExtensions
bundleData {
loadTime {
threeG
Expand Down Expand Up @@ -1333,22 +1292,12 @@ def test_bundle_analysis_asset(self, get_storage_service):
asset_report = bundle_report["asset"]

assert bundle_report is not None
assert sorted(bundle_report["moduleExtensions"]) == [
"",
"css",
"html",
"js",
"svg",
"ts",
"tsx",
]
assert bundle_report["moduleCount"] == 7

assert asset_report is not None
assert asset_report["name"] == "assets/LazyComponent-fcbb0922.js"
assert asset_report["normalizedName"] == "assets/LazyComponent-*.js"
assert asset_report["extension"] == "js"
assert set(asset_report["moduleExtensions"]) == set(["", "tsx"])
assert asset_report["bundleData"] == {
"loadTime": {
"threeG": 320,
Expand Down
24 changes: 20 additions & 4 deletions graphql_api/tests/test_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@
bundleAnalysisCompareWithBase {
__typename
... on BundleAnalysisComparison {
sizeDelta
bundleData {
size {
uncompress
}
}
}
}
behindBy
Expand All @@ -105,7 +109,11 @@
bundleAnalysisCompareWithBase {
__typename
... on BundleAnalysisComparison {
sizeDelta
bundleData {
size {
uncompress
}
}
}
}
"""
Expand Down Expand Up @@ -453,7 +461,11 @@ def test_bundle_analysis_sqlite_file_deleted(self, get_storage_service):
bundleAnalysisCompareWithBase {
__typename
... on BundleAnalysisComparison {
sizeTotal
bundleData {
size {
uncompress
}
}
}
}
"""
Expand All @@ -463,7 +475,11 @@ def test_bundle_analysis_sqlite_file_deleted(self, get_storage_service):
assert pull == {
"bundleAnalysisCompareWithBase": {
"__typename": "BundleAnalysisComparison",
"sizeTotal": 201720,
"bundleData": {
"size": {
"uncompress": 201720,
}
},
}
}

Expand Down
Loading

0 comments on commit 8e41e12

Please sign in to comment.