Пример #1
0
 def test_notify_link(self):
     settings = TelegramSettings()
     settings.access_token = self.helper.real_token
     settings.chat_id = self.helper.real_chat_id
     self.notifier.update_settings(settings)
     response = self.notifier.notify('hello', 'yay', 'http://mywebsite.com')
     self.assertTrue(response)
Пример #2
0
 def test_notify_link(self):
     settings = TelegramSettings()
     settings.access_token = self.helper.real_token
     settings.chat_id = self.helper.real_chat_id
     self.notifier.update_settings(settings)
     response = self.notifier.notify('hello', 'yay', 'http://mywebsite.com')
     self.assertTrue(response)
Пример #3
0
 def test_notify_multiple_chat_ids(self):
     settings = TelegramSettings()
     settings.access_token = self.helper.real_token
     settings.chat_ids = "{0}, {0}".format(self.helper.real_chat_id)
     self.notifier.update_settings(settings)
     response = self.notifier.notify('hello', 'yay')
     self.assertTrue(response)
Пример #4
0
    def test_notify_failed(self):
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message,
                         "Access Token or User Id was not specified")

        settings = TelegramSettings()
        self.notifier.update_settings(settings)

        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message,
                         "Access Token or User Id was not specified")

        settings.access_token = self.helper.fake_token
        self.notifier.update_settings(settings)
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message,
                         "Access Token or User Id was not specified")

        settings.access_token = None
        settings.chat_id = self.helper.fake_chat_id
        self.notifier.update_settings(settings)
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message,
                         "Access Token or User Id was not specified")

        settings.access_token = self.helper.fake_token
        settings.chat_id = self.helper.fake_chat_id
        self.notifier.update_settings(settings)
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 2)
        self.assertEqual(e.exception.message,
                         'Failed to send Telegram notification')
Пример #5
0
    def test_notify_failed(self):
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message, "Access Token or User Id was not specified")

        settings = TelegramSettings()
        self.notifier.update_settings(settings)

        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message, "Access Token or User Id was not specified")

        settings.access_token = self.helper.fake_token
        self.notifier.update_settings(settings)
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message, "Access Token or User Id was not specified")

        settings.access_token = None
        settings.chat_id = self.helper.fake_chat_id
        self.notifier.update_settings(settings)
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 1)
        self.assertEqual(e.exception.message, "Access Token or User Id was not specified")

        settings.access_token = self.helper.fake_token
        settings.chat_id = self.helper.fake_chat_id
        self.notifier.update_settings(settings)
        with self.assertRaises(TelegramException) as e:
            self.notifier.notify('hello', 'yaay')
        self.assertEqual(e.exception.code, 2)
        self.assertEqual(e.exception.message, 'Failed to send Telegram notification')