mirror of https://github.com/zulip/zulip.git
billing tests: Remove unnecessary orjson.dumps of params.
This should have been in https://github.com/zulip/zulip/pull/18066. The reason, the tests were not failing inspite of the params being json encoded was because pretty much all these tests did not test the functionality of the endpoint. Rather they were testing things like whether the user has the right to access the endpoint and all. So the value of the params did not matter. The only one test which is an exception is test_replace_payment_source. Even though a json encoded token was passed to an endpoint that expecteda string, the test continued to work becausethe fixtures were not updated for the test in that PR, so instead of sending an incorrect json encoded token to stripe endpoint it was sending the correct string token. Now that we removed the json.dumps of token, we no longer have to update the fixtures. I have run the tests with --generate-stripe-fixtures set to True and all the tests are passing. Not including the fixture changes since the tests conntinue to work the same with both the existing and new fixtures.
This commit is contained in:
parent
ee0d375f81
commit
19b25b3fa3
|
@ -7,7 +7,19 @@ import sys
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, TypeVar, cast
|
from typing import (
|
||||||
|
Any,
|
||||||
|
Callable,
|
||||||
|
Dict,
|
||||||
|
List,
|
||||||
|
Mapping,
|
||||||
|
Optional,
|
||||||
|
Sequence,
|
||||||
|
Tuple,
|
||||||
|
TypeVar,
|
||||||
|
Union,
|
||||||
|
cast,
|
||||||
|
)
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import orjson
|
import orjson
|
||||||
|
@ -1754,7 +1766,7 @@ class StripeTest(StripeTestCase):
|
||||||
) as m:
|
) as m:
|
||||||
response = self.client_post(
|
response = self.client_post(
|
||||||
"/json/billing/sources/change",
|
"/json/billing/sources/change",
|
||||||
{"stripe_token": orjson.dumps(stripe_token).decode()},
|
{"stripe_token": stripe_token},
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
m.output, ["INFO:corporate.stripe:Stripe card error: 402 card_error card_declined "]
|
m.output, ["INFO:corporate.stripe:Stripe card error: 402 card_error card_declined "]
|
||||||
|
@ -1774,7 +1786,7 @@ class StripeTest(StripeTestCase):
|
||||||
with self.assertLogs("corporate.stripe", "INFO") as m:
|
with self.assertLogs("corporate.stripe", "INFO") as m:
|
||||||
response = self.client_post(
|
response = self.client_post(
|
||||||
"/json/billing/sources/change",
|
"/json/billing/sources/change",
|
||||||
{"stripe_token": orjson.dumps(stripe_token).decode()},
|
{"stripe_token": stripe_token},
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
m.output,
|
m.output,
|
||||||
|
@ -1794,9 +1806,7 @@ class StripeTest(StripeTestCase):
|
||||||
|
|
||||||
# Replace with a valid card
|
# Replace with a valid card
|
||||||
stripe_token = stripe_create_token(card_number="5555555555554444").id
|
stripe_token = stripe_create_token(card_number="5555555555554444").id
|
||||||
response = self.client_post(
|
response = self.client_post("/json/billing/sources/change", {"stripe_token": stripe_token})
|
||||||
"/json/billing/sources/change", {"stripe_token": orjson.dumps(stripe_token).decode()}
|
|
||||||
)
|
|
||||||
self.assert_json_success(response)
|
self.assert_json_success(response)
|
||||||
number_of_sources = 0
|
number_of_sources = 0
|
||||||
for stripe_source in stripe_get_customer(stripe_customer_id).sources:
|
for stripe_source in stripe_get_customer(stripe_customer_id).sources:
|
||||||
|
@ -2900,18 +2910,14 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
||||||
# Billing admins have access
|
# Billing admins have access
|
||||||
self.login_user(self.example_user("hamlet"))
|
self.login_user(self.example_user("hamlet"))
|
||||||
with patch("corporate.views.do_replace_payment_source") as mocked1:
|
with patch("corporate.views.do_replace_payment_source") as mocked1:
|
||||||
response = self.client_post(
|
response = self.client_post("/json/billing/sources/change", {"stripe_token": "token"})
|
||||||
"/json/billing/sources/change", {"stripe_token": orjson.dumps("token").decode()}
|
|
||||||
)
|
|
||||||
self.assert_json_success(response)
|
self.assert_json_success(response)
|
||||||
mocked1.assert_called_once()
|
mocked1.assert_called_once()
|
||||||
|
|
||||||
# Realm owners have access, even if they are not billing admins
|
# Realm owners have access, even if they are not billing admins
|
||||||
self.login_user(self.example_user("desdemona"))
|
self.login_user(self.example_user("desdemona"))
|
||||||
with patch("corporate.views.do_replace_payment_source") as mocked2:
|
with patch("corporate.views.do_replace_payment_source") as mocked2:
|
||||||
response = self.client_post(
|
response = self.client_post("/json/billing/sources/change", {"stripe_token": "token"})
|
||||||
"/json/billing/sources/change", {"stripe_token": orjson.dumps("token").decode()}
|
|
||||||
)
|
|
||||||
self.assert_json_success(response)
|
self.assert_json_success(response)
|
||||||
mocked2.assert_called_once()
|
mocked2.assert_called_once()
|
||||||
|
|
||||||
|
@ -2920,7 +2926,7 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
||||||
username: str,
|
username: str,
|
||||||
endpoint: str,
|
endpoint: str,
|
||||||
method: str,
|
method: str,
|
||||||
request_data: Dict[str, str],
|
request_data: Dict[str, Union[str, int]],
|
||||||
error_message: str,
|
error_message: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
|
@ -2938,10 +2944,10 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
||||||
"/json/billing/upgrade",
|
"/json/billing/upgrade",
|
||||||
"POST",
|
"POST",
|
||||||
{
|
{
|
||||||
"billing_modality": orjson.dumps("charge_automatically").decode(),
|
"billing_modality": "charge_automatically",
|
||||||
"schedule": orjson.dumps("annual").decode(),
|
"schedule": "annual",
|
||||||
"signed_seat_count": orjson.dumps("signed count").decode(),
|
"signed_seat_count": "signed count",
|
||||||
"salt": orjson.dumps("salt").decode(),
|
"salt": "salt",
|
||||||
},
|
},
|
||||||
"Must be an organization member",
|
"Must be an organization member",
|
||||||
)
|
)
|
||||||
|
@ -2951,9 +2957,9 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
||||||
"/json/billing/sponsorship",
|
"/json/billing/sponsorship",
|
||||||
"POST",
|
"POST",
|
||||||
{
|
{
|
||||||
"organization-type": orjson.dumps("event").decode(),
|
"organization-type": "event",
|
||||||
"description": orjson.dumps("event description").decode(),
|
"description": "event description",
|
||||||
"website": orjson.dumps("example.com").decode(),
|
"website": "example.com",
|
||||||
},
|
},
|
||||||
"Must be an organization member",
|
"Must be an organization member",
|
||||||
)
|
)
|
||||||
|
@ -2964,7 +2970,7 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
||||||
username,
|
username,
|
||||||
"/json/billing/sources/change",
|
"/json/billing/sources/change",
|
||||||
"POST",
|
"POST",
|
||||||
{"stripe_token": orjson.dumps("token").decode()},
|
{"stripe_token": "token"},
|
||||||
"Must be a billing administrator or an organization owner",
|
"Must be a billing administrator or an organization owner",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2972,7 +2978,7 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
||||||
username,
|
username,
|
||||||
"/json/billing/plan",
|
"/json/billing/plan",
|
||||||
"PATCH",
|
"PATCH",
|
||||||
{"status": orjson.dumps(1).decode()},
|
{"status": 1},
|
||||||
"Must be a billing administrator or an organization owner",
|
"Must be a billing administrator or an organization owner",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue