def test_save_method_saves_the_version_type_to_the_database(self): """testing if the save method saves the current VersionType to the database """ self.kwargs["name"] = "Test Animation" self.kwargs["code"] = "TA" new_vtype = VersionType(**self.kwargs) new_vtype.save() code = new_vtype.code environments = new_vtype.environments filename = new_vtype.filename name = new_vtype.name output_path = new_vtype.output_path path = new_vtype.path type_for = new_vtype.type_for # del new_vtype new_vtypeDB = VersionType.query().\ filter_by(name=self.kwargs["name"]).first() self.assertEqual(code, new_vtypeDB.code) self.assertEqual(filename, new_vtypeDB.filename) self.assertEqual(name, new_vtypeDB.name) self.assertEqual(output_path, new_vtypeDB.output_path) self.assertEqual(path, new_vtypeDB.path) self.assertEqual(type_for, new_vtypeDB.type_for) self.assertEqual(environments, new_vtypeDB.environments)
def test_extra_folders_argument_is_None(self): """testing if the extra_folders attribute is going to be an empty string when the extra folders argument is given as None """ self.kwargs["extra_folders"] = None new_version_type = VersionType(**self.kwargs) self.assertEqual(new_version_type.extra_folders, "")
def test_extra_folders_argument_is_skipped(self): """testing if the extra_folders argument is skipped the extra_folders attribute will be an empty string """ self.kwargs.pop("extra_folders") new_version_type = VersionType(**self.kwargs) self.assertEqual(new_version_type.extra_folders, "")
def test_name_attribute_is_not_unique(self): """testing if an IntegrityError error will be raised when the name argument is not unique """ # creating a new VersionType should raise the ?? error new_vtype = VersionType(**self.kwargs) self.assertRaises(IntegrityError, new_vtype.save)
def test_code_attribute_is_not_unique(self): """testing if an IntegrityError error will be raised when the code argument is not unique """ # creating a new VersionType should raise the IntegrityError self.kwargs["name"] = "A Different Name" new_vtype = VersionType(**self.kwargs) self.assertRaises(IntegrityError, new_vtype.save)
def test_type_for_argument_is_working_properly(self): """testing if the type_for argument is working properly """ self.kwargs["name"] = "Test Animation" self.kwargs["code"] = "TA" self.kwargs["type_for"] = "Asset" new_vtype = VersionType(**self.kwargs) new_vtype.save() self.assertEqual(new_vtype.type_for, "Asset")
def test_environments_argument_works_properly(self): """testing if the environments attribute will be initialized correctly with the environments argument """ test_value = ["MAYA", "HOUDINI"] self.kwargs["environments"] = test_value new_vtype = VersionType(**self.kwargs) for env in test_value: self.assertTrue(env in new_vtype.environments)
def test__ne__(self): """testing the equality operator """ verst1 = VersionType(name="Test Type", code="TT", path="path", filename="filename", output_path="output_path", environments=["MAYA", "NUKE"], type_for="Asset") verst2 = VersionType(name="Test Type", code="TT", path="path", filename="filename", output_path="output_path", environments=["MAYA", "NUKE"], type_for="Asset") verst3 = VersionType(name="Test Type 2", code="TT", path="path", filename="filename", output_path="output_path", environments=["MAYA", "NUKE"], type_for="Asset") verst4 = VersionType(name="Test Type 3", code="TT3", path="path", filename="filename", output_path="output_path", environments=["MAYA", "NUKE"], type_for="Asset") self.assertFalse(verst1 != verst2) self.assertTrue(verst1 != verst3) self.assertTrue(verst3 != verst4)
def __init_db__(): """initializes the just setup database It adds: - Users - VersionTypes to the database. """ logger.debug("db is newly created, initializing the db") global query global session # get the users from the config from oyProjectManager import conf # ------------------------------------------------------ # create the users from oyProjectManager.models.auth import User # get all users from db users_from_db = query(User).all() for user_data in conf.users_data: name = user_data.get("name") initials = user_data.get("initials") email = user_data.get("email") user_from_config = User(name, initials, email) if user_from_config not in users_from_db: session.add(user_from_config) # ------------------------------------------------------ # add the VersionTypes from oyProjectManager.models.version import VersionType version_types_from_db = query(VersionType).all() for version_type in conf.version_types: version_type_from_conf = VersionType(**version_type) if version_type_from_conf not in version_types_from_db: session.add(version_type_from_conf) session.commit() logger.debug("finished initialization of the db")
def setUp(self): """setup the test settings with environment variables """ # ----------------------------------------------------------------- # start of the setUp conf.database_url = "sqlite://" # create the environment variable and point it to a temp directory self.temp_config_folder = tempfile.mkdtemp() self.temp_projects_folder = tempfile.mkdtemp() os.environ["OYPROJECTMANAGER_PATH"] = self.temp_config_folder os.environ[conf.repository_env_key] = self.temp_projects_folder self.test_project = Project("TEST_PROJ1") self.test_project.create() self.test_project.save() self.kwargs = { # "project": self.test_project, "name": "Test VType", "code": "TVT", "path": "{{project.full_path}}/Sequences/{{sequence.code}}/SHOTS/{{version.base_name}}/{{type.code}}", "filename": "{{version.base_name}}_{{version.take_name}}_{{type.code}}_v{{'%03d'|format(version.version_number)}}_{{version.created_by.initials}}", "environments": ["MAYA", "HOUDINI"], "output_path": "SHOTS/{{version.base_name}}/{{type.code}}/OUTPUT/{{version.take_name}}", "extra_folders": """{{version.path}}/exports {{version.path}}/cache """, "type_for": "Shot" } self.test_versionType = VersionType(**self.kwargs) self.test_versionType.save() self._name_test_values = [ ("base name", "Base_Name"), ("123123 base_name", "Base_Name"), ("123432!+!'^+Base_NAme323^+'^%&+%&324", "Base_NAme323324"), (" ---base 9s_name", "Base_9s_Name"), (" ---base 9s-name", "Base_9s_Name"), (" multiple spaces are converted to under scores", "Multiple_Spaces_Are_Converted_To_Under_Scores"), ("camelCase", "CamelCase"), ("CamelCase", "CamelCase"), ("_Project_Setup_", "Project_Setup"), ("_PROJECT_SETUP_", "PROJECT_SETUP"), ("FUL_3D", "FUL_3D"), ("BaseName", "BaseName"), ("baseName", "BaseName"), (" baseName", "BaseName"), (" base name", "Base_Name"), (" 12base name", "Base_Name"), (" 12 base name", "Base_Name"), (" 12 base name 13", "Base_Name_13"), (">£#>$#£½$ 12 base £#$£#$£½¾{½{ name 13", "Base_Name_13"), ("_base_name_", "Base_Name"), ]