| 728 | def test_version(self): |
| 729 | "--version is handled as a special case" |
| 730 | args = ['--version'] |
| 731 | out, err = self.run_manage(args) |
| 732 | self.assertNoOutput(err) |
| 733 | # Only check the first part of the version number |
| 734 | self.assertOutput(out, get_version().split('-')[0]) |
| 735 | |
| 736 | def test_help(self): |
| 737 | "--help is handled as a special case" |
| 738 | args = ['--help'] |
| 739 | out, err = self.run_manage(args) |
| 740 | self.assertOutput(out, "Usage: manage.py [options]") |
| 741 | self.assertOutput(err, "Type 'manage.py help <subcommand>' for help on a specific subcommand.") |
| 742 | |
| 743 | def test_specific_help(self): |
| 744 | "--help can be used on a specific command" |
| 745 | args = ['sqlall','--help'] |
| 746 | out, err = self.run_manage(args) |
| 747 | self.assertNoOutput(err) |
| 748 | self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).") |
| 749 | |
747 | | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel', 'anotherlabel'), options=[('pythonpath', None), ('settings', None), ('traceback', None)]") |
| 769 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel', 'anotherlabel'), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None)]") |
| 770 | |
| 771 | def test_base_command_with_option(self): |
| 772 | "User BaseCommands can execute with options when a label is provided" |
| 773 | args = ['base_command','testlabel','--option_a=x'] |
| 774 | out, err = self.run_manage(args) |
| 775 | self.assertNoOutput(err) |
| 776 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None)]") |
| 777 | |
| 778 | def test_base_command_with_options(self): |
| 779 | "User BaseCommands can execute with multiple options when a label is provided" |
| 780 | args = ['base_command','testlabel','-a','x','--option_b=y'] |
| 781 | out, err = self.run_manage(args) |
| 782 | self.assertNoOutput(err) |
| 783 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None)]") |
| 854 | |
| 855 | class ArgumentOrder(AdminScriptTestCase): |
| 856 | """Tests for 2-stage argument parsing scheme. |
| 857 | |
| 858 | django-admin command arguments are parsed in 2 parts; the core arguments |
| 859 | (--settings, --traceback and --pythonpath) are parsed using a Lax parser. |
| 860 | This Lax parser ignores any unknown options. Then the full settings are |
| 861 | passed to the command parser, which extracts commands of interest to the |
| 862 | individual command. |
| 863 | """ |
| 864 | def setUp(self): |
| 865 | self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes']) |
| 866 | self.write_settings('alternate_settings.py') |
| 867 | |
| 868 | def tearDown(self): |
| 869 | self.remove_settings('settings.py') |
| 870 | self.remove_settings('alternate_settings.py') |
| 871 | |
| 872 | def test_setting_then_option(self): |
| 873 | "Options passed after settings are correctly handled" |
| 874 | args = ['base_command','testlabel','--settings=alternate_settings','--option_a=x'] |
| 875 | out, err = self.run_manage(args) |
| 876 | self.assertNoOutput(err) |
| 877 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None)]") |
| 878 | |
| 879 | def test_setting_then_short_option(self): |
| 880 | "Short options passed after settings are correctly handled" |
| 881 | args = ['base_command','testlabel','--settings=alternate_settings','--option_a=x'] |
| 882 | out, err = self.run_manage(args) |
| 883 | self.assertNoOutput(err) |
| 884 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None)]") |
| 885 | |
| 886 | def test_option_then_setting(self): |
| 887 | "Options passed before settings are correctly handled" |
| 888 | args = ['base_command','testlabel','--option_a=x','--settings=alternate_settings'] |
| 889 | out, err = self.run_manage(args) |
| 890 | self.assertNoOutput(err) |
| 891 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None)]") |
| 892 | |
| 893 | def test_short_option_then_setting(self): |
| 894 | "Short options passed before settings are correctly handled" |
| 895 | args = ['base_command','testlabel','-a','x','--settings=alternate_settings'] |
| 896 | out, err = self.run_manage(args) |
| 897 | self.assertNoOutput(err) |
| 898 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None)]") |
| 899 | |
| 900 | def test_option_then_setting_then_option(self): |
| 901 | "Options are correctly handled when they are passed before and after a setting" |
| 902 | args = ['base_command','testlabel','--option_a=x','--settings=alternate_settings','--option_b=y'] |
| 903 | out, err = self.run_manage(args) |
| 904 | self.assertNoOutput(err) |
| 905 | self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None)]") |
| 906 | |