def setUp(self):
        self.app = bookshelf.create_app(
            config,
            testing=True,
            config_overrides={
                'DATA_BACKEND': self.backend
            }
        )

        with self.app.app_context():
            self.model = bookshelf.get_model()

        self.ids_to_delete = []

        # Monkey-patch create so we can track the IDs of every item
        # created and delete them during tearDown.
        self.original_create = self.model.create

        def tracking_create(*args, **kwargs):
            res = self.original_create(*args, **kwargs)
            self.ids_to_delete.append(res['id'])
            return res

        self.model.create = tracking_create

        # Monkey-patch get_books_queue to prevents pubsub events
        # from firing
        self.original_get_books_queue = tasks.get_books_queue
        tasks.get_books_queue = mock.Mock()
示例#2
0
    def setUp(self):
        # Define Test Variables and init. app

        self.app = create_app()
        self.client = self.app.test_client
        self.database_name = "bookshelf_test"
        self.database_path = "postgresql://{}:{}@{}/{}".format(
            "postgres", "posgtres_me", "localhost:5432", self.database_name)
        setup_db(self.app, self.database_path)

        self.new_book = {
            "title": "test title",
            "author": "test author",
            "rating": 5
        }

        def tearDown(self):
            # Execute afte each test
            pass

        def test_get_paginated_books(self):
            res = self.client.get('/books')
            data = json.loads(res.data)

            self.assertEqual(res.status_code, 200)
            self.assertEqual(data['success'], True)
            self.assertEqual(data['total_books'])
            self.assertEqual(len(data['books']))

        def test_404_requesting_beyond_valid_page():
            res = self.client.get('/books?page=1000', json={'rating': 1})
            data = json.loads(res.data)
            self.assertEqual(res.status_code, 404)
            self.assertEqual(data['success'], False)
            self.assertEqual(data['message'], 'resource not found')
示例#3
0
    def setUp(self):
        self.app = bookshelf.create_app(
            config,
            testing=True,
            config_overrides={'DATA_BACKEND': self.backend})

        with self.app.app_context():
            self.model = bookshelf.get_model()

        self.ids_to_delete = []

        # Monkey-patch create so we can track the IDs of every item
        # created and delete them during tearDown.
        self.original_create = self.model.create

        def tracking_create(*args, **kwargs):
            res = self.original_create(*args, **kwargs)
            self.ids_to_delete.append(res['id'])
            return res

        self.model.create = tracking_create

        # Monkey-patch get_books_queue to prevents pubsub events
        # from firing
        self.original_get_books_queue = tasks.get_books_queue
        tasks.get_books_queue = mock.Mock()
示例#4
0
def app(request):
    """This fixtures provides a Flask app instance configured for testing.
    Because it's parametric, it will cause every test that uses this fixture
    to run three times: one time for each backend (datastore, cloudsql, and
    mongodb).
    It also ensures the tests run within a request context, allowing
    any calls to flask.request, flask.current_app, etc. to work."""
    app = bookshelf.create_app(
        config, testing=True, config_overrides={'DATA_BACKEND': request.param})

    with app.test_request_context():
        yield app
    def setUp(self):
        # Define Test Variables and init. app
        self.app = create_app()
        self.client = self.app.test_client()
        self.database_name = "bookshelf_test"
        self.database_path = "postgresql://{}:{}@{}/{}".format(
            "postgres", "postgres_me", "localhost:5432", self.database_name)
        setup_db(self.app, self.database_path)

        self.new_book = {
            "title": "test title",
            "author": "test author",
            "rating": 5
        }
def app(request):
    """This fixtures provides a Flask app instance configured for testing.

    Because it's parametric, it will cause every test that uses this fixture
    to run three times: one time for each backend (datastore, cloudsql, and
    mongodb).

    It also ensures the tests run within a request context, allowing
    any calls to flask.request, flask.current_app, etc. to work."""
    app = bookshelf.create_app(
        config,
        testing=True,
        config_overrides={
            'DATA_BACKEND': request.param
        })

    with app.test_request_context():
        yield app
示例#7
0
import bookshelf
import config

app = bookshelf.create_app(config)

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)
示例#8
0
def app():
    app = bookshelf.create_app(config)
    return app
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import bookshelf
import config

application = bookshelf.create_app(config)

# This is only used when running locally. When running live, gunicorn runs
# the application.
if __name__ == '__main__':
    application.run(host='0.0.0.0', port=8080, debug=False)
示例#10
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import bookshelf
import config


app = bookshelf.create_app(config)


# Make the queue available at the top-level, this allows you to run
# `psqworker main.books_queue`. We have to use the app's context because
# it contains all the configuration for plugins.
# If you were using another task queue, such as celery or rq, you can use this
# section to configure your queues to work with Flask.
with app.app_context():
    books_queue = bookshelf.tasks.get_books_queue()


# This is only used when running locally. When running live, gunicorn runs
# the application.
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)
示例#11
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import bookshelf
import config


# Note: debug=True is enabled here to help with troubleshooting. You should
# remove this in production.
app = bookshelf.create_app(config, debug=True)


# Make the queue available at the top-level, this allows you to run
# `psqworker main.books_queue`. We have to use the app's context because
# it contains all the configuration for plugins.
# If you were using another task queue, such as celery or rq, you can use this
# section to configure your queues to work with Flask.
with app.app_context():
    books_queue = bookshelf.tasks.get_books_queue()


# This is only used when running locally. When running live, gunicorn runs
# the application.
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)
示例#12
0
from bookshelf import create_app

app = create_app()

if __name__ == '__main__':
    app.run(debug=True)

示例#13
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import bookshelf
import config

# Note: debug=True is enabled here to help with troubleshooting. You should
# remove this in production.
app = bookshelf.create_app(config, debug=False)

# Make the queue available at the top-level, this allows you to run
# `psqworker main.books_queue`. We have to use the app's context because
# it contains all the configuration for plugins.
# If you were using another task queue, such as celery or rq, you can use this
# section to configure your queues to work with Flask.
with app.app_context():
    books_queue = bookshelf.tasks.get_books_queue()

# This is only used when running locally. When running live, gunicorn runs
# the application.
if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)
示例#14
0
import bookshelf
import config


# Note: debug=True is enabled here to help with troubleshooting. You should
# remove this in production.
app = bookshelf.create_app(config, debug=True)


# Make the queue available at the top-level, this allows you to run
# `psqworker main.books_queue`. We have to use the app's context because
# it contains all the configuration for plugins.
# If you were using another task queue, such as celery or rq, you can use this
# section to configure your queues to work with Flask.
with app.app_context():
    books_queue = bookshelf.tasks.get_books_queue()


# This is only used when running locally. When running live, gunicorn runs
# the application.
if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)