Last active
June 10, 2016 20:44
-
-
Save bengolder/dcc6090bf1b7bc80f87eed38d4981df6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @patch('intake.management.commands.send_unopened_apps_notification.notifications') | |
| @patch('intake.management.commands.send_unopened_apps_notification.models') | |
| @patch('intake.management.commands.send_unopened_apps_notification.settings') | |
| def test_send_unopened_apps_notification(self, settings, models, notifications): | |
| models.FormSubmission.get_unopened_apps.return_value = [ | |
| Mock(id=1), Mock(id=2) | |
| ] | |
| settings.DEFAULT_NOTIFICATION_EMAIL = "[email protected]" | |
| send = Mock() | |
| notifications.front_email_daily_app_bundle.send = send | |
| from intake.management.commands.send_unopened_apps_notification import Command | |
| # instantiate | |
| # this step makes me nervous, | |
| # because I don't what other things that Django | |
| # touches during __init__ unless I go read the method | |
| command = Command() | |
| # patch the inherited methods that I didn't write | |
| command.style = Mock() | |
| command.stdout = Mock() | |
| # run the unit | |
| command.handle() | |
| send.assert_called_once_with( | |
| to="[email protected]", | |
| count=2, | |
| submission_ids=[1,2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.core.management.base import BaseCommand | |
| from django.conf import settings | |
| from intake import notifications, models | |
| class Command(BaseCommand): | |
| help = 'Sends an email about unopened applications' | |
| def handle(self, *args, **options): | |
| email = settings.DEFAULT_NOTIFICATION_EMAIL | |
| unopened_submissions = models.FormSubmission.get_unopened_apps() | |
| count = len(unopened_submissions) | |
| notifications.front_email_daily_app_bundle.send( | |
| to=email, | |
| count=count, | |
| submission_ids=[s.id for s in unopened_submissions] | |
| ) | |
| self.stdout.write( | |
| self.style.SUCCESS( | |
| "Email {} with a link to {} unopened applications".format( | |
| email, count) | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The main concern I have with this method is that in Django generally, I don't know what other things are affected or accessed by any given inherited
__init__method.