flaskext.script.Manager

Here are the examples of the python api flaskext.script.Manager taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

24 Examples 7

Example 1

Project: Flask-Script Source File: tests.py
Function: test_with_default_commands
    def test_with_default_commands(self):

        manager = Manager(self.app)

        assert 'runserver' in manager._commands
        assert 'shell' in manager._commands

Example 2

Project: Flask-Script Source File: tests.py
Function: test_without_default_commands
    def test_without_default_commands(self):

        manager = Manager(self.app, with_default_commands=False)

        assert 'runserver' not in manager._commands
        assert 'shell' not in manager._commands

Example 3

Project: Flask-Script Source File: tests.py
Function: test_add_command
    def test_add_command(self):

        manager = Manager(self.app)
        manager.add_command("simple", SimpleCommand())
        
        assert isinstance(manager._commands['simple'], SimpleCommand)

Example 4

Project: Flask-Script Source File: tests.py
    def test_simple_command_decorator(self):

        manager = Manager(self.app)
        
        @manager.command
        def hello():
            print "hello"

        assert 'hello' in manager._commands

        manager.handle("manage.py", "hello")
        assert 'hello' in sys.stdout.getvalue()

Example 5

Project: Flask-Script Source File: tests.py
    def test_simple_command_decorator_with_pos_arg(self):

        manager = Manager(self.app)
        
        @manager.command
        def hello(name):
            print "hello", name
        

        assert 'hello' in manager._commands

        manager.handle("manage.py", "hello", ["joe"])
        assert 'hello joe' in sys.stdout.getvalue()

Example 6

Project: Flask-Script Source File: tests.py
Function: test_get_usage
    def test_get_usage(self):

        manager = Manager(self.app)
        manager.add_command("simple", SimpleCommand())

        assert "simple     simple command" in manager.get_usage()

Example 7

Project: Flask-Script Source File: tests.py
Function: test_get_usage_with_specified_usage
    def test_get_usage_with_specified_usage(self):

        manager = Manager(self.app, usage="hello")
        manager.add_command("simple", SimpleCommand())

        usage = manager.get_usage()
        assert "simple     simple command" in usage
        assert "hello" in usage

Example 8

Project: Flask-Script Source File: tests.py
    def test_run_existing_command(self):
        
        manager = Manager(self.app)
        manager.add_command("simple", SimpleCommand())
        manager.handle("manage.py", "simple")
        assert 'OK' in sys.stdout.getvalue()

Example 9

Project: Flask-Script Source File: tests.py
Function: test_run_non_existant_command
    def test_run_non_existant_command(self):

        manager = Manager(self.app)
        self.assertRaises(InvalidCommand, 
                           manager.handle,
                           "manage.py", "simple")

Example 10

Project: Flask-Script Source File: tests.py
Function: test_run_existing
    def test_run_existing(self):

        manager = Manager(self.app)
        manager.add_command("simple", SimpleCommand())
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0
        assert 'OK' in sys.stdout.getvalue()

Example 11

Project: Flask-Script Source File: tests.py
Function: test_run_existing_bind_later
    def test_run_existing_bind_later(self):

        manager = Manager(self.app)
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run({'simple':SimpleCommand()})
        except SystemExit, e:
            assert e.code == 0
        assert 'OK' in sys.stdout.getvalue()

Example 12

Project: Flask-Script Source File: tests.py
Function: test_run_not_existing
    def test_run_not_existing(self):

        manager = Manager(self.app)
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 1
        assert 'OK' not in sys.stdout.getvalue()

Example 13

Project: Flask-Script Source File: tests.py
Function: test_run_no_name
    def test_run_no_name(self):

        manager = Manager(self.app)
        sys.argv = ["manage.py"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0

Example 14

Project: Flask-Script Source File: tests.py
Function: test_run_good_options
    def test_run_good_options(self):

        manager = Manager(self.app)
        manager.add_command("simple", CommandWithOptions())
        sys.argv = ["manage.py", "simple", "--name=Joe"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0
        assert "Joe" in sys.stdout.getvalue()

Example 15

Project: Flask-Script Source File: tests.py
Function: test_run_dynamic_options
    def test_run_dynamic_options(self):

        manager = Manager(self.app)
        manager.add_command("simple", CommandWithDynamicOptions('Fred'))
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0
        assert "Fred" in sys.stdout.getvalue()

Example 16

Project: Flask-Script Source File: tests.py
Function: test_run_catch_all
    def test_run_catch_all(self):
        manager = Manager(self.app)
        manager.add_command("catch", CommandWithCatchAll())
        sys.argv = ["manage.py", "catch", "pos1", "--foo", "pos2", "--bar"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0
        assert "['pos1', 'pos2', '--bar']" in sys.stdout.getvalue()

Example 17

Project: Flask-Script Source File: tests.py
Function: test_run_bad_options
    def test_run_bad_options(self):

        manager = Manager(self.app)
        manager.add_command("simple", CommandWithOptions())
        sys.argv = ["manage.py", "simple", "--foo=bar"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 2

Example 18

Project: Flask-Script Source File: tests.py
Function: test_run_with_default_command
    def test_run_with_default_command(self):
        manager = Manager(self.app)
        manager.add_command('simple', SimpleCommand())
        try:
            manager.run(default_command='simple')
        except SystemExit, e:
            assert e.code==0
        assert 'OK' in sys.stdout.getvalue()

Example 19

Project: Flask-Script Source File: tests.py
Function: test_command_decorator_with_options
    def test_command_decorator_with_options(self):

        manager = Manager(self.app)
        
        @manager.command
        def hello(name='fred'):
            "Prints your name"
            print "hello", name

        assert 'hello' in manager._commands

        manager.handle("manage.py", "hello", ["--name=joe"])
        assert 'hello joe' in sys.stdout.getvalue()

        manager.handle("manage.py", "hello", ["-n joe"])
        assert 'hello joe' in sys.stdout.getvalue()

        try:
            manager.handle("manage.py", "hello", ["-h"])
        except SystemExit:
            pass
        assert 'Prints your name' in sys.stdout.getvalue()

        try:
            manager.handle("manage.py", "hello", ["--help"])
        except SystemExit:
            pass
        assert 'Prints your name' in sys.stdout.getvalue()

Example 20

Project: Flask-Script Source File: tests.py
Function: test_command_decorator_with_boolean_options
    def test_command_decorator_with_boolean_options(self):

        manager = Manager(self.app)
        
        @manager.command
        def verify(verified=False):
            "Checks if verified"
            print "VERIFIED ?", "YES" if verified else "NO"

        assert 'verify' in manager._commands

        manager.handle("manage.py", "verify", ["--verified"])
        assert 'YES' in sys.stdout.getvalue()

        manager.handle("manage.py", "verify", ["-v"])
        assert 'YES' in sys.stdout.getvalue()

        manager.handle("manage.py", "verify", [])
        assert 'NO' in sys.stdout.getvalue()

        try:
            manager.handle("manage.py", "verify", ["-h"])
        except SystemExit:
            pass
        assert 'Checks if verified' in sys.stdout.getvalue()

Example 21

Project: Flask-Script Source File: tests.py
Function: test_simple_command_decorator_with_pos_arg_and_options
    def test_simple_command_decorator_with_pos_arg_and_options(self):

        manager = Manager(self.app)
        
        @manager.command
        def hello(name, url=None):
            if url:
                assert type(url) is unicode
                print "hello", name, "from", url
            else:
                assert type(name) is unicode
                print "hello", name
        
        assert 'hello' in manager._commands

        manager.handle("manage.py", "hello", ["joe"])
        assert 'hello joe' in sys.stdout.getvalue()

        manager.handle("manage.py", "hello", ["joe", '--url=reddit.com'])
        assert 'hello joe from reddit.com' in sys.stdout.getvalue()

Example 22

Project: Flask-Script Source File: tests.py
    def test_command_decorator_with_additional_options(self):

        manager = Manager(self.app)
        
        @manager.option('-n', '--name', dest='name', help='Your name')
        def hello(name):
            print "hello", name

        assert 'hello' in manager._commands

        manager.handle("manage.py", "hello", ["--name=joe"])
        assert 'hello joe' in sys.stdout.getvalue()

        try:
            manager.handle("manage.py", "hello", ["-h"])
        except SystemExit:
            pass
        assert "Your name" in sys.stdout.getvalue()

        @manager.option('-n', '--name', dest='name', help='Your name')
        @manager.option('-u', '--url', dest='url', help='Your URL')
        def hello_again(name, url=None):
            if url:
                print "hello", name, "from", url
            else:
                print "hello", name

        assert 'hello_again' in manager._commands

        manager.handle("manage.py", "hello_again", ["--name=joe"])
        assert 'hello joe' in sys.stdout.getvalue()

        manager.handle("manage.py", "hello_again", 
            ["--name=joe", "--url=reddit.com"])
        assert 'hello joe from reddit.com' in sys.stdout.getvalue()

Example 23

Project: Flask-Script Source File: tests.py
Function: test_init_with_flask_instance
    def test_init_with_flask_instance(self):
        
        manager = Manager(self.app)
        assert callable(manager.app)

Example 24

Project: Flask-Script Source File: tests.py
Function: test_init_with_callable
    def test_init_with_callable(self):

        manager = Manager(lambda: app)
        assert callable(manager.app)