예제 #1
0
    def test1(self):
        global _app
        if _app is None:
            tested_app = create_app(debug=True)
            _app = tested_app
        else:
            tested_app = _app
        restart_db_tables(db, tested_app)

        with tested_app.test_client() as client:

            # login
            reply = login(client, '*****@*****.**', 'admin')
            assert b'Hi Admin!' in reply.data

            reply = client.get('/stories/filter')
            self.assertIn(b'Filter Stories', reply.data)

            # Filter correctly a time interval
            reply = client.post('/stories/filter', data=dict(
                init_date='2019-01-01',
                end_date='2019-12-01'
            ), follow_redirects=True)
            self.assertIn(b'Trial story of example', reply.data)

            # Filter wrongly a time interval (init_date > end_date)
            reply = client.post('/stories/filter', data=dict(
                init_date='2019-12-01',
                end_date='2019-01-01'
            ), follow_redirects=True)
            self.assertIn(b'Cant travel back in time', reply.data)
    def test1(self):
        _app = create_app()
        with _app.test_client() as client:
            with mock.patch('service.views.stories.get_users_s') as get_user_mock:
                with mock.patch('service.views.stories.get_stories_s') as get_stories_mock:
                    with mock.patch('service.views.stories.is_follower_s') as is_follower_mock:
                        get_user_mock.return_value = {
                                "firstname": "luca",
                                "lastname": "perez",
                                "email": "*****@*****.**",
                                "dateofbirth": "19/01/01",
                                "user_id": 1
                        }

                        get_stories_mock.return_value = [
                            {
                                'id': 1,
                                'text': 'diodiddio',
                                'dicenumber': 0,
                                'roll': {},
                                'date': '1/1/1',
                                'likes': 0,
                                'dislikes': 1,
                                'author_id': 1}
                            ]

                        is_follower_mock.return_value = True

                        reply = client.get('/stories')
                        self.assertEqual(reply.status_code, 200)
예제 #3
0
def app():
    db_fd, db_path = tempfile.mkstemp()
    db_url = 'sqlite:///' + db_path
    app = create_app(config='service/tests/config_test.py', database=db_url)

    yield app

    os.close(db_fd)
    os.unlink(db_path)
예제 #4
0
def get_app_config(key):
    opath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    if opath not in sys.path:
        sys.path.insert(0, opath)
        
    from service import app as app_module
    app = app_module.create_app()
    
    print 'Getting actual config for', key, app.config.get(key)
    return app.config.get(key)
예제 #5
0
def get_app_config(key):
    opath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    if opath not in sys.path:
        sys.path.insert(0, opath)

    from service import app as app_module
    app = app_module.create_app()

    print 'Getting actual config for', key, app.config.get(key)

    return app.config.get(key)
예제 #6
0
 def test2(self):
     global _app
     if _app is None:
         tested_app = create_app(debug=True)
         _app = tested_app
     else:
         tested_app = _app
     # create 100 Stories
     restart_db_tables(db, tested_app)
     with tested_app.test_client() as client:
         # login
         reply = login(client, '*****@*****.**', 'admin')
         assert b'Hi Admin!' in reply.data
예제 #7
0
def app():
    from service.app import create_app

    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'test_app.db')

    app = create_app(
        {
            'SQLALCHEMY_DATABASE_URI': SQLALCHEMY_DATABASE_URI,
        },
    )
    with app.app_context():
        yield app
        db_sqlalchemy.drop_all()
예제 #8
0
#!/usr/bin/env python

# Copyright 2017 Kubos Corporation
# Licensed under the Apache License, Version 2.0
# See LICENSE file for details.
"""
Boilerplate main for service application.
"""

import argparse
from service import app
import yaml

parser = argparse.ArgumentParser(description='Example Service')
parser.add_argument('config', type=str, help='path to config file')
args = parser.parse_args()

with open(args.config) as ymlfile:
    cfg = yaml.load(ymlfile)

app = app.create_app()
app.run(host=cfg['APP_IP'], port=cfg['APP_PORT'])
 def test2(self):
     app = create_app().test_client()
     reply = app.get('/stories/nonExistingID')
     self.assertEqual(reply.status_code, 404)
예제 #10
0
from service.app import create_app

app = create_app(config='service/config.py')

if __name__ == '__main__':
    app.run()
예제 #11
0
# -*- coding: utf-8 -*-
"""
    wsgi
    ~~~~

    entrypoint wsgi script
"""

from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware

from service import app as citation_helper

application = DispatcherMiddleware(citation_helper.create_app(),mounts={
  #'/mount1': sample_application2.create_app(), #Could have multiple API-applications at different mount points
  })

if __name__ == "__main__":
    run_simple('0.0.0.0', 4000, application, use_reloader=False, use_debugger=True)
예제 #12
0
"""
Alembic migration management file
"""
import os
import sys

PROJECT_HOME = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(PROJECT_HOME)
from flask.ext.script import Manager, Command, Option
from flask.ext.migrate import Migrate, MigrateCommand
from models import db, Resend, Events
from service.app import create_app

# Load the app with the factory
app = create_app()


class CreateDatabase(Command):
    """
    Creates the database based on models.py
    """
    @staticmethod
    def run(app=app):
        """
        Creates the database in the application context
        :return: no return
        """
        with app.app_context():
            db.create_all()
            db.session.commit()
예제 #13
0
 def getTester(self):
     application = app.create_app()
     tester = application.test_client(self)
     return tester
예제 #14
0
# -*- coding: utf-8 -*-
"""
    wsgi
    ~~~~
    entrypoint wsgi script
"""

from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware

from service import app

application = app.create_app()

if __name__ == "__main__":
    run_simple('0.0.0.0',
               4000,
               application,
               use_reloader=False,
               use_debugger=True)
예제 #15
0
    def setUp(self):
        self.app = create_app(config)
        self.client = self.app.test_client()

        self._prepare_test_data(10)
예제 #16
0
from service.app import create_app

app = create_app(config='config.py')

if __name__ == '__main__':
    app.run()
예제 #17
0
# -*- coding: utf-8 -*-
"""
    wsgi
    ~~~~

    entrypoint wsgi script
"""

from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware

from service import app

application = app.create_app()

if __name__ == "__main__":
    run_simple('0.0.0.0', 4000, application, use_reloader=False,
               use_debugger=True)