Esempio n. 1
0
    def setUp(self):
        self.app = Flask('UnitTest')
        self.micron = Micron(self.app)

        self.appctx = self.app.app_context()
        self.appctx.push()

        self.reqctx = self.app.test_request_context()
        self.reqctx.push()

        self.client = self.app.test_client()
Esempio n. 2
0
    def test_SettingsArePassedToDecoratedMethods(self):
        app = Flask('TestApp')
        micron = Micron(app, option1='y', option2='z')
        micron.plugin(ConfigSpy())

        @micron.method()
        def f():
            pass

        response = micron.app.test_client().post('/f')
        config = json.loads(response.data)

        self.assertEqual({'option1': 'y', 'option2': 'z'}, config)
Esempio n. 3
0
    def test_DecoratorCanOnlyBeUsedWhenFlaskAppIsLinkedToMicron(self):
        micron = Micron()
        with self.assertRaises(ImplementationError):

            @micron.method()
            def f():
                pass
Esempio n. 4
0
 def test_AutoloadedPlugins(self):
     autoloaded_plugins = Micron().plugins
     self.assertEqual(4, len(autoloaded_plugins))
     self.assertTrue(json_input.Plugin in autoloaded_plugins)
     self.assertTrue(normalize_input.Plugin in autoloaded_plugins)
     self.assertTrue(call_function.Plugin in autoloaded_plugins)
     self.assertTrue(json_output.Plugin in autoloaded_plugins)
Esempio n. 5
0
class MicronTestCase(unittest.TestCase):

    def setUp(self):
        self.app = Flask('UnitTest')
        self.micron = Micron(self.app)

        self.appctx = self.app.app_context()
        self.appctx.push()

        self.reqctx = self.app.test_request_context()
        self.reqctx.push()

        self.client = self.app.test_client()

    def tearDown(self):
        self.reqctx.pop()
        self.appctx.pop()

    def decorate(self, function, rule=None, **configuration):
        decorate = self.micron.method(rule, **configuration)
        return decorate(function)

    def plugin(self, plugin_object):
        self.micron.plugins.add(plugin_object);

    def editable_session(self):
        return self.client.session_transaction()

    def request(self, path, funcarg=None, **kvargs):
        response = self.client.post(path, data=json.dumps(funcarg), **kvargs)
        response.output = json.loads(response.data)

        return response
Esempio n. 6
0
    def test_SettingsCanBeOverriddenInDecorator(self):
        app = Flask('TestApp')
        micron = Micron(app, option1='x', option2='y', option3='z')
        micron.plugin(ConfigSpy())

        @micron.method(option1='b', option2=None)
        def f():
            pass

        response = micron.app.test_client().post('/f')
        config = json.loads(response.data)

        self.assertEqual({
            'option1': 'b',
            'option2': None,
            'option3': 'z'
        }, config)
Esempio n. 7
0
from flask import Flask
from flask_micron import Micron

app = Flask(__name__)
micron = Micron(app)


@micron.method()
def hello_world(name='World'):
    return 'Hello, %s!' % name


if __name__ == '__main__':
    app.run(port=8888)