Ejemplo n.º 1
0
    def test_unittest_main(self) -> None:
        """
        Tests whether `unittest_main` is called when `__name__ == '__main__'`
        """
        self.assertEqual(type(unittest_main).__name__, "function")
        self.assertIsNone(unittest_main())
        argparse_mock = MagicMock()
        with patch("cdd.tests.utils_for_tests.__name__", "__main__"), patch(
                "sys.stderr",
                new_callable=StringIO), self.assertRaises(SystemExit) as e:
            import cdd.tests.utils_for_tests

            cdd.tests.utils_for_tests.unittest_main()

        self.assertIsInstance(e.exception.code, bool)
        self.assertIsNone(argparse_mock.call_args)
        self.assertIsNone(cdd.tests.utils_for_tests.unittest_main())
Ejemplo n.º 2
0
            output=
            "the following arguments are required: --crud, --model-path, --model-name, --routes-path\n",
        )

    def test_gen_routes(self) -> None:
        """Tests CLI interface gets all the way to the gen_routes call without error"""

        with patch("cdd.__main__.gen_routes", lambda *args, **kwargs:
                   (True, ) * 2), patch("cdd.__main__.upsert_routes",
                                        mock_function):
            self.assertTrue(
                run_cli_test(
                    self,
                    [
                        "gen_routes",
                        "--crud",
                        "CRD",
                        "--model-path",
                        "cdd.tests.mocks.sqlalchemy",
                        "--routes-path",
                        "/api/config",
                        "--model-name",
                        "Config",
                    ],
                    exit_code=None,
                    output=None,
                ), )


unittest_main()