|
6 | 6 |
|
7 | 7 | from flask import Flask
|
8 | 8 | from flask.ext.script._compat import StringIO, text_type
|
9 |
| -from flask.ext.script import Command, Manager, Option, prompt, prompt_bool |
| 9 | +from flask.ext.script import Command, Manager, Option, prompt, prompt_bool, prompt_choices |
10 | 10 |
|
11 | 11 | from pytest import raises
|
12 | 12 |
|
@@ -689,7 +689,52 @@ def correct_n(msg):
|
689 | 689 | code = run('manage.py hello', manager.run)
|
690 | 690 | out, err = capsys.readouterr()
|
691 | 691 | assert 'correct [y]: no' in out
|
| 692 | + |
| 693 | + def test_command_with_prompt_choices(self, capsys): |
692 | 694 |
|
| 695 | + manager = Manager(self.app) |
| 696 | + |
| 697 | + @manager.command |
| 698 | + def hello(): |
| 699 | + print(prompt_choices(name='hello', choices=['peter', 'john', 'sam'])) |
| 700 | + |
| 701 | + @Catcher |
| 702 | + def hello_john(msg): |
| 703 | + if re.search("hello", msg): |
| 704 | + return 'john' |
| 705 | + |
| 706 | + with hello_john: |
| 707 | + code = run('manage.py hello', manager.run) |
| 708 | + out, err = capsys.readouterr() |
| 709 | + assert 'hello - (peter, john, sam): john' in out |
| 710 | + |
| 711 | + def test_command_with_default_prompt_choices(self, capsys): |
| 712 | + |
| 713 | + manager = Manager(self.app) |
| 714 | + |
| 715 | + @manager.command |
| 716 | + def hello(): |
| 717 | + print(prompt_choices(name='hello', choices=['peter', 'charlie', 'sam'], default="john")) |
| 718 | + |
| 719 | + @Catcher |
| 720 | + def hello_john(msg): |
| 721 | + if re.search("hello", msg): |
| 722 | + return '\n' |
| 723 | + |
| 724 | + with hello_john: |
| 725 | + code = run('manage.py hello', manager.run) |
| 726 | + out, err = capsys.readouterr() |
| 727 | + assert 'hello - (peter, charlie, sam) [john]: john' in out |
| 728 | + |
| 729 | + @Catcher |
| 730 | + def hello_charlie(msg): |
| 731 | + if re.search("hello", msg): |
| 732 | + return 'charlie' |
| 733 | + |
| 734 | + with hello_charlie: |
| 735 | + code = run('manage.py hello', manager.run) |
| 736 | + out, err = capsys.readouterr() |
| 737 | + assert 'hello - (peter, charlie, sam) [john]: charlie' in out |
693 | 738 |
|
694 | 739 | class TestSubManager:
|
695 | 740 |
|
|
0 commit comments