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 decimal import Decimal
|
||||
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
|
||||
|
||||
import orjson
|
||||
|
@ -1754,7 +1766,7 @@ class StripeTest(StripeTestCase):
|
|||
) as m:
|
||||
response = self.client_post(
|
||||
"/json/billing/sources/change",
|
||||
{"stripe_token": orjson.dumps(stripe_token).decode()},
|
||||
{"stripe_token": stripe_token},
|
||||
)
|
||||
self.assertEqual(
|
||||
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:
|
||||
response = self.client_post(
|
||||
"/json/billing/sources/change",
|
||||
{"stripe_token": orjson.dumps(stripe_token).decode()},
|
||||
{"stripe_token": stripe_token},
|
||||
)
|
||||
self.assertEqual(
|
||||
m.output,
|
||||
|
@ -1794,9 +1806,7 @@ class StripeTest(StripeTestCase):
|
|||
|
||||
# Replace with a valid card
|
||||
stripe_token = stripe_create_token(card_number="5555555555554444").id
|
||||
response = self.client_post(
|
||||
"/json/billing/sources/change", {"stripe_token": orjson.dumps(stripe_token).decode()}
|
||||
)
|
||||
response = self.client_post("/json/billing/sources/change", {"stripe_token": stripe_token})
|
||||
self.assert_json_success(response)
|
||||
number_of_sources = 0
|
||||
for stripe_source in stripe_get_customer(stripe_customer_id).sources:
|
||||
|
@ -2900,18 +2910,14 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
|||
# Billing admins have access
|
||||
self.login_user(self.example_user("hamlet"))
|
||||
with patch("corporate.views.do_replace_payment_source") as mocked1:
|
||||
response = self.client_post(
|
||||
"/json/billing/sources/change", {"stripe_token": orjson.dumps("token").decode()}
|
||||
)
|
||||
response = self.client_post("/json/billing/sources/change", {"stripe_token": "token"})
|
||||
self.assert_json_success(response)
|
||||
mocked1.assert_called_once()
|
||||
|
||||
# Realm owners have access, even if they are not billing admins
|
||||
self.login_user(self.example_user("desdemona"))
|
||||
with patch("corporate.views.do_replace_payment_source") as mocked2:
|
||||
response = self.client_post(
|
||||
"/json/billing/sources/change", {"stripe_token": orjson.dumps("token").decode()}
|
||||
)
|
||||
response = self.client_post("/json/billing/sources/change", {"stripe_token": "token"})
|
||||
self.assert_json_success(response)
|
||||
mocked2.assert_called_once()
|
||||
|
||||
|
@ -2920,7 +2926,7 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
|||
username: str,
|
||||
endpoint: str,
|
||||
method: str,
|
||||
request_data: Dict[str, str],
|
||||
request_data: Dict[str, Union[str, int]],
|
||||
error_message: str,
|
||||
) -> None:
|
||||
|
||||
|
@ -2938,10 +2944,10 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
|||
"/json/billing/upgrade",
|
||||
"POST",
|
||||
{
|
||||
"billing_modality": orjson.dumps("charge_automatically").decode(),
|
||||
"schedule": orjson.dumps("annual").decode(),
|
||||
"signed_seat_count": orjson.dumps("signed count").decode(),
|
||||
"salt": orjson.dumps("salt").decode(),
|
||||
"billing_modality": "charge_automatically",
|
||||
"schedule": "annual",
|
||||
"signed_seat_count": "signed count",
|
||||
"salt": "salt",
|
||||
},
|
||||
"Must be an organization member",
|
||||
)
|
||||
|
@ -2951,9 +2957,9 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
|||
"/json/billing/sponsorship",
|
||||
"POST",
|
||||
{
|
||||
"organization-type": orjson.dumps("event").decode(),
|
||||
"description": orjson.dumps("event description").decode(),
|
||||
"website": orjson.dumps("example.com").decode(),
|
||||
"organization-type": "event",
|
||||
"description": "event description",
|
||||
"website": "example.com",
|
||||
},
|
||||
"Must be an organization member",
|
||||
)
|
||||
|
@ -2964,7 +2970,7 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
|||
username,
|
||||
"/json/billing/sources/change",
|
||||
"POST",
|
||||
{"stripe_token": orjson.dumps("token").decode()},
|
||||
{"stripe_token": "token"},
|
||||
"Must be a billing administrator or an organization owner",
|
||||
)
|
||||
|
||||
|
@ -2972,7 +2978,7 @@ class RequiresBillingAccessTest(ZulipTestCase):
|
|||
username,
|
||||
"/json/billing/plan",
|
||||
"PATCH",
|
||||
{"status": orjson.dumps(1).decode()},
|
||||
{"status": 1},
|
||||
"Must be a billing administrator or an organization owner",
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue