Esempio n. 1
0
    async def do_stuff(self):
        """ Limits the messages """
        await self.bot.wait_until_ready()
        while True:
            await asyncio.sleep(300)
            if self.is_bad_user():
                with contextlib.supress(Exception):
                    await self.bot.send_to_owners(
                        "Go reset your token and stop hosting on "
                        "Heroku if you can't be bothered to do it without leaking a token."
                    )

                with contextlib.suppress(Exception):
                    g = discord.Game(
                        name=
                        "This bot's token appears to have been leaked online.")
                    await self.bot.change_presence(game=g)
            else:
                raise asyncio.CancelledError()
Esempio n. 2
0
from datetime import datetime
import uuid

from django.test import TestCase
from mock import patch, Mock, MagicMock

from corehq.apps.domain.models import Domain
from corehq.apps.sms.handlers.form_session import form_session_handler
from corehq.apps.sms.models import (PhoneNumber, SMS, INCOMING, MessagingEvent,
                                    MessagingSubEvent)
from corehq.apps.smsforms.models import SQLXFormsSession
from corehq.messaging.smsbackends.test.models import SQLTestSMSBackend


@patch('corehq.apps.smsforms.util.critical_section_for_smsforms_sessions',
       new=lambda contact_id: contextlib.supress())
class FormSessionTestCase(TestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.domain = Domain(name=uuid.uuid4().hex)
        cls.domain.save()

        cls.number = PhoneNumber(domain=cls.domain.name,
                                 owner_doc_type='CommCareCase',
                                 owner_id='fake-owner-id1',
                                 phone_number='01112223333',
                                 backend_id=None,
                                 ivr_backend_id=None,
                                 verified=True,
                                 is_two_way=True,
async def main():
    with contextlib.supress(IndexError):
        await raise_(IndexError)  # does await work here?