Example #1
0
    def test_is_called_with_app_context(self):
        app = self.generate_app()

        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = self.generate_blueprints()
            helpers.setup_blueprints(app, ['foo', 'bar'])

        self.assertEqual(1, app.app_context.call_count)
    def test_is_called_with_app_context(self):
        app = self.generate_app()

        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = self.generate_blueprints()
            helpers.setup_blueprints(app, ['foo', 'bar'])

        self.assertEqual(1, app.app_context.call_count)
    def test_can_handle_simple_strings_inside_iterables_as_well(self):
        app = self.generate_app()
        foo = stub_blueprint('foo')
        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [foo, ]
            blueprints = [
                ['foo', ],
            ]
            helpers.setup_blueprints(app, blueprints=blueprints)

        app.register_blueprint.assert_has_calls([mock.call('foo')])
Example #4
0
    def test_can_handle_args_only(self):
        app = self.generate_app()
        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [
                stub_blueprint('foo'),
            ]
            blueprints = [['foo', ('arg1', 'arg2')]]
            helpers.setup_blueprints(app, blueprints=blueprints)

        app.register_blueprint.assert_has_calls(
            [mock.call('foo', 'arg1', 'arg2')])
    def test_imports_each_blueprint(self):
        b1, b2 = self.generate_blueprints()
        app = self.generate_app()

        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [b1, b2]
            helpers.setup_blueprints(app, ['blueprint.one', 'blueprint.two'])

        import_string.assert_has_calls([
            mock.call('blueprint.one'),
            mock.call('blueprint.two'),
        ])
    def test_can_handle_args_only(self):
        app = self.generate_app()
        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [stub_blueprint('foo'), ]
            blueprints = [
                ['foo', ('arg1', 'arg2')]
            ]
            helpers.setup_blueprints(app, blueprints=blueprints)

        app.register_blueprint.assert_has_calls([
            mock.call('foo', 'arg1', 'arg2')
        ])
    def test_adds_args_and_kwargs_if_not_simple_string(self):
        app = self.generate_app()
        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [stub_blueprint('foo'), ]
            blueprints = [
                ['foo', ('arg1', 'arg2'), {'kwarg1': 'foo', 'kwarg2': 'bar'}],
            ]
            helpers.setup_blueprints(app, blueprints=blueprints)

        app.register_blueprint.assert_has_calls([
            mock.call('foo', 'arg1', 'arg2', kwarg1='foo', kwarg2='bar')
        ])
Example #8
0
    def test_imports_each_blueprint(self):
        b1, b2 = self.generate_blueprints()
        app = self.generate_app()

        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [b1, b2]
            helpers.setup_blueprints(app, ['blueprint.one', 'blueprint.two'])

        import_string.assert_has_calls([
            mock.call('blueprint.one'),
            mock.call('blueprint.two'),
        ])
    def test_register_each_blueprint(self):
        b1, b2 = self.generate_blueprints()
        app = self.generate_app()

        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [b1, b2]
            helpers.setup_blueprints(app, ['foo', 'bar'])

        self.assert_(app.register_blueprint.called, msg='sanity check')
        self.assertEqual(2, app.register_blueprint.call_count)
        app.register_blueprint.assert_has_calls([
            mock.call(b1.blueprint),
            mock.call(b2.blueprint),
        ])
Example #10
0
    def test_register_each_blueprint(self):
        b1, b2 = self.generate_blueprints()
        app = self.generate_app()

        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [b1, b2]
            helpers.setup_blueprints(app, ['foo', 'bar'])

        self.assert_(app.register_blueprint.called, msg='sanity check')
        self.assertEqual(2, app.register_blueprint.call_count)
        app.register_blueprint.assert_has_calls([
            mock.call(b1.blueprint),
            mock.call(b2.blueprint),
        ])
Example #11
0
    def test_can_handle_simple_strings_inside_iterables_as_well(self):
        app = self.generate_app()
        foo = stub_blueprint('foo')
        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [
                foo,
            ]
            blueprints = [
                [
                    'foo',
                ],
            ]
            helpers.setup_blueprints(app, blueprints=blueprints)

        app.register_blueprint.assert_has_calls([mock.call('foo')])
Example #12
0
    def test_adds_args_and_kwargs_if_not_simple_string(self):
        app = self.generate_app()
        with mock.patch.object(helpers, 'import_string') as import_string:
            import_string.side_effect = [
                stub_blueprint('foo'),
            ]
            blueprints = [
                ['foo', ('arg1', 'arg2'), {
                    'kwarg1': 'foo',
                    'kwarg2': 'bar'
                }],
            ]
            helpers.setup_blueprints(app, blueprints=blueprints)

        app.register_blueprint.assert_has_calls(
            [mock.call('foo', 'arg1', 'arg2', kwarg1='foo', kwarg2='bar')])
 def test_does_nothing_with_no_blueprints(self):
     helpers.setup_blueprints(self.generate_server(), None)
Example #14
0
 def test_does_nothing_with_no_blueprints(self):
     helpers.setup_blueprints(self.generate_server(), None)