Exemple #1
0
async def create_task(request):
    errors = None
    status_code = 201
    form = TaskForm().load(request.json)
    if not form.errors:
        async with app.engine.acquire() as conn:
            await conn.execute(Tasks.insert(),
                               id=form.data.get('id', None),
                               title=form.data['title'],
                               description=form.data['description'],
                               status=form.data['status'])
            await conn.connection.commit()
    else:
        errors = form.errors
        status_code = 400
    return response.json({'errors': errors}, status=status_code)
Exemple #2
0
    def setUp(self):
        """Connect to test_db, which must be created manually. Table tasks also must be created manually.
         Primary Key (id) must not be auto increment."""

        app.engine = create_engine(
            "mysql+pymysql://{user}:{password}@{host}/{db}".format(
                user=app.config.DB_USER,
                db=app.config.DB_NAME,
                host=app.config.DB_HOST,
                password=app.config.DB_PASSWORD))
        with app.engine.connect() as conn:
            # Fill test_db with test data
            for task in tasks:
                conn.execute(Tasks.insert(),
                             id=task['id'],
                             title=task['title'],
                             description=task['description'],
                             status=task['status'])