]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Add additional test cases 574/head
authorAviskar KC <aviskarkc10@gmail.com>
Thu, 4 Jul 2019 15:29:50 +0000 (21:14 +0545)
committerAviskar KC <aviskarkc10@gmail.com>
Thu, 4 Jul 2019 15:29:50 +0000 (21:14 +0545)
tests/test_command.py

index 933d7c8d88ecc94c931d1489d6b508e6ef98a0f3..5153312531f40d8ed1e0a557b34797d4300dbf05 100644 (file)
@@ -2,6 +2,7 @@ from contextlib import contextmanager
 import inspect
 from io import BytesIO
 from io import TextIOWrapper
+import os
 import re
 
 from sqlalchemy import exc as sqla_exc
@@ -811,3 +812,80 @@ class CommandLineTest(TestBase):
                 self.cfg,
                 directory=directory,
             )
+
+    def test_init_file_exists_and_is_empty(self):
+        def access_(path, mode):
+            if "generic" in path or path == "foobar":
+                return True
+            else:
+                return False
+
+        def listdir_(path):
+            if path == "foobar":
+                return []
+            else:
+                return ["file1", "file2", "alembic.ini.mako"]
+
+        template_dir = self.cfg.get_template_directory()
+
+        with mock.patch(
+            "alembic.command.os.access", side_effect=access_
+        ) as access, mock.patch(
+            "alembic.command.os.makedirs"
+        ) as makedirs, mock.patch(
+            "alembic.command.os.listdir", side_effect=listdir_
+        ) as listdir, mock.patch(
+            "alembic.command.ScriptDirectory"
+        ):
+            command.init(self.cfg, directory="foobar")
+            eq_(
+                access.mock_calls,
+                [
+                    mock.call("foobar", os.F_OK),
+                    mock.call(os.path.join(template_dir, "generic"), os.F_OK),
+                    mock.call("foobar", os.F_OK),
+                    mock.call(
+                        os.path.abspath("./scratch/test_alembic.ini"), os.F_OK
+                    ),
+                ],
+            )
+            eq_(
+                listdir.mock_calls,
+                [
+                    mock.call("foobar"),
+                    mock.call(os.path.join(template_dir, "generic")),
+                ],
+            )
+            eq_(makedirs.mock_calls, [mock.call("foobar/versions")])
+
+    def test_init_file_doesnt_exist(self):
+        def access_(path, mode):
+            if "generic" in path:
+                return True
+            else:
+                return False
+
+        template_dir = self.cfg.get_template_directory()
+        with mock.patch(
+            "alembic.command.os.access", side_effect=access_
+        ) as access, mock.patch(
+            "alembic.command.os.makedirs"
+        ) as makedirs, mock.patch(
+            "alembic.command.ScriptDirectory"
+        ):
+            command.init(self.cfg, directory="foobar")
+            eq_(
+                access.mock_calls,
+                [
+                    mock.call("foobar", os.F_OK),
+                    mock.call(os.path.join(template_dir, "generic"), os.F_OK),
+                    mock.call("foobar", os.F_OK),
+                    mock.call(
+                        os.path.abspath("./scratch/test_alembic.ini"), os.F_OK
+                    ),
+                ],
+            )
+            eq_(
+                makedirs.mock_calls,
+                [mock.call("foobar"), mock.call("foobar/versions")],
+            )