From d526b08ea9eb5c5f4c1a2548521a23c346fa93fc Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 18 May 2020 23:59:15 +0000 Subject: [PATCH] stripe tests: Add back out-of-realm users. This fixes a minor regression in a very recent commit. In 7ad5bea3e6b0f130805927226f25e67750410c10 I was a little too aggressive about deactivating users. We do want a few users who are outside the realm, just to prevent regressions where we fail to filter on realm. The likelihood of such regressions are fairly low, but it would certainly be an ugly bug. --- corporate/tests/test_stripe.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 74fab3c992..bcec656731 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -241,8 +241,8 @@ class StripeTestCase(ZulipTestCase): self.example_email('default_bot'), # bot ] - # Deactivate all users that aren't in our whitelist. - UserProfile.objects.exclude(email__in=active_emails).update(is_active=False) + # Deactivate all users in our realm that aren't in our whitelist. + UserProfile.objects.filter(realm_id=realm.id).exclude(email__in=active_emails).update(is_active=False) # sanity check our 8 expected users are active self.assertEqual( @@ -250,6 +250,13 @@ class StripeTestCase(ZulipTestCase): 8 ) + # Make sure we have active users outside our realm (to make + # sure relevant queries restrict on realm). + self.assertEqual( + UserProfile.objects.exclude(realm=realm).filter(is_active=True).count(), + 10 + ) + # Our seat count excludes our guest user and bot, and # we want this to be predictable for certain tests with # arithmetic calculations.