示例#1
0
    def test_testrun_persistent_path(self):
        try:
            import cms
        except ImportError:
            raise unittest.SkipTest("django CMS not available, skipping test")
        path = mkdtemp()
        with work_in(self.basedir):
            with captured_output() as (out, err):
                with self.assertRaises(SystemExit) as exit:
                    try:
                        from django.test.utils import _TestState

                        del _TestState.saved_data
                    except (ImportError, AttributeError):
                        pass
                    args = copy(DEFAULT_ARGS)
                    args["test"] = True
                    args["--persistent"] = True
                    args["--persistent-path"] = path
                    args["--runner"] = "runners.CapturedOutputRunner"
                    core(args, self.application)
        self.assertTrue("Ran 14 tests in" in err.getvalue())
        self.assertEqual(exit.exception.code, 0)
        self.assertTrue(args["STATIC_ROOT"].startswith(path))
        self.assertTrue(args["MEDIA_ROOT"].startswith(path))
        self.assertTrue(os.path.exists(args["STATIC_ROOT"]))
        self.assertTrue(os.path.exists(args["MEDIA_ROOT"]))
示例#2
0
 def setUpClass(cls):
     os.environ.setdefault("DATABASE_URL", "sqlite://localhost/:memory:")
     cls.basedir = os.path.abspath(os.path.join("app_helper", "test_utils"))
     cls.application = "example1"
     cls.application_2 = "example2"
     with work_in(cls.basedir):
         with captured_output():
             cls.migration_example = os.path.abspath(
                 os.path.join(cls.application, "data",
                              "django_0001_initial.py"))
             cls.migration_partial = os.path.abspath(
                 os.path.join(cls.application, "data",
                              "django_0001_partial.py"))
             cls.poexample = os.path.abspath(
                 os.path.join(cls.application, "data", "django.po"))
             cls.pofile = os.path.abspath(
                 os.path.join(cls.application, "locale", "en",
                              "LC_MESSAGES", "django.po"))
             cls.mofile = os.path.abspath(
                 os.path.join(cls.application, "locale", "en",
                              "LC_MESSAGES", "django.mo"))
             cls.migration_dir = os.path.abspath(
                 os.path.join(cls.application, "migrations"))
             cls.migration_dir_2 = os.path.abspath(
                 os.path.join(cls.application_2, "migrations"))
             cls.migration_file = os.path.abspath(
                 os.path.join(cls.application, "migrations",
                              "0001_initial.py"))
             cls.migration_file_2 = os.path.abspath(
                 os.path.join(cls.application_2, "migrations",
                              "0001_initial.py"))
     try:
         import cms
     except ImportError:
         DEFAULT_ARGS["--cms"] = False
示例#3
0
 def test_makemessages(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["makemessages"] = True
             core(args, self.application)
             self.assertTrue(os.path.exists(self.pofile))
示例#4
0
 def test_compilemessages(self):
     with work_in(self.basedir):
         shutil.copy(self.poexample, self.pofile)
         args = copy(DEFAULT_ARGS)
         args["compilemessages"] = True
         core(args, self.application)
         self.assertTrue(os.path.exists(self.mofile))
示例#5
0
 def test_server(self, mocked_command):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["server"] = True
             core(args, self.application)
         self.assertTrue(
             "A admin user (username: admin, password: admin) has been created."
             in out.getvalue())
示例#6
0
 def test_makemigrations_merge(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["makemigrations"] = True
             args["--merge"] = True
             core(args, self.application)
             self.assertTrue(
                 "No conflicts detected to merge" in out.getvalue())
示例#7
0
    def test_setup_nocms(self):
        with work_in(self.basedir):
            with captured_output() as (out, err):
                from app_helper.test_utils import helper

                settings = runner.setup("example1", helper, extra_args=[])
        self.assertTrue("example2" in settings.INSTALLED_APPS)
        self.assertFalse("aldryn_boilerplates" in settings.INSTALLED_APPS)
        self.assertFalse("cms" in settings.INSTALLED_APPS)
示例#8
0
 def test_authors(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["authors"] = True
             core(args, self.application)
     self.assertTrue("Generating AUTHORS" in out.getvalue())
     self.assertTrue("* Iacopo Spalletti" in out.getvalue())
     self.assertTrue("Authors (" in out.getvalue())
示例#9
0
 def skip_test_makemigrations_update(self):
     os.makedirs(self.migration_dir)
     open(os.path.join(self.migration_dir, "__init__.py"), "w")
     shutil.copy(self.migration_partial, self.migration_file)
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["makemigrations"] = True
             core(args, self.application)
     self.assertTrue("Migrations for 'example1':" in out.getvalue())
示例#10
0
 def test_any_command_check(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["<command>"] = "check"
             args["options"] = [
                 "helper", "check", "--extra-settings=cms_helper_extra.py"
             ]
             core(args, self.application)
     self.assertTrue("no issues" in out.getvalue())
示例#11
0
 def test_any_command_compilemessages(self):
     with work_in(os.path.join(self.basedir, self.application)):
         with captured_output() as (out, err):
             shutil.copy(self.poexample, self.pofile)
             args = copy(DEFAULT_ARGS)
             args["<command>"] = "compilemessages"
             args[
                 "options"] = "helper compilemessages --cms -len --verbosity=2".split(
                     " ")
             core(args, self.application)
             self.assertTrue(os.path.exists(self.mofile))
示例#12
0
 def test_makemigrations(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["makemigrations"] = True
             args["<extra-applications>"] = ["example2"]
             core(args, self.application)
         self.assertTrue(os.path.exists(self.migration_file))
         self.assertTrue(os.path.exists(self.migration_file_2))
     self.assertTrue("Create model ExampleModel1" in out.getvalue())
     self.assertTrue("Create model ExampleModel2" in out.getvalue())
示例#13
0
 def test_pyflakes(self):
     try:
         import cms
     except ImportError:
         raise unittest.SkipTest("django CMS not available, skipping test")
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["pyflakes"] = True
             core(args, self.application)
     self.assertFalse(os.path.exists(args["STATIC_ROOT"]))
     self.assertFalse(os.path.exists(args["MEDIA_ROOT"]))
示例#14
0
 def test_runner_nocms(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             with self.assertRaises(SystemExit) as exit:
                 args = list()
                 args.append("helper")
                 args.append("example1")
                 args.append("test")
                 args.append("--extra-settings=helper.py")
                 args.append("--runner=runners.CapturedOutputRunner")
                 runner.run("example1", args)
     self.assertTrue("Ran 14 tests in" in err.getvalue())
     self.assertEqual(exit.exception.code, 0)
示例#15
0
 def test_any_command_migrations(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             args = copy(DEFAULT_ARGS)
             args["<command>"] = "makemigrations"
             args[
                 "options"] = "helper makemigrations example2 --verbosity=2".split(
                     " ")
             core(args, self.application)
         self.assertFalse("Create model ExampleModel1" in out.getvalue())
         self.assertFalse(os.path.exists(self.migration_file))
         self.assertTrue("Create model ExampleModel2" in out.getvalue())
         self.assertTrue(os.path.exists(self.migration_file_2))
示例#16
0
    def test_runner_argv(self):
        def fake_runner(argv):
            return argv

        from app_helper.test_utils.runners import CapturedOutputRunner

        with patch("django.test.runner.DiscoverRunner", CapturedOutputRunner):
            with work_in(self.basedir):
                with captured_output() as (out, err):
                    args = list()
                    args.append("helper")
                    with patch("app_helper.runner.runner", fake_runner):
                        data = runner.run("example1", args)
                    self.assertEqual(data, ["helper", "example1", "test"])
示例#17
0
 def test_urls_nocms(self):
     try:
         from django.urls import reverse, NoReverseMatch
     except ImportError:
         from django.core.urlresolvers import reverse, NoReverseMatch
     with work_in(self.basedir):
         with captured_output() as (out, err):
             shutil.copy(self.poexample, self.pofile)
             args = copy(DEFAULT_ARGS)
             args["makemessages"] = True
             args["--cms"] = False
             core(args, self.application)
             with self.assertRaises(NoReverseMatch):
                 reverse("pages-root")
示例#18
0
    def test_cms_check_nocms_19(self):
        try:
            import cms

            raise unittest.SkipTest("django CMS available, skipping test")
        except ImportError:
            pass
        with work_in(self.basedir):
            with self.assertRaises(ImportError):
                shutil.copy(self.poexample, self.pofile)
                args = copy(DEFAULT_ARGS)
                args["cms_check"] = True
                args["--extra-settings"] = "helper.py"
                args["--migrate"] = False
                core(args, self.application)
示例#19
0
    def test_runner_cms_exception(self):
        try:
            import cms

            raise unittest.SkipTest("django CMS available, skipping test")
        except ImportError:
            pass
        from app_helper.test_utils.runners import CapturedOutputRunner

        with patch("django.test.runner.DiscoverRunner", CapturedOutputRunner):
            with work_in(self.basedir):
                with captured_output() as (out, err):
                    with self.assertRaises(ImportError) as exit:
                        args = list()
                        args.append("helper")
                        runner.cms("example1", args)
示例#20
0
 def test_cms_check(self):
     try:
         import cms
     except ImportError:
         raise unittest.SkipTest("django CMS not available, skipping test")
     with work_in(self.basedir):
         with captured_output() as (out, err):
             shutil.copy(self.poexample, self.pofile)
             args = copy(DEFAULT_ARGS)
             args["cms_check"] = True
             args["--extra-settings"] = "helper.py"
             args["--migrate"] = False
             core(args, self.application)
         self.assertTrue("Installation okay" in out.getvalue())
         self.assertFalse("[WARNING]" in out.getvalue())
         self.assertFalse("[ERROR]" in out.getvalue())
示例#21
0
 def test_urls(self):
     try:
         import cms
     except ImportError:
         raise unittest.SkipTest("django CMS not available, skipping test")
     try:
         from django.urls import reverse
     except ImportError:
         from django.core.urlresolvers import reverse
     with work_in(self.basedir):
         with captured_output() as (out, err):
             shutil.copy(self.poexample, self.pofile)
             args = copy(DEFAULT_ARGS)
             args["makemessages"] = True
             core(args, self.application)
             self.assertTrue(reverse("pages-root"))
示例#22
0
 def test_runner_pytest(self):
     with work_in(self.basedir):
         with captured_output() as (out, err):
             with self.assertRaises(SystemExit) as exit:
                 args = list()
                 args.append("helper_no_cms")
                 args.append("example1")
                 args.append("test")
                 args.append("--extra-settings=helper_no_cms.py")
                 args.append(
                     "--runner=app_helper.pytest_runner.PytestTestRunner")
                 runner.run("example1", args)
     self.assertTrue("collected 15 items" in out.getvalue())
     # warnings will depend on django version and adds too much noise
     self.assertTrue("10 passed, 5 skipped" in out.getvalue())
     self.assertEqual(exit.exception.code, 0)
示例#23
0
    def test_setup_cms(self):
        try:
            import cms
        except ImportError:
            raise unittest.SkipTest("django CMS not available, skipping test")
        with work_in(self.basedir):
            with captured_output() as (out, err):
                from app_helper.test_utils import helper

                settings = runner.setup("example1",
                                        helper,
                                        use_cms=True,
                                        extra_args=["--boilerplate"])
        self.assertTrue("example2" in settings.INSTALLED_APPS)
        self.assertTrue("aldryn_boilerplates" in settings.INSTALLED_APPS)
        self.assertTrue("cms" in settings.INSTALLED_APPS)
示例#24
0
    def test_testrun_nocms(self):
        with work_in(self.basedir):
            with captured_output() as (out, err):
                with self.assertRaises(SystemExit) as exit:
                    try:
                        from django.test.utils import _TestState

                        del _TestState.saved_data
                    except (ImportError, AttributeError):
                        pass
                    args = copy(DEFAULT_ARGS)
                    args["test"] = True
                    args["--cms"] = False
                    args["--runner"] = "runners.CapturedOutputRunner"
                    core(args, self.application)
        self.assertTrue("Ran 14 tests in" in err.getvalue())
        self.assertEqual(exit.exception.code, 0)
示例#25
0
    def test_pyflakes_nocms(self):
        try:
            import cms

            raise unittest.SkipTest("django CMS available, skipping test")
        except ImportError:
            pass
        with work_in(self.basedir):
            with captured_output() as (out, err):
                args = copy(DEFAULT_ARGS)
                args["pyflakes"] = True
                core(args, self.application)
            self.assertTrue(
                "Static analysis available only if django CMS and pyflakes are installed"
                in out.getvalue())
        self.assertFalse(os.path.exists(args["STATIC_ROOT"]))
        self.assertFalse(os.path.exists(args["MEDIA_ROOT"]))
示例#26
0
    def test_cms_check_nocms(self):
        try:
            import cms

            raise unittest.SkipTest("django CMS available, skipping test")
        except ImportError:
            pass
        with work_in(self.basedir):
            with captured_output() as (out, err):
                shutil.copy(self.poexample, self.pofile)
                args = copy(DEFAULT_ARGS)
                args["cms_check"] = True
                args["--extra-settings"] = "helper.py"
                args["--migrate"] = False
                core(args, self.application)
            self.assertTrue(
                "cms_check available only if django CMS is installed" in
                out.getvalue())
示例#27
0
    def test_setup_custom_user(self):
        os.environ["AUTH_USER_MODEL"] = "custom_user.CustomUser"
        try:
            import cms
        except ImportError:
            raise unittest.SkipTest("django CMS not available, skipping test")
        with work_in(self.basedir):
            with captured_output() as (out, err):
                from app_helper.test_utils import cms_helper_custom

                settings = runner.setup("example1",
                                        cms_helper_custom,
                                        use_cms=True,
                                        extra_args=["--boilerplate"])
        self.assertTrue("example2" in settings.INSTALLED_APPS)
        self.assertTrue("custom_user" in settings.INSTALLED_APPS)
        self.assertTrue("aldryn_boilerplates" in settings.INSTALLED_APPS)
        self.assertTrue("cms" in settings.INSTALLED_APPS)
        del os.environ["AUTH_USER_MODEL"]
示例#28
0
    def test_runner_cms_argv(self):
        try:
            import cms
        except ImportError:
            raise unittest.SkipTest("django CMS not available, skipping test")

        def fake_runner(argv):
            return argv

        from app_helper.test_utils.runners import CapturedOutputRunner

        with patch("django.test.runner.DiscoverRunner", CapturedOutputRunner):
            with work_in(self.basedir):
                with captured_output() as (out, err):
                    args = list()
                    args.append("helper")
                    with patch("app_helper.runner.runner", fake_runner):
                        data = runner.cms("example1", args)
                    self.assertEqual(data,
                                     ["helper", "example1", "test", "--cms"])
示例#29
0
    def test_testrun_native(self):
        try:
            import cms
        except ImportError:
            raise unittest.SkipTest("django CMS not available, skipping test")
        with work_in(self.basedir):
            with captured_output() as (out, err):
                try:
                    from django.test.utils import _TestState

                    del _TestState.saved_data
                except (ImportError, AttributeError):
                    pass
                args = copy(DEFAULT_ARGS)
                args["<command>"] = "test"
                args["--cms"] = False
                args["--native"] = True
                args["--extra-settings"] = "cms_helper_extra_runner.py"
                core(args, self.application)
        self.assertTrue("Ran 14 tests in" in err.getvalue())
示例#30
0
    def test_runner_compat(self):
        try:
            import cms
        except ImportError:
            raise unittest.SkipTest("django CMS not available, skipping test")
        from app_helper.test_utils.runners import CapturedOutputRunner

        with patch("django.test.runner.DiscoverRunner", CapturedOutputRunner):
            with work_in(self.basedir):
                with captured_output() as (out, err):
                    with self.assertRaises(SystemExit) as exit:
                        args = list()
                        args.append("cms_helper")
                        args.append("test")
                        args.append("example1")
                        runner.cms("example1", args)
        self.assertTrue("visible string" in out.getvalue())
        self.assertFalse("hidden string" in out.getvalue())
        self.assertFalse("hidden string" in err.getvalue())
        self.assertTrue("Ran 14 tests in" in err.getvalue())
        self.assertEqual(exit.exception.code, 0)