示例#1
0
    def create_app(self):
        app = Flask(__name__, static_folder=None)

        Watchman(app, environment={})

        app.config.setdefault('APP_LOGGING', 'MY LOGGING')

        return app
示例#2
0
def create_app(**config):
    """
    Create the application and return it to the user
    :return: application
    """

    if config:
        app = ADSFlask(__name__, static_folder=None, local_config=config)
    else:
        app = ADSFlask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    load_s3(app)

    # Register extensions
    watchman = Watchman(app, version=dict(scopes=['']))
    api = Api(app)
    Discoverer(app)

    # Add the end resource end points
    api.add_resource(AuthenticateUserClassic, '/auth/classic', methods=['POST'])
    api.add_resource(AuthenticateUserTwoPointOh, '/auth/twopointoh', methods=['POST'])

    api.add_resource(
        ClassicLibraries,
        '/libraries/classic/<int:uid>',
        methods=['GET']
    )
    api.add_resource(
        TwoPointOhLibraries,
        '/libraries/twopointoh/<int:uid>',
        methods=['GET']
    )

    api.add_resource(
        ExportTwoPointOhLibraries,
        '/export/twopointoh/<export>',
        methods=['GET']
    )

    api.add_resource(
        ClassicMyADS,
        '/myads/classic/<int:uid>',
        methods=['GET']
    )

    api.add_resource(ClassicUser, '/user', methods=['GET'])
    api.add_resource(AllowedMirrors, '/mirrors', methods=['GET'])

    return app
示例#3
0
    def test_no_scopes(self):
        """
        Check the behaviour when no scopes are requested at all
        """

        app = Flask(__name__, static_folder=None)

        with self.assertRaises(AttributeError):
            getattr(Environment, 'scopes')
            getattr(Environment, 'rate_limit')
            getattr(Environment, 'decorators')

        Watchman(app)

        with self.assertRaises(AttributeError):
            getattr(Environment, 'scopes')
            getattr(Environment, 'decorators')
            getattr(Environment, 'rate_limit')
示例#4
0
    def test_adding_scopes_to_routes(self):
        """
        Check the behaviour when scopes are specified
        """

        app = Flask(__name__, static_folder=None)

        environment = {
            'scopes': ['adsws:internal'],
        }

        with self.assertRaises(AttributeError):
            getattr(Environment, 'scopes')
            getattr(Environment, 'rate_limit')
            getattr(Environment, 'decorators')

        Watchman(app, environment=environment)

        self.assertEqual(Environment.scopes, ['adsws:internal'])
        self.assertIsInstance(Environment.decorators, list)
        self.assertIsInstance(Environment.rate_limit, list)
示例#5
0
    def test_empty_scopes(self):
        """
        Check the behaviour when empty scopes are requested
        """

        app = Flask(__name__, static_folder=None)

        environment = {
            'scopes': [],
        }

        with self.assertRaises(AttributeError):
            getattr(Environment, 'scopes')
            getattr(Environment, 'rate_limit')
            print getattr(Environment, 'decorators')

        Watchman(app, environment=environment)

        self.assertEqual(Environment.scopes, [])
        self.assertIsInstance(Environment.decorators, list)
        self.assertIsInstance(Environment.rate_limit, list)