コード例 #1
0
ファイル: test_channel.py プロジェクト: Dadard29/PassiveDNS
 def test_init_email(self):
     ch = Channel.new(CHANNEL_NAME, channel_email['type'],
                      channel_email['infos'])
     self.assertEqual(ch.name, CHANNEL_NAME)
     self.assertEqual(ch.infos.smtp_host,
                      channel_email['infos']['smtp_host'])
     self.assertEqual(ch.infos.smtp_port,
                      channel_email['infos']['smtp_port'])
     self.assertEqual(ch.infos.sender_email,
                      channel_email['infos']['sender_email'])
     self.assertEqual(ch.infos.sender_password,
                      channel_email['infos']['sender_password'])
コード例 #2
0
ファイル: channels_admin.py プロジェクト: Dadard29/PassiveDNS
def ch_post(name):
    try:
        ch_type = request.args.get('type')
        if ch_type is None or ch_type == '':
            return error_view(400, "missing parameter")

        infos = request.json
        if infos is None or infos == '':
            return error_view(400, "missing json")

        if Channel.exists(name):
            return error_view(500, "a channel with this name already exists")

        new_ch = Channel.new(name, ch_type, infos)
        new_ch.insert()

        return ch_admin_post_view(new_ch)

    except KeyError:
        return error_view(500, "error parsing json input")

    except ChannelTypeError:
        return error_view(400, "invalid channel type")
コード例 #3
0
import os
from unittest import TestCase
from datetime import datetime

from channels.email import send_email
from channels.templates_list import TEST_TEMPLATE
from models.channel import Channel
from models.channel_meta import ChannelEmail

channel_email = Channel.new(
    "test", ChannelEmail.TYPE, {
        "smtp_host": "mail.gmx.com",
        "smtp_port": "587",
        "sender_email": "*****@*****.**",
        "sender_password": os.environ['SMTP_PASSWORD']
    })

user_mail = "*****@*****.**"


class TestEmail(TestCase):
    def test_send(self):
        template = TEST_TEMPLATE
        template.set_format(date=str(datetime.now().date()))
        send_email(user_mail, channel_email.infos, template)
コード例 #4
0
ファイル: test_channel.py プロジェクト: Dadard29/PassiveDNS
 def test_init_error(self):
     with self.assertRaises(ChannelTypeError):
         Channel.new(CHANNEL_NAME, "stuff", {})
コード例 #5
0
ファイル: test_channel.py プロジェクト: Dadard29/PassiveDNS
 def test_init_telegram(self):
     ch = Channel.new(CHANNEL_NAME, channel_telegram['type'],
                      channel_telegram['infos'])
     self.assertEqual(ch.name, CHANNEL_NAME)
     self.assertEqual(ch.infos.bot_token,
                      channel_telegram['infos']['bot_token'])
コード例 #6
0
ファイル: test_telegram.py プロジェクト: Dadard29/PassiveDNS
import os
from unittest import TestCase
from datetime import datetime

from channels.telegram import send_telegram
from channels.templates_list import TEST_TEMPLATE
from models.channel import Channel
from models.channel_meta import ChannelTelegram

channel_telegram = Channel.new("test", ChannelTelegram.TYPE,
                               {"bot_token": os.environ['TELEGRAM_BOT_TOKEN']})

chat_id = os.environ['CHAT_ID']


class TestTelegram(TestCase):
    def test_send(self):
        template = TEST_TEMPLATE
        template.set_format(date=str(datetime.now().date()))
        send_telegram(chat_id, channel_telegram.infos, template)
コード例 #7
0
ファイル: test_discord.py プロジェクト: Dadard29/PassiveDNS
import os
from unittest import TestCase
from datetime import datetime

from channels.discord_chan import send_discord
from models.channel import Channel
from models.channel_meta import ChannelDiscord
from channels.templates_list import TEST_TEMPLATE

channel_discord = Channel.new("discord", ChannelDiscord.TYPE,
                              {"bot_token": os.environ['DISCORD_BOT_TOKEN']})

user_id = os.environ['DISCORD_USER_ID']


class TestDiscord(TestCase):
    def test_send(self):
        template = TEST_TEMPLATE
        template.set_format(date=str(datetime.now().date()))
        send_discord(user_id, channel_discord.infos, template)