Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Fix missed mypy errors in tests.

PIG208de2678a31979
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index ea114e864b6..d99cbe0e12f 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -1248,6 +1248,7 @@ class StripeTest(StripeTestCase):
)
# Check that we created a Customer object but no CustomerPlan
stripe_customer_id = Customer.objects.get(realm=get_realm("zulip")).stripe_customer_id
+ assert stripe_customer_id is not None
self.assertFalse(CustomerPlan.objects.exists())
# Check that we created a Customer in stripe, a failed Charge, and no Invoices or Invoice Items
self.assertTrue(stripe_get_customer(stripe_customer_id))
@@ -1689,7 +1690,9 @@ class StripeTest(StripeTestCase):
assert customer is not None
[charge] = stripe.Charge.list(customer=customer.stripe_customer_id)
self.assertEqual(1200 * self.seat_count, charge.amount)
- [invoice] = stripe.Invoice.list(customer=customer.stripe_customer_id)
+ stripe_customer_id = customer.stripe_customer_id
+ assert stripe_customer_id is not None
+ [invoice] = stripe.Invoice.list(customer=stripe_customer_id)
self.assertEqual(
[1200 * self.seat_count, -1200 * self.seat_count],
[item.amount for item in invoice.lines],
@@ -1707,7 +1710,9 @@ class StripeTest(StripeTestCase):
)
[charge, _] = stripe.Charge.list(customer=customer.stripe_customer_id)
self.assertEqual(6000 * self.seat_count, charge.amount)
- [invoice, _] = stripe.Invoice.list(customer=customer.stripe_customer_id)
+ stripe_customer_id = customer.stripe_customer_id
+ assert stripe_customer_id is not None
+ [invoice, _] = stripe.Invoice.list(customer=stripe_customer_id)
self.assertEqual(
[6000 * self.seat_count, -6000 * self.seat_count],
[item.amount for item in invoice.lines],
@@ -1721,7 +1726,9 @@ class StripeTest(StripeTestCase):
customer.refresh_from_db()
self.assertEqual(customer.default_discount, 50)
invoice_plans_as_needed(self.next_year + timedelta(days=10))
- [invoice, _, _] = stripe.Invoice.list(customer=customer.stripe_customer_id)
+ stripe_customer_id = customer.stripe_customer_id
+ assert stripe_customer_id is not None
+ [invoice, _, _] = stripe.Invoice.list(customer=stripe_customer_id)
self.assertEqual([4000 * self.seat_count], [item.amount for item in invoice.lines])
realm_audit_log = RealmAuditLog.objects.filter(
event_type=RealmAuditLog.REALM_DISCOUNT_CHANGED
@@ -1779,6 +1786,7 @@ class StripeTest(StripeTestCase):
stripe_customer = Customer.objects.first()
assert stripe_customer is not None
stripe_customer_id = stripe_customer.stripe_customer_id
+ assert stripe_customer_id is not None
stripe.InvoiceItem.create(amount=5000, currency="usd", customer=stripe_customer_id)
stripe_invoice = stripe.Invoice.create(customer=stripe_customer_id)
stripe.Invoice.finalize_invoice(stripe_invoice)
@@ -3491,8 +3499,9 @@ class InvoiceTest(StripeTestCase):
plan = CustomerPlan.objects.first()
assert plan is not None
invoice_plan(plan, self.now + timedelta(days=400))
-
- [invoice0, invoice1] = stripe.Invoice.list(customer=plan.customer.stripe_customer_id)
+ stripe_cutomer_id = plan.customer.stripe_customer_id
+ assert stripe_cutomer_id is not None
+ [invoice0, invoice1] = stripe.Invoice.list(customer=stripe_cutomer_id)
self.assertIsNotNone(invoice0.status_transitions.finalized_at)
[item0, item1, item2] = invoice0.lines
line_item_params = {
@@ -3545,8 +3554,10 @@ class InvoiceTest(StripeTestCase):
plan.price_per_license = 0
plan.save(update_fields=["fixed_price", "price_per_license"])
invoice_plan(plan, self.next_year)
- [invoice0, invoice1] = stripe.Invoice.list(customer=plan.customer.stripe_customer_id)
- self.assertEqual(invoice0.collection_method, "send_invoice")
+ stripe_customer_id = plan.customer.stripe_customer_id
+ assert stripe_customer_id is not None
+ [invoice0, invoice1] = stripe.Invoice.list(customer=stripe_customer_id)
+ self.assertEqual(invoice0.billing, "send_invoice")
[item] = invoice0.lines
line_item_params = {
"amount": 100,
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 79590308e4b..2ca5b4777bc 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -1954,8 +1954,9 @@ class NormalActionsTest(BaseAction):
event_type=RealmAuditLog.REALM_EXPORTED
).first()
assert audit_log_entry is not None
+ audit_log_entry_id = audit_log_entry.id
events = self.verify_action(
- lambda: self.client_delete(f"/json/export/realm/{audit_log_entry.id}"),
+ lambda: self.client_delete(f"/json/export/realm/{audit_log_entry_id}"),
state_change_expected=False,
num_events=1,
)
diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py
index c1072d5f40e..676f0180c91 100644
--- a/zerver/tests/test_message_fetch.py
+++ b/zerver/tests/test_message_fetch.py
@@ -74,7 +74,7 @@ def get_sqlalchemy_query_params(query: ClauseElement) -> Dict[str, object]:
return comp.params
-def get_recipient_id_for_stream_name(realm: Realm, stream_name: str) -> Optional[str]:
+def get_recipient_id_for_stream_name(realm: Realm, stream_name: str) -> Optional[int]:
stream = get_stream(stream_name, realm)
return stream.recipient.id if stream.recipient is not None else None
diff --git a/zerver/tests/test_realm_export.py b/zerver/tests/test_realm_export.py
index 79be7148c54..ca40edf8f72 100644
--- a/zerver/tests/test_realm_export.py
+++ b/zerver/tests/test_realm_export.py
@@ -65,7 +65,9 @@ class RealmExportTest(ZulipTestCase):
self.assertEqual(audit_log_entry.acting_user_id, admin.id)
# Test that the file is hosted, and the contents are as expected.
- export_path = orjson.loads(audit_log_entry.extra_data)["export_path"]
+ extra_data = audit_log_entry.extra_data
+ assert extra_data is not None
+ export_path = orjson.loads(extra_data)["export_path"]
assert export_path.startswith("/")
path_id = export_path[1:]
self.assertEqual(bucket.Object(path_id).get()["Body"].read(), b"zulip!")
@@ -96,7 +98,9 @@ class RealmExportTest(ZulipTestCase):
# Try to delete an export with a `deleted_timestamp` key.
audit_log_entry.refresh_from_db()
- export_data = orjson.loads(audit_log_entry.extra_data)
+ extra_data = audit_log_entry.extra_data
+ assert extra_data is not None
+ export_data = orjson.loads(extra_data)
self.assertIn("deleted_timestamp", export_data)
result = self.client_delete(f"/json/export/realm/{audit_log_entry.id}")
self.assert_json_error(result, "Export already deleted")
@@ -131,7 +135,9 @@ class RealmExportTest(ZulipTestCase):
self.assertEqual(audit_log_entry.acting_user_id, admin.id)
# Test that the file is hosted, and the contents are as expected.
- export_path = orjson.loads(audit_log_entry.extra_data).get("export_path")
+ extra_data = audit_log_entry.extra_data
+ assert extra_data is not None
+ export_path = orjson.loads(extra_data).get("export_path")
response = self.client_get(export_path)
self.assertEqual(response.status_code, 200)
self.assert_url_serves_contents_of_file(export_path, b"zulip!")
@@ -159,7 +165,9 @@ class RealmExportTest(ZulipTestCase):
# Try to delete an export with a `deleted_timestamp` key.
audit_log_entry.refresh_from_db()
- export_data = orjson.loads(audit_log_entry.extra_data)
+ extra_data = audit_log_entry.extra_data
+ assert extra_data is not None
+ export_data = orjson.loads(extra_data)
self.assertIn("deleted_timestamp", export_data)
result = self.client_delete(f"/json/export/realm/{audit_log_entry.id}")
self.assert_json_error(result, "Export already deleted")