Example #1
0
    def setUpClass(cls):
        # Suppress logging to keep unittest output clean
        import logging
        logger = logging.getLogger('werkzeug')
        logger.setLevel(logging.ERROR)

        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except Exception as e:
            print e
            logging.critical(
                'Could not start Firefox browser for running '
                'selenium tests. Error{error}'.format(error=e.message))

        # skip the tests if browser is not launched
        if cls.client:
            # Create application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # Empty any data if present
            MyBot.objects.delete()
            Message.objects.delete()

            MyBot.drop_collection()
            Message.drop_collection()

            # Populate database
            MyBot.generate_fake(5)
            Message.generate_fake(100)

            # start flask server in another thread.
            threading.Thread(target=cls.app.run).start()
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
Example #3
0
"""
import sys
import logging
from botapp import create_app, db
from botapp.models import MyBot, Message
from flask_script import Manager, Shell
from telegram.error import NetworkError

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s - %(name)s - '
                           '%(levelname)s - %(message)s')
logger = logging.getLogger()
logger.setLevel(logging.INFO)

try:
    app = create_app('default')
except NetworkError:
    logger.error('Network error while communicating with Telegram API, please '
                 'try again.')
    sys.exit(-1)
manager = Manager(app)


def make_shell_context():
    """
    Make context for Shell.
    :return: Application models, database and application object.
    """
    return dict(app=app, MyBot=MyBot, Message=Message, db=db)

manager.add_command("shell", Shell(make_context=make_shell_context))