def test_creation_api_without_app_dependency(self):
     """Tests that api can be added before app will be passed to manager."""
     manager = APIManager()
     manager.create_api(self.Person)
     manager.init_app(self.flaskapp, self.session)
     response = self.app.get('/api/person')
     assert response.status_code == 200
Exemple #2
0
    def test_multiple_managers_init_multiple_apps(self):
        """Tests for calling :meth:`~APIManager.init_app` on multiple
        :class:`~flask.Flask` applications after calling
        :meth:`~APIManager.create_api` on multiple instances of
        :class:`APIManager`.

        """
        manager1 = APIManager(session=self.session)
        manager2 = APIManager(session=self.session)

        # Create the Flask applications and the test clients.
        flaskapp1 = self.flaskapp
        flaskapp2 = Flask(__name__)
        testclient1 = self.app
        testclient2 = flaskapp2.test_client()
        force_content_type_jsonapi(testclient2)

        # First create the API, then initialize the Flask applications after.
        manager1.create_api(self.Person)
        manager2.create_api(self.Article)
        manager1.init_app(flaskapp1)
        manager2.init_app(flaskapp2)

        # Tests that only the first Flask application gets requests for
        # /api/person and only the second gets requests for /api/article.
        response = testclient1.get('/api/person')
        assert response.status_code == 200
        response = testclient1.get('/api/article')
        assert response.status_code == 404
        response = testclient2.get('/api/person')
        assert response.status_code == 404
        response = testclient2.get('/api/article')
        assert response.status_code == 200
 def test_init_app(self):
     self.db.create_all()
     manager = APIManager(flask_sqlalchemy_db=self.db)
     manager.create_api(self.Person)
     manager.init_app(self.flaskapp)
     response = self.app.get('/api/person')
     assert response.status_code == 200
Exemple #4
0
 def test_init_app(self):
     self.db.create_all()
     manager = APIManager(flask_sqlalchemy_db=self.db)
     manager.create_api(self.Person)
     manager.init_app(self.flaskapp)
     response = self.app.get('/api/person')
     assert response.status_code == 200
Exemple #5
0
 def test_creation_api_without_app_dependency(self):
     """Tests that api can be added before app will be passed to manager."""
     manager = APIManager()
     manager.create_api(self.Person)
     manager.init_app(self.flaskapp, self.session)
     response = self.app.get('/api/person')
     assert response.status_code == 200
Exemple #6
0
    def test_multiple_app_delayed_init(self):
        manager = APIManager(session=self.session)

        # Create the Flask applications and the test clients.
        flaskapp1 = self.flaskapp
        flaskapp2 = Flask(__name__)
        testclient1 = self.app
        testclient2 = flaskapp2.test_client()
        force_json_contenttype(testclient2)

        # First create the API, then initialize the Flask applications after.
        manager.create_api(self.Person, app=flaskapp1)
        manager.create_api(self.Computer, app=flaskapp2)
        manager.init_app(flaskapp1)
        manager.init_app(flaskapp2)

        # Tests that only the first Flask application gets requests for
        # /api/person and only the second gets requests for /api/computer.
        response = testclient1.get('/api/person')
        assert response.status_code == 200
        response = testclient1.get('/api/computer')
        assert response.status_code == 404
        response = testclient2.get('/api/person')
        assert response.status_code == 404
        response = testclient2.get('/api/computer')
        assert response.status_code == 200
    def test_multiple_app_delayed_init(self):
        manager = APIManager(session=self.session)

        # Create the Flask applications and the test clients.
        flaskapp1 = self.flaskapp
        flaskapp2 = Flask(__name__)
        testclient1 = self.app
        testclient2 = flaskapp2.test_client()
        force_json_contenttype(testclient2)

        # First create the API, then initialize the Flask applications after.
        manager.create_api(self.Person, app=flaskapp1)
        manager.create_api(self.Computer, app=flaskapp2)
        manager.init_app(flaskapp1)
        manager.init_app(flaskapp2)

        # Tests that only the first Flask application gets requests for
        # /api/person and only the second gets requests for /api/computer.
        response = testclient1.get('/api/person')
        assert response.status_code == 200
        response = testclient1.get('/api/computer')
        assert response.status_code == 404
        response = testclient2.get('/api/person')
        assert response.status_code == 404
        response = testclient2.get('/api/computer')
        assert response.status_code == 200
Exemple #8
0
    def test_multiple_managers_init_multiple_apps(self):
        """Tests for calling :meth:`~APIManager.init_app` on multiple
        :class:`~flask.Flask` applications after calling
        :meth:`~APIManager.create_api` on multiple instances of
        :class:`APIManager`.

        """
        manager1 = APIManager(session=self.session)
        manager2 = APIManager(session=self.session)

        # Create the Flask applications and the test clients.
        flaskapp1 = self.flaskapp
        flaskapp2 = Flask(__name__)
        testclient1 = self.app
        testclient2 = flaskapp2.test_client()
        force_content_type_jsonapi(testclient2)

        # First create the API, then initialize the Flask applications after.
        manager1.create_api(self.Person)
        manager2.create_api(self.Article)
        manager1.init_app(flaskapp1)
        manager2.init_app(flaskapp2)

        # Tests that only the first Flask application gets requests for
        # /api/person and only the second gets requests for /api/article.
        response = testclient1.get('/api/person')
        assert response.status_code == 200
        response = testclient1.get('/api/article')
        assert response.status_code == 404
        response = testclient2.get('/api/person')
        assert response.status_code == 404
        response = testclient2.get('/api/article')
        assert response.status_code == 200
    def test_init_app(self):
        """Tests for initializing the Flask application after instantiating the
        :class:`flask.ext.restless.APIManager` object.

        """
        manager = APIManager()
        manager.init_app(self.flaskapp, session=self.session)
        manager.create_api(self.Person, app=self.flaskapp)
        response = self.app.get('/api/person')
        assert response.status_code == 200
Exemple #10
0
    def test_init_app(self):
        """Tests for initializing the Flask application after instantiating the
        :class:`flask.ext.restless.APIManager` object.

        """
        manager = APIManager()
        manager.init_app(self.flaskapp, session=self.session)
        manager.create_api(self.Person, app=self.flaskapp)
        response = self.app.get('/api/person')
        assert response.status_code == 200
Exemple #11
0
    def test_single_manager_init_single_app(self):
        """Tests for calling :meth:`~APIManager.init_app` with a single
        :class:`~flask.Flask` application after calling
        :meth:`~APIManager.create_api`.

        """
        manager = APIManager(session=self.session)
        manager.create_api(self.Person)
        manager.init_app(self.flaskapp)
        response = self.app.get('/api/person')
        assert response.status_code == 200
Exemple #12
0
    def test_single_manager_init_single_app(self):
        """Tests for calling :meth:`~APIManager.init_app` with a single
        :class:`~flask.Flask` application after calling
        :meth:`~APIManager.create_api`.

        """
        manager = APIManager(session=self.session)
        manager.create_api(self.Person)
        manager.init_app(self.flaskapp)
        response = self.app.get('/api/person')
        assert response.status_code == 200
Exemple #13
0
class WebServer(object):

    """TODO: Add here description """

    def __init__(self, hostname, port, app):
        self.hostname = hostname
        self.port = port
        self.app = app
        self.apimanager = APIManager()

    def create_blueprints(self, session):
        # Initialize APIManager with Flask object
        self.apimanager.init_app(self.app, session=session)

        # Create API endpoints

        # SmaliClass
        self.apimanager.create_api(
            SmaliClass, app=self.app, methods=['GET', 'POST']
        )

        # SmaliProperty
        self.apimanager.create_api(
            SmaliProperty, app=self.app, methods=['GET', 'POST']
        )

        # SmaliMethod
        self.apimanager.create_api(
            SmaliMethod, app=self.app, methods=['GET', 'POST']
        )

        # SmaliConstString
        self.apimanager.create_api(
            SmaliConstString, app=self.app, methods=['GET', 'POST']
        )

        # SmaliCall
        self.apimanager.create_api(
            SmaliCall, app=self.app, methods=['GET', 'POST']
        )

    def run(self):
        """Runs the server"""
        run_simple(self.hostname, self.port, self.app)
Exemple #14
0
    def test_single_manager_init_multiple_apps(self):
        """Tests for calling :meth:`~APIManager.init_app` on multiple
        :class:`~flask.Flask` applications after calling
        :meth:`~APIManager.create_api`.

        """
        manager = APIManager(session=self.session)
        flaskapp1 = self.flaskapp
        flaskapp2 = Flask(__name__)
        testclient1 = self.app
        testclient2 = flaskapp2.test_client()
        force_content_type_jsonapi(testclient2)
        manager.create_api(self.Person)
        manager.init_app(flaskapp1)
        manager.init_app(flaskapp2)
        response = testclient1.get('/api/person')
        assert response.status_code == 200
        response = testclient2.get('/api/person')
        assert response.status_code == 200
Exemple #15
0
    def test_single_manager_init_multiple_apps(self):
        """Tests for calling :meth:`~APIManager.init_app` on multiple
        :class:`~flask.Flask` applications after calling
        :meth:`~APIManager.create_api`.

        """
        manager = APIManager(session=self.session)
        flaskapp1 = self.flaskapp
        flaskapp2 = Flask(__name__)
        testclient1 = self.app
        testclient2 = flaskapp2.test_client()
        force_content_type_jsonapi(testclient2)
        manager.create_api(self.Person)
        manager.init_app(flaskapp1)
        manager.init_app(flaskapp2)
        response = testclient1.get('/api/person')
        assert response.status_code == 200
        response = testclient2.get('/api/person')
        assert response.status_code == 200
Exemple #16
0
 def test_init_multiple(self):
     manager = APIManager(session=self.session)
     flaskapp1 = self.flaskapp
     flaskapp2 = Flask(__name__)
     testclient1 = self.app
     testclient2 = flaskapp2.test_client()
     force_json_contenttype(testclient2)
     manager.init_app(flaskapp1)
     manager.init_app(flaskapp2)
     manager.create_api(self.Person, app=flaskapp1)
     manager.create_api(self.Computer, app=flaskapp2)
     response = testclient1.get('/api/person')
     assert response.status_code == 200
     response = testclient1.get('/api/computer')
     assert response.status_code == 404
     response = testclient2.get('/api/person')
     assert response.status_code == 404
     response = testclient2.get('/api/computer')
     assert response.status_code == 200
 def test_init_multiple(self):
     manager = APIManager(session=self.session)
     flaskapp1 = self.flaskapp
     flaskapp2 = Flask(__name__)
     testclient1 = self.app
     testclient2 = flaskapp2.test_client()
     force_json_contenttype(testclient2)
     manager.init_app(flaskapp1)
     manager.init_app(flaskapp2)
     manager.create_api(self.Person, app=flaskapp1)
     manager.create_api(self.Computer, app=flaskapp2)
     response = testclient1.get('/api/person')
     assert response.status_code == 200
     response = testclient1.get('/api/computer')
     assert response.status_code == 404
     response = testclient2.get('/api/person')
     assert response.status_code == 404
     response = testclient2.get('/api/computer')
     assert response.status_code == 200
Exemple #18
0
    def test_multiple_managers_init_single_app(self):
        """Tests for calling :meth:`~APIManager.init_app` on a single
        :class:`~flask.Flask` application after calling
        :meth:`~APIManager.create_api` on multiple instances of
        :class:`APIManager`.

        """
        manager1 = APIManager(session=self.session)
        manager2 = APIManager(session=self.session)

        # First create the API, then initialize the Flask applications after.
        manager1.create_api(self.Person)
        manager2.create_api(self.Article)
        manager1.init_app(self.flaskapp)
        manager2.init_app(self.flaskapp)

        # Tests that both endpoints are accessible on the Flask application.
        response = self.app.get('/api/person')
        assert response.status_code == 200
        response = self.app.get('/api/article')
        assert response.status_code == 200
Exemple #19
0
    def test_multiple_managers_init_single_app(self):
        """Tests for calling :meth:`~APIManager.init_app` on a single
        :class:`~flask.Flask` application after calling
        :meth:`~APIManager.create_api` on multiple instances of
        :class:`APIManager`.

        """
        manager1 = APIManager(session=self.session)
        manager2 = APIManager(session=self.session)

        # First create the API, then initialize the Flask applications after.
        manager1.create_api(self.Person)
        manager2.create_api(self.Article)
        manager1.init_app(self.flaskapp)
        manager2.init_app(self.flaskapp)

        # Tests that both endpoints are accessible on the Flask application.
        response = self.app.get('/api/person')
        assert response.status_code == 200
        response = self.app.get('/api/article')
        assert response.status_code == 200
def create_app():
    app = Flask(__name__)
    app.config.from_object('config')

    login_manager = LoginManager()

    api_manager = APIManager()
    api_manager.create_api(Race, methods=['GET'], include_columns=['start_time'])
    api_manager.create_api(Checkpoint, methods=['GET'])
    api_manager.create_api(User, methods=['GET'], include_columns=['username'])
    api_manager.create_api(Marker, methods=['GET', 'PATCH'])
    api_manager.create_api(CheckpointTime, collection_name='time',
                           methods=['GET', 'POST', 'PUT'],
                           preprocessors=dict(POST=[auth_func]))

    with app.app_context():
        login_manager.init_app(app)
        db.init_app(app)
        api_manager.init_app(app, flask_sqlalchemy_db=db)
        Bootstrap(app)

    return app
 def test_init_app_split_initialization(self):
     manager = APIManager(flask_sqlalchemy_db=self.db)
     manager.init_app(self.flaskapp)
     manager.create_api(self.Person, app=self.flaskapp)
     response = self.app.get('/api/person')
     assert response.status_code == 200
Exemple #22
0
 def test_init_app_split_initialization(self):
     manager = APIManager(flask_sqlalchemy_db=self.db)
     manager.init_app(self.flaskapp)
     manager.create_api(self.Person, app=self.flaskapp)
     response = self.app.get('/api/person')
     assert response.status_code == 200