Exemplo n.º 1
0
def send_async_email(message_details):
    """Background task to send an email with Flask-Mail."""
    with app.app_context():
        msg = Message(message_details['subject'],
                      recipients=message_details['recipients'])
        msg.body = message_details['body']
        mail.send(msg)
def run_app():
    app.config['SQLALCHEMY_DATABASE_URI'] = esi_config.database_url
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    with app.app_context():
        db.init_app(app)
        init_db()
        initDbForE2e(wipe=False)
        app.run(host='localhost', port='8080')
Exemplo n.º 3
0
def run_app():
    print('Running WSGI')
    sys.stdout.flush()
    app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
        'DATABASE_URL', database_url)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    with app.app_context():
        db.init_app(app)
        db.create_all()
    def setUp(self):
        # Make sure that database exists
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'

        with app.app_context():
            db.init_app(app)
            db.create_all()

        self.app = app.test_client()
        self.app_context = app.app_context
Exemplo n.º 5
0
def client():
    from flask_app import app

    app.config["SERVER_NAME"] = "example.com"
    app.config["TESTING"] = True
    client = app.test_client()
    # Establish an application context before running the tests.
    ctx = app.app_context()
    ctx.push()
    yield client  # this is where the testing happens!
    ctx.pop()
Exemplo n.º 6
0
def test_app():
    '''Uses ``app`` imported from flask_app to create a testable Flask
    application.

    :yield: Flask application with a context, ready for testing
    '''
    # Uses global variable "app"
    app.config['TESTING'] = True
    test_app = app.test_client()
    ctx = app.app_context()
    ctx.push()
    yield test_app
    ctx.pop()
Exemplo n.º 7
0
 def test_single_data_point(self):
     features = [
         0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
         0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
         0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
     ]
     with app.app_context():
         response = self.post(dict(features=features))
         self.assertEqual(response.status_code, 200)
         response_object = json.loads(response.data)
         self.assertTrue("scores" in response_object)
         self.assertEqual(len(response_object["scores"]), 1)
         self.assertTrue(isinstance(response_object["scores"][0], float))
Exemplo n.º 8
0
def run_app():
    basedir = os.path.abspath(os.path.dirname(__file__))
    sqlite_location = os.path.join(basedir, 'data.sqlite')
    if os.path.exists(sqlite_location):
        os.remove(sqlite_location)
    print('Sqlite:', sqlite_location)
    app.config['SQLALCHEMY_DATABASE_URI'] =\
        'sqlite:///' + sqlite_location
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['TESTING'] = True
    with app.app_context():
        db.init_app(app)
        db.create_all()
        initDbForE2e(wipe=True)
        app.run(host='localhost', port='8080')
Exemplo n.º 9
0
 def test_single_data_point(self):
     features = [
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
     ]
     with app.app_context():
         response = self.post(dict(features=features))
         self.assertEqual(response.status_code, 200)
         response_object = json.loads(response.data)
         self.assertTrue("scores" in response_object)
         self.assertEqual(len(response_object["scores"]), 1)
         self.assertTrue(isinstance(response_object["scores"][0], float))
Exemplo n.º 10
0
 def test_no_features(self):
     with app.app_context():
         response = self.post(dict(features=None))
         self.assertEqual(response.status_code, 400)
         response_object = json.loads(response.data)
         self.assertTrue("error" in response_object)
Exemplo n.º 11
0
        })
        url = 'https://www.luogu.com.cn/api/verify/captcha'
        res = self.luogu_http.get(url=url)
        predict_res = requests.post('http://fun.newitd.com/captcha/', data=res.content).json()
        if predict_res['code'] != 0 or len(predict_res['message']) != 4:
            return self._get_captcha()
        captcha = predict_res['message']
        print(captcha)
        return captcha

    def _get_csrf_value(self):
        self.luogu_http.headers.update({
            'referer': 'https://www.luogu.com.cn/',
            'content-type': None
        })
        url = 'https://www.luogu.com.cn/auth/login'
        res = self.luogu_http.get(url=url)
        return re.search(r'<meta name="csrf-token" content="(.*?)">', res.text).group(1)


if __name__ == '__main__':
    from flask_app import app

    app.app_context().push()
    from app.models.oj_username import OJUsername

    oju = OJUsername()
    oju.oj_username = '******'
    res = LuoguSpider().get_user_info(oju, {})
    print(res)
Exemplo n.º 12
0
# pylint: disable=W0611
"""Asynchronous tasks backed by Celery"""

import os
from celery import Celery
from flask_app import app as flask


QUEUE_NAME_PREFIX = os.environ['MINTAX_QUEUE_NAME_PREFIX'] \
                    if 'MINTAX_QUEUE_NAME_PREFIX' in os.environ \
                    else 'mintax-dev-'

# pylint: disable=C0103
app = Celery('celery_app',
             broker='sqs://',
             include=['tasks.refresh_employee_travel_history'])
app.conf.broker_transport_options = {'queue_name_prefix': QUEUE_NAME_PREFIX}

# https://stackoverflow.com/questions/16478048/celery-connection-broker-lost-makes-cpu-usage-go-to-100/16580863#16580863
app.conf.broker_heartbeat = 0
app.conf.broker_heartbeat_checkrate = 0

if __name__ == '__main__':
    with flask.app_context():
        app.start()
Exemplo n.º 13
0
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)
Exemplo n.º 14
0
 def setUp(self):
     self.app_context = app.app_context()
     self.app_context.push()
 def tearDown(self):
     with app.app_context():
         db.session.remove()
         db.drop_all()
Exemplo n.º 16
0
 def setUp(self):
     super().setUp()
     app.config.from_object(config['test'])
     self.app_context = app.app_context()
     self.app_context.push()
     self.app = app.test_client()
Exemplo n.º 17
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
Exemplo n.º 18
0
 def test_empty_body(self):
     with app.app_context():
         response = self.post({})
         self.assertEqual(response.status_code, 400)
         response_object = json.loads(response.data)
         self.assertTrue("error" in response_object)
Exemplo n.º 19
0
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)
Exemplo n.º 20
0
 def test_empty_body(self):
     with app.app_context():
         response = self.post({})
         self.assertEqual(response.status_code, 400)
         response_object = json.loads(response.data)
         self.assertTrue("error" in response_object)
Exemplo n.º 21
0
 def test_no_features(self):
     with app.app_context():
         response = self.post(dict(features=None))
         self.assertEqual(response.status_code, 400)
         response_object = json.loads(response.data)
         self.assertTrue("error" in response_object)
            'security_status': float,
        },
        'optional': {
            'current_application_status': str,
            'alliance_name': (str, type(None)),
        },
        'redlisting': {
            'corporation_name': (Corporation, 'corporation_id'),
            'character_name': (Character, 'character_id'),
        },
        'entry_identifier': 'character_id',
    }


    def test_get_admin_API(self):
        pass  # admin isn't a real character

    def test_get_recruiter_API(self):
        pass  # recruiter isn't a real character



if __name__ == '__main__':
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['TESTING'] = True
    with app.app_context():
        db.init_app(app)
        db.create_all()
        unittest.main()
Exemplo n.º 23
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)