Пример #1
0
    def test_parse_args(self):
        # The key is the arg line, the value is a triple. First properties and
        # values of the opts, second the django_opts, last any positional args
        # that are passed through to Django.
        data = {
            "--admin -d sqlite:///example.db -a app1 --extra=1 test": (
                {"admin": True, "database": "sqlite:///example.db", "apps": [("app1", "")]},
                {"EXTRA": 1},
                ["test"],
            ),
            "-a app1 --app app2:foo --installed-apps ['bar'] test": (
                {"admin": False, "database": "sqlite:///:memory:", "apps": [("app1", ""), ("app2", "foo")]},
                {"INSTALLED_APPS": ["bar"]},
                ["test"],
            ),
            "syncdb --noinput --database=DATABASE": (
                {"admin": False, "database": "sqlite:///:memory:", "apps": []},
                {},
                ["syncdb", "--noinput", "--database=DATABASE"],
            ),
            "--database=sqlite:///:memory: --foo bar test": (
                {"admin": False, "database": "sqlite:///:memory:", "apps": []},
                {"FOO": "bar"},
                ["test"],
            ),
        }

        for line, expected in data.items():
            opts, django_opts, args = djangomini.parse_args(line.split(" "))

            for key, expected_value in expected[0].items():
                self.assertEqual(getattr(opts, key), expected_value)
            self.assertEqual(django_opts, expected[1])
            self.assertEqual(args, expected[2])
Пример #2
0
    def test_default_args(self):
        opts, django_opts, args = djangomini.parse_args(["test"])

        expected = {
            "admin": False,
            "persisting": False,
            "apps": [],
            "database": "sqlite:///:memory:",
            "debug_toolbar": False,
        }

        for option, value in expected.items():
            self.assertEqual(getattr(opts, option), value)