forked from GithubBackups/healthchecks
Silence stdout output from management commands during tests
This commit is contained in:
parent
15ba415298
commit
d6be955fa7
@ -6,6 +6,7 @@ from hc.accounts.management.commands.pruneusers import Command
|
||||
from hc.accounts.models import Project
|
||||
from hc.api.models import Check
|
||||
from hc.test import BaseTestCase
|
||||
from mock import Mock
|
||||
|
||||
|
||||
class PruneUsersTestCase(BaseTestCase):
|
||||
@ -19,7 +20,7 @@ class PruneUsersTestCase(BaseTestCase):
|
||||
charlies_project = Project.objects.create(owner=self.charlie)
|
||||
Check(project=charlies_project).save()
|
||||
|
||||
Command().handle()
|
||||
Command(stdout=Mock()).handle()
|
||||
|
||||
self.assertEqual(User.objects.filter(username="charlie").count(), 0)
|
||||
self.assertEqual(Check.objects.count(), 0)
|
||||
@ -29,6 +30,7 @@ class PruneUsersTestCase(BaseTestCase):
|
||||
self.bob.last_login = self.year_ago
|
||||
self.bob.save()
|
||||
|
||||
Command().handle()
|
||||
Command(stdout=Mock()).handle()
|
||||
|
||||
# Bob belongs to a team so should not get removed
|
||||
self.assertEqual(User.objects.filter(username="bob").count(), 1)
|
||||
|
@ -24,8 +24,7 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
self.project.member_set.all().delete()
|
||||
|
||||
def test_it_sends_notice(self):
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
cmd = Command(stdout=Mock())
|
||||
cmd.pause = Mock() # don't pause for 1s
|
||||
|
||||
result = cmd.handle()
|
||||
@ -42,10 +41,7 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
self.alice.last_login = now() - td(days=15)
|
||||
self.alice.save()
|
||||
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
|
||||
result = cmd.handle()
|
||||
result = Command(stdout=Mock()).handle()
|
||||
self.assertEqual(result, "Done! Sent 0 notices")
|
||||
|
||||
self.profile.refresh_from_db()
|
||||
@ -56,10 +52,7 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
self.alice.date_joined = now() - td(days=15)
|
||||
self.alice.save()
|
||||
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
|
||||
result = cmd.handle()
|
||||
result = Command(stdout=Mock()).handle()
|
||||
self.assertEqual(result, "Done! Sent 0 notices")
|
||||
|
||||
self.profile.refresh_from_db()
|
||||
@ -70,10 +63,7 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
self.profile.deletion_notice_date = now() - td(days=15)
|
||||
self.profile.save()
|
||||
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
|
||||
result = cmd.handle()
|
||||
result = Command(stdout=Mock()).handle()
|
||||
self.assertEqual(result, "Done! Sent 0 notices")
|
||||
|
||||
def test_it_checks_sms_limit(self):
|
||||
@ -81,10 +71,7 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
self.profile.sms_limit = 50
|
||||
self.profile.save()
|
||||
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
|
||||
result = cmd.handle()
|
||||
result = Command(stdout=Mock()).handle()
|
||||
self.assertEqual(result, "Done! Sent 0 notices")
|
||||
|
||||
self.profile.refresh_from_db()
|
||||
@ -94,10 +81,7 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
# bob has access to alice's project
|
||||
Member.objects.create(user=self.bob, project=self.project)
|
||||
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
|
||||
result = cmd.handle()
|
||||
result = Command(stdout=Mock()).handle()
|
||||
self.assertEqual(result, "Done! Sent 0 notices")
|
||||
|
||||
self.profile.refresh_from_db()
|
||||
@ -107,10 +91,7 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
check = Check.objects.create(project=self.project)
|
||||
Ping.objects.create(owner=check)
|
||||
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
|
||||
result = cmd.handle()
|
||||
result = Command(stdout=Mock()).handle()
|
||||
self.assertEqual(result, "Done! Sent 0 notices")
|
||||
|
||||
self.profile.refresh_from_db()
|
||||
@ -121,8 +102,5 @@ class SendDeletionNoticesTestCase(BaseTestCase):
|
||||
self.profile.last_active_date = now() - td(days=15)
|
||||
self.profile.save()
|
||||
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
|
||||
result = cmd.handle()
|
||||
result = Command(stdout=Mock()).handle()
|
||||
self.assertEqual(result, "Done! Sent 0 notices")
|
||||
|
@ -4,6 +4,7 @@ from django.utils import timezone
|
||||
from hc.api.management.commands.prunepingsslow import Command
|
||||
from hc.api.models import Check, Ping
|
||||
from hc.test import BaseTestCase
|
||||
from mock import Mock
|
||||
|
||||
|
||||
class PrunePingsSlowTestCase(BaseTestCase):
|
||||
@ -19,6 +20,6 @@ class PrunePingsSlowTestCase(BaseTestCase):
|
||||
Ping.objects.create(owner=c, n=1)
|
||||
Ping.objects.create(owner=c, n=2)
|
||||
|
||||
Command().handle()
|
||||
Command(stdout=Mock()).handle()
|
||||
|
||||
self.assertEqual(Ping.objects.count(), 1)
|
||||
|
@ -32,8 +32,7 @@ class SendReportsTestCase(BaseTestCase):
|
||||
self.check.save()
|
||||
|
||||
def test_it_sends_report(self):
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
cmd = Command(stdout=Mock())
|
||||
cmd.pause = Mock() # don't pause for 1s
|
||||
|
||||
found = cmd.handle_one_monthly_report()
|
||||
@ -84,8 +83,7 @@ class SendReportsTestCase(BaseTestCase):
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
def test_it_sends_nag(self):
|
||||
cmd = Command()
|
||||
cmd.stdout = Mock() # silence output to stdout
|
||||
cmd = Command(stdout=Mock())
|
||||
cmd.pause = Mock() # don't pause for 1s
|
||||
|
||||
found = cmd.handle_one_nag()
|
||||
|
Loading…
x
Reference in New Issue
Block a user