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
3
Example 1
def test_with_default_commands(self):
manager = Manager(self.app)
assert 'runserver' in manager._commands
assert 'shell' in manager._commands
3
Example 2
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
3
Example 3
def test_add_command(self):
manager = Manager(self.app)
manager.add_command("simple", SimpleCommand())
assert isinstance(manager._commands['simple'], SimpleCommand)
3
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()
3
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()
3
Example 6
def test_get_usage(self):
manager = Manager(self.app)
manager.add_command("simple", SimpleCommand())
assert "simple simple command" in manager.get_usage()
3
Example 7
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
3
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()
3
Example 9
def test_run_non_existant_command(self):
manager = Manager(self.app)
self.assertRaises(InvalidCommand,
manager.handle,
"manage.py", "simple")
3
Example 10
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()
3
Example 11
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()
3
Example 12
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()
3
Example 13
def test_run_no_name(self):
manager = Manager(self.app)
sys.argv = ["manage.py"]
try:
manager.run()
except SystemExit, e:
assert e.code == 0
3
Example 14
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()
3
Example 15
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()
3
Example 16
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()
3
Example 17
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
3
Example 18
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()
0
Example 19
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()
0
Example 20
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()
0
Example 21
Project: Flask-Script Source File: tests.py
Function: test_simple_command_decorator_with_pos_arg_and_options
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()
0
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()
0
Example 23
def test_init_with_flask_instance(self):
manager = Manager(self.app)
assert callable(manager.app)
0
Example 24
def test_init_with_callable(self):
manager = Manager(lambda: app)
assert callable(manager.app)