Example #1
0
def run():
    connect(get_config().MONGODB_DATABASE, host=get_config().MONGODB_URL, port=get_config().MONGODB_PORT)
    # workaround for dual runnings of the server
    if 'WERKZEUG_RUN_MAIN' in os.environ and os.environ['WERKZEUG_RUN_MAIN'] == 'true':
        start_event_thread(app)
        start_heartbeat_thread(app)
        start_rpc_proxy(app)
        initialize_runner()
    #app.run(host='0.0.0.0')
    socketio.run(app, host='0.0.0.0')
Example #2
0
async def send_email(task):
    from_addr = get_config().FROM_ADDR
    password = get_config().SMTP_PASSWORD
    smtp_user = get_config().SMTP_USER
    smtp_server = get_config().SMTP_SERVER
    smtp_server_port = get_config().SMTP_SERVER_PORT
    smtp_always_cc = get_config().SMTP_ALWAYS_CC

    test = await task.test.fetch()
    organization = await test.organization.fetch()
    team = None
    if test.team:
        team = await test.team.fetch()
    tester = await task.tester.fetch()

    body_msg = BODY_TEMPLATE.format(test.test_suite, task.status, task.pk, organization.pk, '&team=%s' % team.pk if team else '')
    msg = MIMEText(body_msg, 'plain', 'utf-8')
    msg['From'] = _format_addr(from_addr)
    msg['To'] = _format_addr(tester.email)
    msg['cc'] = _format_addr(smtp_always_cc)
    msg['Subject'] = Header(SUBJECT_TEMPLATE.format(test.test_suite))

    try:
        server = await async_wraps(smtplib.SMTP)(smtp_server, smtp_server_port, timeout=5)
    except TimeoutError:
        logger.error('SMTP server connecting timeout')
        return
    except timeout:
        logger.error('SMTP server connecting socket timeout')
        return
    except ConnectionRefusedError:
        logger.error('SMTP server connecting refused')
        return
    except socket.gaierror:
        logger.error('Network of SMTP is not available')
        return
    except:
        exc_type, exc_value, exc_tb = sys.exc_info()
        APP.logger.error(f'Un-catched error happened: {exc_type}, {exc_value}')
    else:
        # await async_wraps(server.starttls)()
        # await async_wraps(server.set_debuglevel)(1)
        try:
            await async_wraps(server.login)(smtp_user, password)
        except smtplib.SMTPAuthenticationError:
            logger.error('SMTP authentication failed')
            await async_wraps(server.quit)()
            return
        await async_wraps(server.sendmail)(from_addr, [task.tester.email], msg.as_string())
        await async_wraps(server.quit)()
Example #3
0
def send_email(task):
    from_addr = get_config().FROM_ADDR
    password = get_config().SMTP_PASSWORD
    smtp_user = get_config().SMTP_USER
    smtp_server = get_config().SMTP_SERVER
    smtp_server_port = get_config().SMTP_SERVER_PORT
    smtp_always_cc = get_config().SMTP_ALWAYS_CC

    body_msg = BODY_TEMPLATE.format(
        task.test.test_suite, task.status, task.id, task.test.organization.id,
        '&team=%s' % task.test.team.id if task.test.team else '')
    msg = MIMEText(body_msg, 'plain', 'utf-8')
    msg['From'] = _format_addr(from_addr)
    msg['To'] = _format_addr(task.tester.email)
    msg['cc'] = _format_addr(smtp_always_cc)
    msg['Subject'] = Header(SUBJECT_TEMPLATE.format(task.test.test_suite))

    try:
        server = smtplib.SMTP(smtp_server, smtp_server_port, timeout=5)
    except TimeoutError:
        current_app.logger.error('SMTP server connecting timeout')
        return
    except timeout:
        current_app.logger.error('SMTP server connecting socket timeout')
        return
    except ConnectionRefusedError:
        current_app.logger.error('SMTP server connecting refused')
        return
    except socket.gaierror:
        current_app.logger.error('Network is not available')
        return

    # server.starttls()
    # server.set_debuglevel(1)
    try:
        server.login(smtp_user, password)
    except smtplib.SMTPAuthenticationError:
        current_app.logger.error('SMTP authentication failed')
        server.quit()
        return
    server.sendmail(from_addr, [task.tester.email], msg.as_string())
    server.quit()
Example #4
0
import shutil
import os
from app.main.config import get_config
from flask import current_app
from pathlib import Path

from ..model.database import *
from .response import *

TEST_RESULTS_ROOT = 'test_results'
USER_SCRIPT_ROOT = 'user_scripts'
BACK_SCRIPT_ROOT = 'back_scripts'
TEST_PACKAGE_ROOT = 'pypi'
USERS_ROOT = Path(get_config().USERS_ROOT)
UPLOAD_ROOT = Path(get_config().UPLOAD_ROOT)
STORE_ROOT = Path(get_config().STORE_ROOT)
try:
    os.makedirs(UPLOAD_ROOT)
except FileExistsError:
    pass
try:
    os.makedirs(USERS_ROOT)
except FileExistsError:
    pass
try:
    os.makedirs(STORE_ROOT)
except FileExistsError:
    pass

def get_test_result_path(task):
    return get_test_results_root(task) / str(task.id)
Example #5
0
    monkey_patch(os=False)

from flask_script import Manager
from flask_cors import CORS

from app import blueprint
from app.main import create_app
from mongoengine import connect
from app.main.config import get_config
from task_runner.runner import start_event_thread, start_heartbeat_thread, start_rpc_proxy, initialize_runner, install_sio
from flask_socketio import SocketIO, send, emit
from app.main.controller.socketio_controller import handle_message, \
            handle_join_room, handle_enter_room, handle_leave_room

app = create_app(os.getenv('BOILERPLATE_ENV') or 'dev')
get_config().init_app(app)
app.register_blueprint(blueprint)

async_mode = 'threading' if os.name == 'nt' else 'eventlet'
cors_allowed_origins = '*' if os.getenv('BOILERPLATE_ENV') != 'prod' else None
socketio = SocketIO(app, async_mode=async_mode, cors_allowed_origins=cors_allowed_origins)
install_sio(socketio)

app.app_context().push()
if os.getenv('BOILERPLATE_ENV') != 'prod':
    CORS(app)

manager = Manager(app)


@manager.command
Example #6
0
from sanic import Blueprint, Sanic
from sanic.log import logger
from sanic_openapi import swagger_blueprint
from sanic_limiter import Limiter, get_remote_address
from sanic_cors import CORS
from simple_bcrypt import Bcrypt

from app.main.config import get_config

development = True if (os.getenv('BOILERPLATE_ENV')
                       or 'dev') == 'dev' else False

app = Sanic('Ember For Test Automation')
app.blueprint(swagger_blueprint)
app.config.from_object(get_config())
bcrypt = Bcrypt(app)

if development:
    # CORS(app)
    # app.config['CORS_SUPPORTS_CREDENTIALS'] = True
    sio = socketio.AsyncServer(async_mode='sanic', cors_allowed_origins='*')
else:
    sio = socketio.AsyncServer(async_mode='sanic')
sio.attach(app)

limits = ['20000 per hour', '200000 per day'
          ] if development else ['200 per hour', '2000 per day']
limiter = Limiter(app, global_limits=limits, key_func=get_remote_address)
event_task = None
heartbeat_task = None
Example #7
0
import os
from app.main.config import get_config
from pathlib import Path

from ..model.database import *
from .errors import *

TEST_RESULTS_ROOT = 'test_results'
USER_SCRIPT_ROOT = 'user_scripts'
BACK_SCRIPT_ROOT = 'back_scripts'
USERS_ROOT = Path(get_config().USERS_ROOT)
UPLOAD_DIR = Path(get_config().UPLOAD_ROOT)
try:
    os.mkdir(UPLOAD_DIR)
except FileExistsError:
    pass
try:
    os.mkdir(USERS_ROOT)
except FileExistsError:
    pass


def get_test_result_path(task):
    return get_test_results_root(task) / str(task.id)


def get_test_results_root(task=None, team=None, organization=None):
    if task:
        if team or organization:
            print('team or organization should not used along wite task')
            return None
Example #8
0
def run():
    connect(get_config().MONGODB_DATABASE,
            host=get_config().MONGODB_URL,
            port=get_config().MONGODB_PORT)
    app.run(host='0.0.0.0')