def test_check_for_new_invites_no_invite(self):
     Message = namedtuple('Message', ['subject'])
     m = Message('invitation to moderate')
     reddit = Mock(inbox=Mock(messages=PropertyMock(return_value=[m])))
     with mock.patch.object(NewActivationMonitor,
                            'activate_sub') as mocked_monitor:
         monitor = NewActivationMonitor(MagicMock(), reddit=reddit)
         monitor.check_for_new_invites()
         mocked_monitor.assert_called()
 def test_is_already_active_true(self):
     sub_repo = MagicMock()
     uow = MagicMock()
     uowm = MagicMock()
     sub_repo.get_by_sub.return_value = MonitoredSub(name='testsub', id=123)
     type(uow).monitored_sub = mock.PropertyMock(return_value=sub_repo)
     uow.__enter__.return_value = uow
     uow.commit.return_value = None
     uowm.start.return_value = uow
     monitor = NewActivationMonitor(uowm, Mock())
     self.assertTrue(monitor.is_already_active('testsub'))
 def test__create_monitored_sub_in_db_already_exists(self):
     sub_repo = MagicMock()
     uow = MagicMock()
     uowm = MagicMock()
     sub_repo.get_by_sub.return_value = MonitoredSub(name='testsub', id=123)
     type(uow).monitored_sub = mock.PropertyMock(return_value=sub_repo)
     uow.__enter__.return_value = uow
     uow.commit.return_value = None
     uowm.start.return_value = uow
     monitor = NewActivationMonitor(uowm, Mock())
     result = monitor._create_monitored_sub_in_db(
         Mock(subreddit=Mock(display_name='testsub')))
     self.assertEqual(123, result.id)
 def test__notify_added(self):
     sub_repo = MagicMock()
     uow = MagicMock()
     uowm = MagicMock()
     sub_repo.get_by_sub.return_value = MonitoredSub(name='testsub')
     type(uow).monitored_sub = mock.PropertyMock(return_value=sub_repo)
     uow.__enter__.return_value = uow
     uow.commit.return_value = None
     uowm.start.return_value = uow
     monitor = NewActivationMonitor(uowm, Mock())
     subreddit = Mock(message=Mock(return_value=None),
                      display_name='testsub')
     monitor._notify_added(subreddit)
     subreddit.message.assert_called()
     self.assertTrue(sub_repo.get_by_sub.activation_notification_sent)
예제 #5
0
def event_callback(event):
    print(event)


if __name__ == '__main__':
    config = Config()
    uowm = SqlAlchemyUnitOfWorkManager(get_db_engine(config))
    reddit = get_reddit_instance(config)
    reddit_manager = RedditManager(reddit)
    notification_svc = NotificationService(config)
    comment_monitor = BotCommentMonitor(reddit_manager,
                                        uowm,
                                        config,
                                        notification_svc=notification_svc)
    stats_updater = StatsUpdater()
    activation_monitor = NewActivationMonitor(
        uowm, get_reddit_instance(config), notification_svc=notification_svc)
    event_logger = EventLogging(config=config)
    response_handler = ResponseHandler(reddit_manager, uowm, event_logger)
    inbox_monitor = InboxMonitor(uowm, reddit_manager.reddit, response_handler)

    #config_updater.update_configs()

    scheduler = BackgroundScheduler()
    scheduler.add_listener(event_callback, EVENT_JOB_ERROR)
    scheduler.add_job(func=activation_monitor.check_for_new_invites,
                      trigger='interval',
                      minutes=1,
                      name='activation_checker',
                      max_instances=1)
    scheduler.add_job(func=stats_updater.run_update,
                      trigger='interval',
 def test__create_wiki_page(self):
     monitor = NewActivationMonitor(Mock(), Mock())
     subreddit = Mock(wiki=Mock(create=Mock(return_value=None)),
                      display_name='testsub')
     monitor._create_wiki_page(subreddit)
     subreddit.wiki.create.assert_called()