Пример #1
0
def register_messengers():
    """Регистрирует средства отсылки сообщений.

    :return:
    """

    SETTINGS = settings.SITEMESSAGES_SETTINGS
    SETTINGS_TWITTER = SETTINGS['twitter']
    SETTINGS_SMTP = SETTINGS['smtp']

    messengers = []
    if SETTINGS_TWITTER:
        from sitemessage.messengers.twitter import TwitterMessenger
        messengers.append(TwitterMessenger(*SETTINGS_TWITTER))

    if SETTINGS_SMTP:
        from sitemessage.messengers.smtp import SMTPMessenger
        messengers.append(SMTPMessenger(*SETTINGS_SMTP))

    if messengers:
        register_messenger_objects(*messengers)
Пример #2
0
def register_messengers():
    """Регистрирует средства отсылки сообщений.

    :return:
    """

    SETTINGS = settings.SITEMESSAGES_SETTINGS
    SETTINGS_TWITTER = SETTINGS['twitter']
    SETTINGS_SMTP = SETTINGS['smtp']

    messengers = []
    if SETTINGS_TWITTER:
        from sitemessage.messengers.twitter import TwitterMessenger
        messengers.append(TwitterMessenger(*SETTINGS_TWITTER))

    if SETTINGS_SMTP:
        from sitemessage.messengers.smtp import SMTPMessenger
        messengers.append(SMTPMessenger(*SETTINGS_SMTP))

    if messengers:
        register_messenger_objects(*messengers)
Пример #3
0
def register_messengers():
    """Регистрирует средства отсылки сообщений."""

    SETTINGS = settings.SITEMESSAGES_SETTINGS
    SOCKS5_PROXY = settings.SOCKS5_PROXY

    SETTINGS_TWITTER = SETTINGS['twitter']
    SETTINGS_SMTP = SETTINGS['smtp']
    SETTINGS_TELEGRAM = SETTINGS['telegram']
    SETTINGS_FB = SETTINGS['fb']
    SETTINGS_VK = SETTINGS['vk']

    messengers = []

    if SETTINGS_TWITTER:
        from sitemessage.messengers.twitter import TwitterMessenger
        messengers.append(TwitterMessenger(*SETTINGS_TWITTER))

    if SETTINGS_SMTP:
        from sitemessage.messengers.smtp import SMTPMessenger
        messengers.append(SMTPMessenger(*SETTINGS_SMTP))

    if SETTINGS_TELEGRAM:
        from sitemessage.messengers.telegram import TelegramMessenger
        messengers.append(
            TelegramMessenger(*SETTINGS_TELEGRAM,
                              proxy={'https': f'socks5://{SOCKS5_PROXY}'}
                              if SOCKS5_PROXY else None))

    if SETTINGS_FB:
        from sitemessage.messengers.facebook import FacebookMessenger
        messengers.append(FacebookMessenger(*SETTINGS_FB))

    if SETTINGS_VK:
        from sitemessage.messengers.vkontakte import VKontakteMessenger
        messengers.append(VKontakteMessenger(*SETTINGS_VK))

    if messengers:
        register_messenger_objects(*messengers)
Пример #4
0
def register_messengers():
    """Регистрирует средства отсылки сообщений.

    :return:
    """

    SETTINGS = settings.SITEMESSAGES_SETTINGS
    SETTINGS_TWITTER = SETTINGS['twitter']
    SETTINGS_SMTP = SETTINGS['smtp']
    SETTINGS_TELEGRAM = SETTINGS['telegram']
    SETTINGS_FB = SETTINGS['fb']
    SETTINGS_VK = SETTINGS['vk']

    messengers = []
    if SETTINGS_TWITTER:
        from sitemessage.messengers.twitter import TwitterMessenger
        messengers.append(TwitterMessenger(*SETTINGS_TWITTER))

    if SETTINGS_SMTP:
        from sitemessage.messengers.smtp import SMTPMessenger
        messengers.append(SMTPMessenger(*SETTINGS_SMTP))

    if SETTINGS_TELEGRAM:
        from sitemessage.messengers.telegram import TelegramMessenger
        messengers.append(TelegramMessenger(*SETTINGS_TELEGRAM))

    if SETTINGS_FB:
        from sitemessage.messengers.facebook import FacebookMessenger
        messengers.append(FacebookMessenger(*SETTINGS_FB))

    if SETTINGS_VK:
        from sitemessage.messengers.vkontakte import VKontakteMessenger
        messengers.append(VKontakteMessenger(*SETTINGS_VK))

    if messengers:
        register_messenger_objects(*messengers)
Пример #5
0
messenger_fb = mock_thirdparty(
    'requests',
    lambda: FacebookMessenger('pagetoken', proxy=lambda: {'https': '0.0.0.0'}))
messenger_fb.lib = MagicMock()
messenger_fb.lib.exceptions.RequestException = MockException

messenger_vk = mock_thirdparty('requests',
                               lambda: VKontakteMessenger('apptoken'))
messenger_vk.lib = MagicMock()
messenger_vk.lib.exceptions.RequestException = MockException

register_messenger_objects(
    messenger_smtp,
    messenger_xmpp,
    messenger_twitter,
    messenger_telegram,
    messenger_fb,
    messenger_vk,
)

register_builtin_message_types()

WONDERLAND_DOMAIN = '@wonderland'


class MessengerForTest(MessengerBase):

    title = 'Test messenger'
    alias = 'test_messenger'
    last_send = None
Пример #6
0
def test_register_messengers():
    messenger = type('MyMessenger', (MessengerBase,), {})  # type: MessengerBase
    register_messenger_objects(messenger)
    assert messenger.get_alias() in get_registered_messenger_objects()
Пример #7
0
messenger_telegram = mock_thirdparty('requests', lambda: TelegramMessenger('bottoken'))
messenger_telegram.lib = MagicMock()
messenger_telegram.lib.exceptions.RequestException = MockException

messenger_fb = mock_thirdparty('requests', lambda: FacebookMessenger('pagetoken'))
messenger_fb.lib = MagicMock()
messenger_fb.lib.exceptions.RequestException = MockException

messenger_vk = mock_thirdparty('requests', lambda: VKontakteMessenger('apptoken'))
messenger_vk.lib = MagicMock()
messenger_vk.lib.exceptions.RequestException = MockException

register_messenger_objects(
    messenger_smtp,
    messenger_xmpp,
    messenger_twitter,
    messenger_telegram,
    messenger_fb,
    messenger_vk,
)

register_builtin_message_types()


WONDERLAND_DOMAIN = '@wonderland'


class MessengerForTest(MessengerBase):

    title = 'Test messenger'
    alias = 'test_messenger'
    last_send = None
Пример #8
0
def test_register_messengers():
    messenger = type('MyMessenger', (MessengerBase,), {})  # type: MessengerBase
    register_messenger_objects(messenger)
    assert messenger.get_alias() in get_registered_messenger_objects()