class TestNotifiable: def setup_method(self): self.app = App() self.app.bind('Container', self.app) self.app.bind('ViewClass', View(self.app)) # self.app.make('ViewClass').add_environment('notifications/snippets') self.app.bind('View', View(self.app).render) self.app.bind('MailConfig', MockMailConfig) self.app.bind('MailTerminalDriver', MailTerminalDriver) self.app.bind('MailMailgunDriver', MailMailgunDriver) self.app.bind('MailManager', MailManager(self.app)) self.app.bind( 'Mail', self.app.make('MailManager').driver(MockMailConfig.DRIVER)) # Setup and test Queueing self.app.bind('QueueAsyncDriver', QueueAsyncDriver) self.app.bind('QueueConfig', queue) self.app.bind('Container', self.app) self.app.bind('QueueManager', QueueManager(self.app)) self.app.swap(Queue, self.app.make('QueueManager').driver('async')) self.notification = WelcomeNotification self.notify = Notify(self.app) def test_notification_sends_mail(self): assert self.notify.mail(WelcomeNotification, to='*****@*****.**') is None def test_notification_sends_slack(self): assert self.notify.slack(WelcomeNotification) is None def test_notify_returns_called_notification(self): self.notify.mail(WelcomeNotification) assert self.notify.called_notifications def test_notification_sets_protected_members(self): assert self.notify.mail(WelcomeNotification, to='*****@*****.**') is None assert self.notify.called_notifications[0]._to == '*****@*****.**' def test_mail_notification_appends_template(self): assert self.notify.mail(WelcomeNotification, to='*****@*****.**') is None assert 'We greatly value your service!' in self.notify.called_notifications[ 0].template def test_mail_notification_should_queue(self): assert self.notify.mail(ShouldQueueWelcomeNotification, to='*****@*****.**') is None def test_can_send_with_via_method(self): notifications = self.notify.via('mail').send( ShouldQueueWelcomeNotification, to="*****@*****.**").called_notifications assert isinstance(notifications[0], ShouldQueueWelcomeNotification)
def test_can_substitute_with_make_object(self): app = App() app.swap(SubstituteThis, MakeObject()) assert isinstance(app.make(SubstituteThis), MakeObject)
def test_can_substitute(self): app = App() app.swap(SubstituteThis, self._substitute) assert app.resolve(self._test_substitute) == 'test'
def test_can_substitute_with_object(self): app = App() app.swap(SubstituteThis, MakeObject()) assert isinstance(app.resolve(self._test_substitute), MakeObject)
def test_can_substitute(self): app = App() app.swap(SubstituteThis, self._substitute) self.assertEqual(app.resolve(self._test_substitute), 'test')