refs #0 The root commit.
This commit is contained in:
75
back/core/test.py
Normal file
75
back/core/test.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from re import match
|
||||
from os.path import exists
|
||||
from unittest import TestCase, main
|
||||
from shutil import rmtree
|
||||
|
||||
from command import create_project
|
||||
|
||||
|
||||
def increment_name(full_name: str) -> str:
|
||||
name, index = match(
|
||||
pattern="^([a-z\d]+)(?:_(\d+))?", string=full_name.lower()
|
||||
).groups()
|
||||
|
||||
if not index:
|
||||
postfix = "_1"
|
||||
else:
|
||||
postfix = f"_{index+1}"
|
||||
|
||||
return name + postfix
|
||||
|
||||
|
||||
def get_temporary_directory_name() -> str:
|
||||
dir_name = "test"
|
||||
while exists("config/module/" + dir_name + "/"):
|
||||
dir_name = increment_name(dir_name)
|
||||
|
||||
return dir_name
|
||||
|
||||
|
||||
class TestCommandMethods(TestCase):
|
||||
def test_create_project_creates_project_directory(self: TestCase):
|
||||
directory = get_temporary_directory_name()
|
||||
create_project(directory)
|
||||
directory_exists = exists(f"config/module/{directory}/")
|
||||
rmtree(f"config/module/{directory}/")
|
||||
self.assertTrue(directory_exists)
|
||||
|
||||
def test_create_project_creates_init(self: TestCase):
|
||||
directory = get_temporary_directory_name()
|
||||
create_project(directory)
|
||||
file_exists = exists(f"config/module/{directory}/__init__.py")
|
||||
rmtree(f"config/module/{directory}/")
|
||||
self.assertTrue(file_exists)
|
||||
|
||||
def test_create_project_creates_config(self: TestCase):
|
||||
directory = get_temporary_directory_name()
|
||||
create_project(directory)
|
||||
file_exists = exists(f"config/module/{directory}/config.yaml")
|
||||
rmtree(f"config/module/{directory}/")
|
||||
self.assertTrue(file_exists)
|
||||
|
||||
def test_create_project_creates_create_schema(self: TestCase):
|
||||
directory = get_temporary_directory_name()
|
||||
create_project(directory)
|
||||
file_exists = exists(f"config/module/{directory}/create_schema.py")
|
||||
rmtree(f"config/module/{directory}/")
|
||||
self.assertTrue(file_exists)
|
||||
|
||||
def test_create_project_creates_model(self: TestCase):
|
||||
directory = get_temporary_directory_name()
|
||||
create_project(directory)
|
||||
file_exists = exists(f"config/module/{directory}/model.py")
|
||||
rmtree(f"config/module/{directory}/")
|
||||
self.assertTrue(file_exists)
|
||||
|
||||
def test_create_project_creates_schema(self: TestCase):
|
||||
directory = get_temporary_directory_name()
|
||||
create_project(directory)
|
||||
file_exists = exists(f"config/module/{directory}/schema.py")
|
||||
rmtree(f"config/module/{directory}/")
|
||||
self.assertTrue(file_exists)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user