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)
Beispiel #2
0
    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_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")
Beispiel #4
0
 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")
Beispiel #5
0
 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, "")
Beispiel #6
0
 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, "")
Beispiel #7
0
    def test_assets_tableWidget_horizontal_labels_are_set_properly(self):
        """testing if the assets_tableWidget horizontal labels are filled with
        all the possible VersionTypes for assets
        """

        db.setup()

        asset_vtypes = VersionType.query()\
            .filter(VersionType.type_for=='Asset')\
            .order_by(VersionType.name)\
            .all()

        dialog = status_manager.MainDialog()
        #        self.show_dialog(dialog)

        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(0).text(),
            'Thumbnail')

        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(1).text(), 'Type')

        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(2).text(), 'Name')

        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(3).text(), 'Take')

        self.assertEqual(dialog.assets_tableWidget.columnCount(),
                         len(asset_vtypes) + 4)

        for i, vtype in enumerate(asset_vtypes):
            self.assertEqual(
                dialog.assets_tableWidget.horizontalHeaderItem(i + 4).text(),
                vtype.code)
Beispiel #8
0
 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 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"),
        ]
Beispiel #10
0
    def setUp(self):
        """setup the tests
        """
        # -----------------------------------------------------------------
        # start of the setUp
        # create the environment variable and point it to a temp directory
        conf.database_url = "sqlite://"
        
        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
        
        # create a test project
        self.project = Project("Test Project")
        self.project.create()

        # create a test asset
        self.asset1 = Asset(self.project, "Test Asset 1")

        # version type
        self.asset_vtypes = VersionType.query()\
            .filter(VersionType.type_for == "Asset").all()
        
        self.shot_vtypes = VersionType.query()\
            .filter(VersionType.type_for == "Shot").all()

        self.user1 = User(name="Test User 1", email="*****@*****.**")

        # create a test version
        self.kwargs = {
            "version_of":self.asset1,
            "base_name":self.asset1.code,
            "type":self.asset_vtypes[0],
            "created_by":self.user1,
            "extension":"ma"
        }
        
        self.version1 = Version(**self.kwargs)
        self.version1.save()
        
        # create the environment instance
        self.mEnv = mayaEnv.Maya()

        # just renew the scene
        pm.newFile(force=True)
Beispiel #11
0
    def setUp(self):
        """setup the tests
        """
        # -----------------------------------------------------------------
        # start of the setUp
        # create the environment variable and point it to a temp directory
        conf.database_url = "sqlite://"

        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

        # create a test project
        self.project = Project("Test Project")
        self.project.create()

        # create a test asset
        self.asset1 = Asset(self.project, "Test Asset 1")

        # version type
        self.asset_vtypes = VersionType.query()\
            .filter(VersionType.type_for == "Asset").all()

        self.shot_vtypes = VersionType.query()\
            .filter(VersionType.type_for == "Shot").all()

        self.user1 = User(name="Test User 1", email="*****@*****.**")

        # create a test version
        self.kwargs = {
            "version_of": self.asset1,
            "base_name": self.asset1.code,
            "type": self.asset_vtypes[0],
            "created_by": self.user1,
            "extension": "ma"
        }

        self.version1 = Version(**self.kwargs)
        self.version1.save()

        # create the environment instance
        self.mEnv = mayaEnv.Maya()

        # just renew the scene
        pm.newFile(force=True)
Beispiel #12
0
 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)
Beispiel #13
0
    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)
Beispiel #14
0
    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)
Beispiel #15
0
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 test_assets_tableWidget_horizontal_labels_are_set_properly(self):
        """testing if the assets_tableWidget horizontal labels are filled with
        all the possible VersionTypes for assets
        """
        
        db.setup()
        
        asset_vtypes = VersionType.query()\
            .filter(VersionType.type_for=='Asset')\
            .order_by(VersionType.name)\
            .all()
        
        dialog = status_manager.MainDialog()
#        self.show_dialog(dialog)
        
        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(0).text(),
            'Thumbnail'
        )
        
        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(1).text(),
            'Type'
        )
        
        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(2).text(),
            'Name'
        )
        
        self.assertEqual(
            dialog.assets_tableWidget.horizontalHeaderItem(3).text(),
            'Take'
        )
        
        self.assertEqual(
            dialog.assets_tableWidget.columnCount(),
            len(asset_vtypes) + 4
        )
        
        for i, vtype in enumerate(asset_vtypes):
            self.assertEqual(
                dialog.assets_tableWidget.horizontalHeaderItem(i + 4).text(),
                vtype.code
            )
class VersionTypeTester(unittest.TestCase):
    """tests the VersionType class
    """

    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"),
        ]

    def tearDown(self):
        """cleanup the test
        """
        # set the db.session to None
        db.session = None

        # delete the temp folder
        shutil.rmtree(self.temp_config_folder)
        shutil.rmtree(self.temp_projects_folder)

    def test_name_argument_is_None(self):
        """testing if a TypeError will be raised when the name argument is
        None
        """
        self.kwargs["name"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_name_attribute_is_None(self):
        """testing if a TypeError will be raised when the name attribute is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "name", None)

    def test_name_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the name argument is not
        a string or unicode instance
        """
        self.kwargs["name"] = 123
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_name_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the name argument is not
        a string or unicode instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "name", 8)

    def test_name_argument_is_working_properly(self):
        """testing if the name argument is working properly and sets the name
        attribute correctly
        """
        self.assertEqual(self.kwargs["name"], self.test_versionType.name)

    def test_name_attribute_is_working_properly(self):
        """testing if the name attribute is working properly
        """
        test_value = "New Name"
        self.test_versionType.name = test_value
        self.assertEqual(test_value, self.test_versionType.name)

    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_argument_is_skipped(self):
        """testing if a TypeError will be raised when the code argument is
        skipped
        """
        self.kwargs.pop("code")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_code_argument_is_None(self):
        """testing if a TypeError will be raised when the code argument is
        None
        """
        self.kwargs["code"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_code_attribute_is_None(self):
        """testing if a TypeError will be raised when the code attribute is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "code", None)

    def test_code_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the code argument is not
        a string or unicode instance
        """
        self.kwargs["code"] = 123
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_code_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the code argument is not
        a string or unicode instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "code", 8)

    def test_code_argument_is_working_properly(self):
        """testing if the code argument is working properly and sets the code
        attribute correctly
        """
        self.assertEqual(self.kwargs["code"], self.test_versionType.code)

    def test_code_attribute_is_working_properly(self):
        """testing if the code attribute is working properly
        """
        test_value = "New Name"
        self.test_versionType.code = test_value
        self.assertEqual(test_value, self.test_versionType.code)

    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_filename_argument_is_skipped(self):
        """testing if a TypeError will be raised when the filename argument
        is skipped
        """
        self.kwargs.pop("filename")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_filename_argument_is_empty_string(self):
        """testing if a ValueError will be raised when the filename argument
        is an empty string
        """
        self.kwargs["filename"] = ""
        self.assertRaises(ValueError, VersionType, **self.kwargs)

    def test_filename_attribute_is_empty_string(self):
        """testing if a ValueError will be raised when the filename attribute
        is set to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_versionType, "filename", "")

    def test_filename_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the filename argument is
        not a string instance
        """
        self.kwargs["filename"] = 13245
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_filename_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the filename attribute is
        not a string instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "filename", 23412)

    def test_filename_argument_is_working_properly(self):
        """testing if the filename attribute is initialized correctly with the
        same value of the filename argument
        """
        self.assertEqual(self.test_versionType.filename, self.kwargs["filename"])

    def test_filename_attribute_is_working_properly(self):
        """testing if the filename attribute is working properly
        """
        test_value = "test_filename"
        self.test_versionType.filename = test_value
        self.assertEqual(self.test_versionType.filename, test_value)

    def test_path_argument_is_skipped(self):
        """testing if a TypeError will be raised when the path argument
        is skipped
        """
        self.kwargs.pop("path")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_path_argument_is_empty_string(self):
        """testing if a ValueError will be raised when the path argument
        is an empty string
        """
        self.kwargs["path"] = ""
        self.assertRaises(ValueError, VersionType, **self.kwargs)

    def test_path_attribute_is_empty_string(self):
        """testing if a ValueError will be raised when the path attribute
        is set to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_versionType, "path", "")

    def test_path_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the path argument is
        not a string instance
        """
        self.kwargs["path"] = 13245
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_path_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the path attribute is
        not a string instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "path", 23412)

    def test_path_argument_is_working_properly(self):
        """testing if the path attribute is initialized correctly with the
        same value of the path argument
        """
        self.assertEqual(self.test_versionType.path, self.kwargs["path"])

    def test_path_attribute_is_working_properly(self):
        """testing if the path attribute is working properly
        """
        test_value = "test_path"
        self.test_versionType.path = test_value
        self.assertEqual(self.test_versionType.path, test_value)

    def test_output_path_argument_is_skipped(self):
        """testing if a TypeError will be raised when the output_path
        argument is skipped
        """
        self.kwargs.pop("output_path")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_output_path_argument_is_empty_string(self):
        """testing if a ValueError will be raised when the output_path
        argument is an empty string
        """
        self.kwargs["output_path"] = ""
        self.assertRaises(ValueError, VersionType, **self.kwargs)

    def test_output_path_attribute_is_empty_string(self):
        """testing if a ValueError will be raised when the output_path
        attribute is set to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_versionType, "output_path", "")

    def test_output_path_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the output_path argument
        is not a string instance
        """
        self.kwargs["output_path"] = 13245
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_output_path_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the output_path attribute
        is not a string instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "output_path", 23412)

    def test_output_path_argument_is_working_properly(self):
        """testing if the output_path attribute is initialized correctly with
        the same value of the output_path argument
        """
        self.assertEqual(self.test_versionType.output_path, self.kwargs["output_path"])

    def test_output_path_attribute_is_working_properly(self):
        """testing if the output_path attribute is working properly
        """
        test_value = "test_output_path"
        self.test_versionType.output_path = test_value
        self.assertEqual(self.test_versionType.output_path, test_value)

    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_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_attribute_is_None(self):
        """testing if the extra_folders attribute will be an empty list when it
        is set to None
        """
        self.test_versionType.extra_folders = None
        self.assertEqual(self.test_versionType.extra_folders, "")

    def test_extra_folders_argument_is_not_a_string_instance(self):
        """testing if a TypeError will be raised when the extra_folders
        argument is not a string or unicode instance
        """
        self.kwargs["extra_folders"] = 123
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_extra_folders_attribute_is_not_a_string_instance(self):
        """testing if a TypeError will be raised when the extra_folders
        attribute is set to something other than a string or unicode instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "extra_folders", 23423)

    def test_extra_folders_argument_is_working_properly(self):
        """testing if the extra_folders attribute will be set to the same value
        with the extra_folders argument while initialization
        """
        self.assertEqual(self.test_versionType.extra_folders, self.kwargs["extra_folders"])

    def test_extra_folders_attribute_is_working_properly(self):
        """testing if the extra_folders attribute is working properly
        """
        test_value = "extra_folders"
        self.test_versionType.extra_folders = test_value
        self.assertEqual(self.test_versionType.extra_folders, test_value)

    def test_environments_argument_is_skipped(self):
        """testing if a TypeError will be raised when the environments
        argument is skipped
        """
        self.kwargs.pop("environments")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_argument_is_None(self):
        """testing if a TypeError will be raised when the environments
        argument is None
        """
        self.kwargs["environments"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_attribute_is_None(self):
        """testing if a TypeError will be raised when the environments
        attribute is set to None
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "environments", None)

    def test_environments_argument_is_not_a_list(self):
        """testing if a TypeError will be raised when the environments argument
        is not a list instance
        """
        self.kwargs["environments"] = 12354
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_attribute_is_not_a_list(self):
        """testing if a TypeError will be raised when the environments
        attribute is set to something other than a list
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "environments", 123)

    def test_environments_argument_is_not_a_list_of_strings(self):
        """testing if a TypeError will be raised when the environments argument
        is not a list of strings
        """
        self.kwargs["environments"] = [123, "MAYA"]
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_attribute_is_not_a_list_of_strings(self):
        """testing if a TypeError will be raised when the environments
        attribute is not a list of strings
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "environments", [123, "MAYA"])

    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_environments_attribute_works_properly(self):
        """testing if the environments attribute is working properly
        """
        test_value = ["MAYA", "HOUDINI", "NUKE", "3DEQUALIZER"]
        self.test_versionType.environments = test_value

        for env in test_value:
            self.assertTrue(env in self.test_versionType.environments)

    def test_type_for_argument_is_skipped(self):
        """testing if a TypeError will be raised when the type_for argument is
        skipped
        """
        self.kwargs.pop("type_for")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_type_for_argument_is_None(self):
        """testing if a TypeError will be raised when the type_for argument
        is None
        """
        self.kwargs["type_for"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_type_for_argument_is_not_a_string_or_integer(self):
        """testing if a TypeError will be raised when the type_for argument is
        not a string or unicode or an integer
        """
        self.kwargs["type_for"] = [12]
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    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_type_for_attribute_is_read_only(self):
        """testing if type_for attribute is read-only
        """
        self.assertRaises(AttributeError, setattr, self.test_versionType, "type_for", "Asset")

    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__eq__(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.assertTrue(verst1 == verst2)
        self.assertFalse(verst1 == verst3)
        self.assertFalse(verst3 == verst4)

    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)
Beispiel #18
0
    def test_shots_tableWidget_is_filled_with_Shot_data(self):
        """testing if the shots_tableWidget is filled with shot data properly
        """
        db.setup()

        # create a project
        proj1 = Project('Test Project 1')
        proj1.save()

        proj2 = Project('Test Project 2')
        proj2.save()

        shot_vtypes = VersionType.query()\
            .filter(VersionType.type_for=='Shot')\
            .order_by(VersionType.name)\
            .all()

        admin = User.query().first()

        # seqs for proj1
        seq1 = Sequence(proj1, 'Test Seq 1')
        seq1.save()

        seq2 = Sequence(proj1, 'Test Seq 2')
        seq2.save()

        # seqs for proj2
        seq3 = Sequence(proj2, 'Test Seq 3')
        seq3.save()

        seq4 = Sequence(proj2, 'Test Seq 4')
        seq4.save()

        # shots for seq1
        shot1 = Shot(seq1, 1)
        shot1.save()

        shot2 = Shot(seq1, 2)
        shot2.save()

        shot3 = Shot(seq1, 3)
        shot3.save()

        # shots for seq2
        shot4 = Shot(seq2, 4)
        shot4.save()

        shot5 = Shot(seq2, 5)
        shot5.save()

        shot6 = Shot(seq2, 6)
        shot6.save()

        # shots for seq3
        shot7 = Shot(seq3, 7)
        shot7.save()

        shot8 = Shot(seq3, 8)
        shot8.save()

        # shots for seq4
        shot9 = Shot(seq4, 9)
        shot9.save()

        shot10 = Shot(seq4, 10)
        shot10.save()

        # versions for shot1
        version1 = Version(version_of=shot1,
                           base_name=shot1.code,
                           type=shot_vtypes[0],
                           created_by=admin,
                           status=conf.status_list[0])
        version1.save()

        version2 = Version(version_of=shot1,
                           base_name=shot1.code,
                           type=shot_vtypes[1],
                           created_by=admin,
                           status=conf.status_list[1])
        version2.save()

        # versions for shot2
        version3 = Version(version_of=shot2,
                           base_name=shot2.code,
                           type=shot_vtypes[2],
                           created_by=admin,
                           status=conf.status_list[2])
        version3.save()

        version4 = Version(
            version_of=shot2,
            base_name=shot2.code,
            type=shot_vtypes[3],
            created_by=admin,
            status=conf.status_list[3],
        )
        version4.save()

        # versions for shot3
        version5 = Version(
            version_of=shot3,
            base_name=shot3.code,
            type=shot_vtypes[4],
            created_by=admin,
            status=conf.status_list[4],
        )
        version5.save()

        version6 = Version(
            version_of=shot3,
            base_name=shot3.code,
            type=shot_vtypes[5],
            created_by=admin,
            status=conf.status_list[4],
        )
        version6.save()

        # versions for shot4
        version7 = Version(version_of=shot4,
                           base_name=shot4.code,
                           type=shot_vtypes[5],
                           created_by=admin,
                           status=conf.status_list[4])
        version7.save()

        version8 = Version(version_of=shot4,
                           base_name=shot4.code,
                           type=shot_vtypes[5],
                           created_by=admin,
                           status=conf.status_list[0])
        version8.save()

        dialog = status_manager.MainDialog()
        #        self.show_dialog(dialog)

        # start tests

        # set the project to project1
        dialog.projects_comboBox.setCurrentIndex(0)

        #self.show_dialog(dialog)

        # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3]
        self.fail('test is not finished yet!')
Beispiel #19
0
    def test_assets_tableWidget_is_filled_with_Asset_data(self):
        """testing if the assets_tableWidget is filled with asset data properly
        """

        db.setup()

        # create a project
        proj1 = Project('Test Project 1')
        proj1.save()

        proj2 = Project('Test Project 2')
        proj2.save()

        asset_vtypes = VersionType.query()\
            .filter(VersionType.type_for=='Asset')\
            .order_by(VersionType.name)\
            .all()

        admin = User.query().first()

        asset1 = Asset(proj1, 'Test Asset 1', type='Char')
        asset1.save()

        asset2 = Asset(proj1, 'Test Asset 2', type='Prop')
        asset2.save()

        asset3 = Asset(proj1, 'Test Asset 3', type='Environment')
        asset3.save()

        asset4 = Asset(proj1, 'Test Asset 4', type='Prop')
        asset4.save()

        # versions for asset1
        version1 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=asset_vtypes[0],
                           created_by=admin,
                           status=conf.status_list[0])
        version1.save()

        version2 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=asset_vtypes[1],
                           created_by=admin,
                           status=conf.status_list[1])
        version2.save()

        version3 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=asset_vtypes[2],
                           created_by=admin,
                           status=conf.status_list[2])
        version3.save()

        # version for asset1 with different takes
        version4 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=asset_vtypes[3],
                           created_by=admin,
                           status=conf.status_list[3],
                           take_name='Test_A')
        version4.save()

        version5 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=asset_vtypes[4],
                           created_by=admin,
                           status=conf.status_list[4],
                           take_name='Test_A')
        version5.save()

        version6 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=asset_vtypes[5],
                           created_by=admin,
                           status=conf.status_list[4],
                           take_name='Test_B')
        version6.save()

        version7 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=asset_vtypes[5],
                           created_by=admin,
                           status=conf.status_list[4],
                           take_name='Test_B')
        version7.save()

        dialog = status_manager.MainDialog()
        #        self.show_dialog(dialog)

        # start tests

        # What we should see shoul be:
        #
        # +-----------+-------------+--------------+--------+---------------------+
        # | Thumbnail | Type        |     Name     |  Take  | Asset Version Types |
        # +===========+=============+==============+========+=====================+
        # |  (IMAGE)  | Char        | Test Asset 1 |  MAIN  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Char        | Test Asset 1 | Test_A | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Char        | Test Asset 1 | Test_B | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Environment | Test Asset 3 |  ----  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Prop        | Test Asset 2 |  ----  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Prop        | Test Asset 4 |  ----  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        #

        # set the project to project1
        dialog.projects_comboBox.setCurrentIndex(0)

        # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3]
        # set to assets
        dialog.tabWidget.setCurrentIndex(0)
        #self.show_dialog(dialog)

        # expect to see 6 rows
        self.assertEqual(6, dialog.assets_tableWidget.rowCount())

        # expect the assets types listed in the first column
        # first three should be Char
        dialog.assets_tableWidget.setCurrentCell(0, 1)
        self.assertEqual('Char',
                         dialog.assets_tableWidget.currentItem().text())
        dialog.assets_tableWidget.setCurrentCell(1, 1)
        self.assertEqual('Char',
                         dialog.assets_tableWidget.currentItem().text())
        dialog.assets_tableWidget.setCurrentCell(2, 1)
        self.assertEqual('Char',
                         dialog.assets_tableWidget.currentItem().text())

        # next should be Environment
        dialog.assets_tableWidget.setCurrentCell(3, 1)
        self.assertEqual('Environment',
                         dialog.assets_tableWidget.currentItem().text())

        # the next two should be Prop
        dialog.assets_tableWidget.setCurrentCell(4, 1)
        self.assertEqual('Prop',
                         dialog.assets_tableWidget.currentItem().text())
        dialog.assets_tableWidget.setCurrentCell(5, 1)
        self.assertEqual('Prop',
                         dialog.assets_tableWidget.currentItem().text())
 def fill_shots_tableWidget(self):
     """fills the shots_tableWidget
     """
     
     # TODO: merge cells of the same shot, or at least paint them in some other color
     
     # clear the tableWidget
     self.shots_tableWidget.clear()
     
     shot_vtypes = VersionType.query()\
         .filter(VersionType.type_for=='Shot')\
         .order_by(VersionType.name)\
         .all()
     
     shot_vtype_codes = map(lambda x: x.code, shot_vtypes)
     
     labels = ['Thumbnail', 'Sequence', 'Number', 'Take']
     labels.extend(map(lambda x: x.code, shot_vtypes))
     
     #logger.debug('shot_tableWidget.labels: %s' % labels)
     
     self.shots_tableWidget.setColumnCount(len(labels))
     self.shots_tableWidget.setHorizontalHeaderLabels(labels)
     
     # get the project
     project = self.get_current_project()
     
     if project is None:
         return
     
     # get all the shots for the sequence
     sequences = Sequence.query()\
         .filter(Sequence.project==project)\
         .order_by(Sequence.name)\
         .all()
     
     shot_count = db.query(func.count(Shot.id))\
         .join(Sequence)\
         .filter(Sequence.id==Shot.sequence_id)\
         .filter(Sequence.project==project)\
         .all()[0][0]
     
     # set the row count for all shots in that sequence
     self.shots_tableWidget.setRowCount(shot_count)
     
     items = []
     row = 0
     column = 0
     for sequence in sequences:    
         shots = Shot.query()\
             .filter(Shot.sequence==sequence)\
             .order_by(Shot.number)\
             .all()
         
         # sort according to numbers
         shots.sort(key=lambda x: utils.embedded_numbers(x.number))
         
         #logger.debug('shots of sequence %s is %s' % (sequence.name, shots))
         
         # feed the shots to the list
         
         previous_shot = None
         for shot in shots:
             take_names = map(
                 lambda x: x[0],
                 db.query(distinct(Version.take_name))
                     .filter(Version.version_of==shot)
                     .all()
             )
             
             if not len(take_names):
                 take_names = ['-']
             
             for take_name in take_names:
                 # add the seq name to the first column
                 column = 0
                 item = QtGui.QTableWidgetItem()
                 item.setTextAlignment(0x0004 | 0x0080)
                 #set the thumbnail
                 if os.path.exists(shot.thumbnail_full_path):
                     thumbnail_full_path = shot.thumbnail_full_path
                     pixmap = QtGui.QPixmap(thumbnail_full_path)
                     pixmap = pixmap.scaled(
                         conf.thumbnail_size[0] / 2,
                         conf.thumbnail_size[1] / 2,
                         QtCore.Qt.KeepAspectRatio,
                         QtCore.Qt.SmoothTransformation
                     )
                     brush = QtGui.QBrush(pixmap)
                     item.has_thumbnail = True
                     item.setBackground(brush)
                 else:
                     item.has_thumbnail = False
                 items.append(item)
                 
                 column = 1
                 item = QtGui.QTableWidgetItem(sequence.name)
                 item.setTextAlignment(0x0004 | 0x0080)
                 #self.shots_tableWidget.setItem(row, column, item)
                 items.append(item)
                 
                 # add the shot code to the second column
                 column = 2
                 item = QtGui.QTableWidgetItem(shot.code)
                 item.setTextAlignment(0x0004 | 0x0080)
                 #self.shots_tableWidget.setItem(row, column, item)
                 items.append(item)
                 
                 # add the take name to the third column
                 column = 3
                 item = QtGui.QTableWidgetItem(take_name)
                 item.setTextAlignment(0x0004 | 0x0080)
                 #self.assets_tableWidget.setItem(row, column, item)
                 items.append(item)
             
                 for type_code in shot_vtype_codes:
                     column += 1
                     
                     # get the latest version of that type and take
                     version = Version.query()\
                         .join(VersionType)\
                         .filter(Version.version_of==shot)\
                         .filter(Version.type_id==VersionType.id)\
                         .filter(VersionType.code==type_code)\
                         .filter(Version.take_name==take_name)\
                         .order_by(Version.version_number.desc())\
                         .first()
                     
                     if version:
                         # mark the status of that type in that take
                         item = QtGui.QTableWidgetItem(
                             version.status + '\n' + version.created_by.name
                         )
                         item.setTextAlignment(0x0004 | 0x0080)
                         
                         # set the color according to status
                         index = conf.status_list.index(version.status)
                         bgcolor = conf.status_bg_colors[index]
                         fgcolor = conf.status_fg_colors[index]
                         
                         bg = item.background()
                         bg.setColor(QtGui.QColor(*bgcolor))
                         item.setBackground(bg)
                         
                         fg = item.foreground()
                         fg.setColor(QtGui.QColor(*fgcolor))
                         item.setForeground(fg)
                         
                         try:
                             item.setBackgroundColor(QtGui.QColor(*bgcolor))
                         except AttributeError: # for PySide
                             pass
                         
                         # set this version to the item
                         item.version = version
                         
                     else:
                         # set the background color to black
                         item = QtGui.QTableWidgetItem('-')
                         item.setTextAlignment(0x0004 | 0x0080)
                         bg = item.background()
                         bg.setColor(QtGui.QColor(0, 0, 0))
                         item.setBackground(bg)
                         
                         try:
                             item.setBackgroundColor(QtGui.QColor(0, 0, 0))
                         except AttributeError: # for PySide
                             pass
                         
                         # set the version to None for this item
                         item.version = None
                     
                     items.append(item)
                 
                 row += 1
     
     self.shots_tableWidget.setRowCount(row)
     
     item_index = 0
     for r in range(row):
         for c in range(column + 1):
             item = items[item_index]
             self.shots_tableWidget.setItem(r, c, item)
             item_index += 1
     
     # adjust the row heights accordingly
     self.shots_tableWidget.resizeRowsToContents()
     
     # need to pass over the first rows again
     # to resize the thumbnail cell
     for r in range(row):
         item_index = r * (column + 1)
         item = items[item_index]
         if item.has_thumbnail:
             # scale the row height
             self.shots_tableWidget.setRowHeight(
                 r,
                 conf.thumbnail_size[1] / 2
             )
     
     # resize columns to fit the content
     self.shots_tableWidget.resizeColumnsToContents()
     
     # set the column width
     self.shots_tableWidget.setColumnWidth(0, conf.thumbnail_size[0] / 2)
 def fill_assets_tableWidget(self):
     """fills the asset_tableWidget
     """
     # clear the table
     self.assets_tableWidget.clear()
     
     asset_vtypes = VersionType.query()\
         .filter(VersionType.type_for=='Asset')\
         .order_by(VersionType.name)\
         .all()
     
     asset_vtype_codes = map(lambda x: x.code, asset_vtypes)
     
     labels = ['Thumbnail', 'Type', 'Name', 'Take']
     labels.extend(map(lambda x: x.code, asset_vtypes))
     
     logger.debug('asset_tableWidget.labels: %s' % labels)
     
     self.assets_tableWidget.setColumnCount(len(labels))
     self.assets_tableWidget.setHorizontalHeaderLabels(labels)
     
     # get the project
     project = self.get_current_project()
     
     if project is None:
         return
     
     # get all the assets for the project
     assets = Asset.query()\
         .filter(Asset.project==project)\
         .order_by(Asset.type)\
         .all()
     
     # feed the assets to the list
     items = []
     
     row = 0
     column = 0
     for asset in assets:
        # get the distinct take names
         take_names = map(
             lambda x: x[0],
             db.query(distinct(Version.take_name))
                 .filter(Version.version_of==asset)
                 .all()
         )
         
         if not len(take_names):
             take_names = ['-']
         
         for take_name in take_names:
             
             # add the asset type to the first column
             column = 0
             item = QtGui.QTableWidgetItem()
             item.setTextAlignment(0x0004 | 0x0080)
             # set the thumbnail
             if os.path.exists(asset.thumbnail_full_path):
                 thumbnail_full_path = asset.thumbnail_full_path
                 pixmap = QtGui.QPixmap(thumbnail_full_path)
                 pixmap = pixmap.scaled(
                     conf.thumbnail_size[0] / 2,
                     conf.thumbnail_size[1] / 2,
                     QtCore.Qt.KeepAspectRatio,
                     QtCore.Qt.SmoothTransformation
                 )
                 brush = QtGui.QBrush(pixmap)
                 item.has_thumbnail = True
                 item.setBackground(brush)
             else:
                 item.has_thumbnail = False
             items.append(item)
             
             column = 1
             item = QtGui.QTableWidgetItem(asset.type)
             item.setTextAlignment(0x0004 | 0x0080)
             items.append(item)
             
             # add the asset name to the second column
             column = 2
             item = QtGui.QTableWidgetItem(asset.name)
             item.setTextAlignment(0x0004 | 0x0080)
             items.append(item)
             
             # add the take name to the third column
             column = 3
             item = QtGui.QTableWidgetItem(take_name)
             item.setTextAlignment(0x0004 | 0x0080)
             #self.assets_tableWidget.setItem(row, column, item)
             items.append(item)
             
             for type_code in asset_vtype_codes:
                 column += 1
                 
                 # now for every asset vtype create two rows instead of one
                 # and show the users name on the second row
                 
                 # get the latest version of that type and take
                 version = Version.query()\
                     .join(VersionType)\
                     .filter(Version.version_of==asset)\
                     .filter(Version.type_id==VersionType.id)\
                     .filter(VersionType.code==type_code)\
                     .filter(Version.take_name==take_name)\
                     .order_by(Version.version_number.desc())\
                     .first()
                 
                 if version:
                     # mark the status of that type in that take
                     item = QtGui.QTableWidgetItem(
                         version.status + '\n' + version.created_by.name
                     )
                     item.setTextAlignment(0x0004 | 0x0080)
                     
                     # set the color according to status
                     index = conf.status_list.index(version.status)
                     bgcolor = conf.status_bg_colors[index]
                     fgcolor = conf.status_fg_colors[index]
                     
                     bg = item.background()
                     bg.setColor(QtGui.QColor(*bgcolor))
                     item.setBackground(bg)
                     
                     fg = item.foreground()
                     fg.setColor(QtGui.QColor(*fgcolor))
                     item.setForeground(fg)
                     
                     try:
                         item.setBackgroundColor(QtGui.QColor(*bgcolor))
                     except AttributeError: # gives errpor with PySide
                         pass
                     
                     # add this version to the item
                     item.version = version
                     
                 else:
                     # set the background color to black
                     item = QtGui.QTableWidgetItem('-')
                     item.setTextAlignment(0x0004 | 0x0080)
                     bg = item.background()
                     bg.setColor(QtGui.QColor(0, 0, 0))
                     item.setBackground(bg)
                     
                     try:
                         item.setBackgroundColor(QtGui.QColor(0, 0, 0))
                     except AttributeError: # gives error with PySide
                         pass
                     
                     # set the related version to None
                     item.version = None
                 
                 items.append(item)
                 
             row += 1
     
     self.assets_tableWidget.setRowCount(row)
     
     item_index = 0
     for r in range(row):
         for c in range(column + 1):
             item = items[item_index]
             self.assets_tableWidget.setItem(r, c, item)
             item_index += 1
     
     # adjust the row heights accordingly
     self.assets_tableWidget.resizeRowsToContents()
     
     # need to pass over the first rows again
     # to resize the thumbnail cell
     for r in range(row):
         item_index = r * (column + 1)
         item = items[item_index]
         if item.has_thumbnail:
             # scale the row height
             self.assets_tableWidget.setRowHeight(
                 r,
                 conf.thumbnail_size[1] / 2
             )
     
     # resize columns to fit the content
     self.assets_tableWidget.resizeColumnsToContents()
     
     # set column width
     self.assets_tableWidget.setColumnWidth(0, conf.thumbnail_size[0] / 2)
Beispiel #22
0
    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"),
        ]
Beispiel #23
0
class VersionTypeTester(unittest.TestCase):
    """tests the VersionType class
    """
    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"),
        ]

    def tearDown(self):
        """cleanup the test
        """
        # set the db.session to None
        db.session = None

        # delete the temp folder
        shutil.rmtree(self.temp_config_folder)
        shutil.rmtree(self.temp_projects_folder)

    def test_name_argument_is_None(self):
        """testing if a TypeError will be raised when the name argument is
        None
        """
        self.kwargs["name"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_name_attribute_is_None(self):
        """testing if a TypeError will be raised when the name attribute is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "name",
                          None)

    def test_name_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the name argument is not
        a string or unicode instance
        """
        self.kwargs["name"] = 123
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_name_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the name argument is not
        a string or unicode instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "name", 8)

    def test_name_argument_is_working_properly(self):
        """testing if the name argument is working properly and sets the name
        attribute correctly
        """
        self.assertEqual(self.kwargs["name"], self.test_versionType.name)

    def test_name_attribute_is_working_properly(self):
        """testing if the name attribute is working properly
        """
        test_value = "New Name"
        self.test_versionType.name = test_value
        self.assertEqual(test_value, self.test_versionType.name)

    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_argument_is_skipped(self):
        """testing if a TypeError will be raised when the code argument is
        skipped
        """
        self.kwargs.pop("code")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_code_argument_is_None(self):
        """testing if a TypeError will be raised when the code argument is
        None
        """
        self.kwargs["code"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_code_attribute_is_None(self):
        """testing if a TypeError will be raised when the code attribute is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "code",
                          None)

    def test_code_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the code argument is not
        a string or unicode instance
        """
        self.kwargs["code"] = 123
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_code_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the code argument is not
        a string or unicode instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "code", 8)

    def test_code_argument_is_working_properly(self):
        """testing if the code argument is working properly and sets the code
        attribute correctly
        """
        self.assertEqual(self.kwargs["code"], self.test_versionType.code)

    def test_code_attribute_is_working_properly(self):
        """testing if the code attribute is working properly
        """
        test_value = "New Name"
        self.test_versionType.code = test_value
        self.assertEqual(test_value, self.test_versionType.code)

    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_filename_argument_is_skipped(self):
        """testing if a TypeError will be raised when the filename argument
        is skipped
        """
        self.kwargs.pop("filename")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_filename_argument_is_empty_string(self):
        """testing if a ValueError will be raised when the filename argument
        is an empty string
        """
        self.kwargs["filename"] = ""
        self.assertRaises(ValueError, VersionType, **self.kwargs)

    def test_filename_attribute_is_empty_string(self):
        """testing if a ValueError will be raised when the filename attribute
        is set to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_versionType,
                          "filename", "")

    def test_filename_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the filename argument is
        not a string instance
        """
        self.kwargs["filename"] = 13245
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_filename_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the filename attribute is
        not a string instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType,
                          "filename", 23412)

    def test_filename_argument_is_working_properly(self):
        """testing if the filename attribute is initialized correctly with the
        same value of the filename argument
        """
        self.assertEqual(self.test_versionType.filename,
                         self.kwargs["filename"])

    def test_filename_attribute_is_working_properly(self):
        """testing if the filename attribute is working properly
        """
        test_value = "test_filename"
        self.test_versionType.filename = test_value
        self.assertEqual(self.test_versionType.filename, test_value)

    def test_path_argument_is_skipped(self):
        """testing if a TypeError will be raised when the path argument
        is skipped
        """
        self.kwargs.pop("path")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_path_argument_is_empty_string(self):
        """testing if a ValueError will be raised when the path argument
        is an empty string
        """
        self.kwargs["path"] = ""
        self.assertRaises(ValueError, VersionType, **self.kwargs)

    def test_path_attribute_is_empty_string(self):
        """testing if a ValueError will be raised when the path attribute
        is set to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_versionType, "path",
                          "")

    def test_path_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the path argument is
        not a string instance
        """
        self.kwargs["path"] = 13245
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_path_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the path attribute is
        not a string instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType, "path",
                          23412)

    def test_path_argument_is_working_properly(self):
        """testing if the path attribute is initialized correctly with the
        same value of the path argument
        """
        self.assertEqual(self.test_versionType.path, self.kwargs["path"])

    def test_path_attribute_is_working_properly(self):
        """testing if the path attribute is working properly
        """
        test_value = "test_path"
        self.test_versionType.path = test_value
        self.assertEqual(self.test_versionType.path, test_value)

    def test_output_path_argument_is_skipped(self):
        """testing if a TypeError will be raised when the output_path
        argument is skipped
        """
        self.kwargs.pop("output_path")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_output_path_argument_is_empty_string(self):
        """testing if a ValueError will be raised when the output_path
        argument is an empty string
        """
        self.kwargs["output_path"] = ""
        self.assertRaises(ValueError, VersionType, **self.kwargs)

    def test_output_path_attribute_is_empty_string(self):
        """testing if a ValueError will be raised when the output_path
        attribute is set to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_versionType,
                          "output_path", "")

    def test_output_path_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the output_path argument
        is not a string instance
        """
        self.kwargs["output_path"] = 13245
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_output_path_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when the output_path attribute
        is not a string instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType,
                          "output_path", 23412)

    def test_output_path_argument_is_working_properly(self):
        """testing if the output_path attribute is initialized correctly with
        the same value of the output_path argument
        """
        self.assertEqual(self.test_versionType.output_path,
                         self.kwargs["output_path"])

    def test_output_path_attribute_is_working_properly(self):
        """testing if the output_path attribute is working properly
        """
        test_value = "test_output_path"
        self.test_versionType.output_path = test_value
        self.assertEqual(self.test_versionType.output_path, test_value)

    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_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_attribute_is_None(self):
        """testing if the extra_folders attribute will be an empty list when it
        is set to None
        """
        self.test_versionType.extra_folders = None
        self.assertEqual(self.test_versionType.extra_folders, "")

    def test_extra_folders_argument_is_not_a_string_instance(self):
        """testing if a TypeError will be raised when the extra_folders
        argument is not a string or unicode instance
        """
        self.kwargs["extra_folders"] = 123
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_extra_folders_attribute_is_not_a_string_instance(self):
        """testing if a TypeError will be raised when the extra_folders
        attribute is set to something other than a string or unicode instance
        """
        self.assertRaises(TypeError, setattr, self.test_versionType,
                          "extra_folders", 23423)

    def test_extra_folders_argument_is_working_properly(self):
        """testing if the extra_folders attribute will be set to the same value
        with the extra_folders argument while initialization
        """
        self.assertEqual(self.test_versionType.extra_folders,
                         self.kwargs["extra_folders"])

    def test_extra_folders_attribute_is_working_properly(self):
        """testing if the extra_folders attribute is working properly
        """
        test_value = "extra_folders"
        self.test_versionType.extra_folders = test_value
        self.assertEqual(self.test_versionType.extra_folders, test_value)

    def test_environments_argument_is_skipped(self):
        """testing if a TypeError will be raised when the environments
        argument is skipped
        """
        self.kwargs.pop("environments")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_argument_is_None(self):
        """testing if a TypeError will be raised when the environments
        argument is None
        """
        self.kwargs["environments"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_attribute_is_None(self):
        """testing if a TypeError will be raised when the environments
        attribute is set to None
        """
        self.assertRaises(TypeError, setattr, self.test_versionType,
                          "environments", None)

    def test_environments_argument_is_not_a_list(self):
        """testing if a TypeError will be raised when the environments argument
        is not a list instance
        """
        self.kwargs["environments"] = 12354
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_attribute_is_not_a_list(self):
        """testing if a TypeError will be raised when the environments
        attribute is set to something other than a list
        """
        self.assertRaises(TypeError, setattr, self.test_versionType,
                          "environments", 123)

    def test_environments_argument_is_not_a_list_of_strings(self):
        """testing if a TypeError will be raised when the environments argument
        is not a list of strings
        """
        self.kwargs["environments"] = [123, "MAYA"]
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_environments_attribute_is_not_a_list_of_strings(self):
        """testing if a TypeError will be raised when the environments
        attribute is not a list of strings
        """
        self.assertRaises(TypeError, setattr, self.test_versionType,
                          "environments", [123, "MAYA"])

    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_environments_attribute_works_properly(self):
        """testing if the environments attribute is working properly
        """
        test_value = ["MAYA", "HOUDINI", "NUKE", "3DEQUALIZER"]
        self.test_versionType.environments = test_value

        for env in test_value:
            self.assertTrue(env in self.test_versionType.environments)

    def test_type_for_argument_is_skipped(self):
        """testing if a TypeError will be raised when the type_for argument is
        skipped
        """
        self.kwargs.pop("type_for")
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_type_for_argument_is_None(self):
        """testing if a TypeError will be raised when the type_for argument
        is None
        """
        self.kwargs["type_for"] = None
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    def test_type_for_argument_is_not_a_string_or_integer(self):
        """testing if a TypeError will be raised when the type_for argument is
        not a string or unicode or an integer
        """
        self.kwargs["type_for"] = [12]
        self.assertRaises(TypeError, VersionType, **self.kwargs)

    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_type_for_attribute_is_read_only(self):
        """testing if type_for attribute is read-only
        """
        self.assertRaises(AttributeError, setattr, self.test_versionType,
                          "type_for", "Asset")

    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__eq__(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.assertTrue(verst1 == verst2)
        self.assertFalse(verst1 == verst3)
        self.assertFalse(verst3 == verst4)

    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 test_shots_tableWidget_is_filled_with_Shot_data(self):
        """testing if the shots_tableWidget is filled with shot data properly
        """
        db.setup()
        
        # create a project
        proj1 = Project('Test Project 1')
        proj1.save()
        
        proj2 = Project('Test Project 2')
        proj2.save()
        
        shot_vtypes = VersionType.query()\
            .filter(VersionType.type_for=='Shot')\
            .order_by(VersionType.name)\
            .all()
        
        admin = User.query().first()
        
        # seqs for proj1
        seq1 = Sequence(proj1, 'Test Seq 1')
        seq1.save()
        
        seq2 = Sequence(proj1, 'Test Seq 2')
        seq2.save()
        
        # seqs for proj2
        seq3 = Sequence(proj2, 'Test Seq 3')
        seq3.save()
        
        seq4 = Sequence(proj2, 'Test Seq 4')
        seq4.save()
        
        # shots for seq1
        shot1 = Shot(seq1, 1)
        shot1.save()
        
        shot2 = Shot(seq1, 2)
        shot2.save()
        
        shot3 = Shot(seq1, 3)
        shot3.save()
        
        # shots for seq2
        shot4 = Shot(seq2, 4)
        shot4.save()
        
        shot5 = Shot(seq2, 5)
        shot5.save()
        
        shot6 = Shot(seq2, 6)
        shot6.save()
        
        # shots for seq3
        shot7 = Shot(seq3, 7)
        shot7.save()
        
        shot8 = Shot(seq3, 8)
        shot8.save()
        
        # shots for seq4
        shot9 = Shot(seq4, 9)
        shot9.save()
        
        shot10 = Shot(seq4, 10)
        shot10.save()
        
        # versions for shot1
        version1 = Version(
            version_of=shot1,
            base_name=shot1.code,
            type=shot_vtypes[0],
            created_by=admin,
            status=conf.status_list[0]
        )
        version1.save()
        
        version2 = Version(
            version_of=shot1,
            base_name=shot1.code,
            type=shot_vtypes[1],
            created_by=admin,
            status=conf.status_list[1]
        )
        version2.save()
        
        # versions for shot2
        version3 = Version(
            version_of=shot2,
            base_name=shot2.code,
            type=shot_vtypes[2],
            created_by=admin,
            status=conf.status_list[2]
        )
        version3.save()
        
        version4 = Version(
            version_of=shot2,
            base_name=shot2.code,
            type=shot_vtypes[3],
            created_by=admin,
            status=conf.status_list[3],
        )
        version4.save()
        
        # versions for shot3
        version5 = Version(
            version_of=shot3,
            base_name=shot3.code,
            type=shot_vtypes[4],
            created_by=admin,
            status=conf.status_list[4],
        )
        version5.save()
        
        version6 = Version(
            version_of=shot3,
            base_name=shot3.code,
            type=shot_vtypes[5],
            created_by=admin,
            status=conf.status_list[4],
        )
        version6.save()
        
        # versions for shot4
        version7 = Version(
            version_of=shot4,
            base_name=shot4.code,
            type=shot_vtypes[5],
            created_by=admin,
            status=conf.status_list[4]
        )
        version7.save()
        
        version8 = Version(
            version_of=shot4,
            base_name=shot4.code,
            type=shot_vtypes[5],
            created_by=admin,
            status=conf.status_list[0]
        )
        version8.save()
        
        dialog = status_manager.MainDialog()
#        self.show_dialog(dialog)
        
        # start tests
        
        # set the project to project1
        dialog.projects_comboBox.setCurrentIndex(0)
        
        #self.show_dialog(dialog)
        
        # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3]
        self.fail('test is not finished yet!')
    def test_assets_tableWidget_is_filled_with_Asset_data(self):
        """testing if the assets_tableWidget is filled with asset data properly
        """
        
        db.setup()
        
        # create a project
        proj1 = Project('Test Project 1')
        proj1.save()
        
        proj2 = Project('Test Project 2')
        proj2.save()
        
        asset_vtypes = VersionType.query()\
            .filter(VersionType.type_for=='Asset')\
            .order_by(VersionType.name)\
            .all()
        
        admin = User.query().first()
        
        asset1 = Asset(proj1, 'Test Asset 1', type='Char')
        asset1.save()
        
        asset2 = Asset(proj1, 'Test Asset 2', type='Prop')
        asset2.save()
        
        asset3 = Asset(proj1, 'Test Asset 3', type='Environment')
        asset3.save()
        
        asset4 = Asset(proj1, 'Test Asset 4', type='Prop')
        asset4.save()
        
        # versions for asset1
        version1 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=asset_vtypes[0],
            created_by=admin,
            status=conf.status_list[0]
        )
        version1.save()
        
        version2 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=asset_vtypes[1],
            created_by=admin,
            status=conf.status_list[1]
        )
        version2.save()
        
        version3 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=asset_vtypes[2],
            created_by=admin,
            status=conf.status_list[2]
        )
        version3.save()
        
        # version for asset1 with different takes
        version4 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=asset_vtypes[3],
            created_by=admin,
            status=conf.status_list[3],
            take_name='Test_A'
        )
        version4.save()
        
        version5 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=asset_vtypes[4],
            created_by=admin,
            status=conf.status_list[4],
            take_name='Test_A'
        )
        version5.save()
        
        version6 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=asset_vtypes[5],
            created_by=admin,
            status=conf.status_list[4],
            take_name='Test_B'
        )
        version6.save()
        
        version7 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=asset_vtypes[5],
            created_by=admin,
            status=conf.status_list[4],
            take_name='Test_B'
        )
        version7.save()
           
        dialog = status_manager.MainDialog()
#        self.show_dialog(dialog)      
        
        # start tests
        
        # What we should see shoul be:
        # 
        # +-----------+-------------+--------------+--------+---------------------+
        # | Thumbnail | Type        |     Name     |  Take  | Asset Version Types |
        # +===========+=============+==============+========+=====================+
        # |  (IMAGE)  | Char        | Test Asset 1 |  MAIN  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Char        | Test Asset 1 | Test_A | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Char        | Test Asset 1 | Test_B | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Environment | Test Asset 3 |  ----  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Prop        | Test Asset 2 |  ----  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        # |  (IMAGE)  | Prop        | Test Asset 4 |  ----  | ******************* |
        # +-----------+-------------+--------------+--------+---------------------+
        #
        
        # set the project to project1
        dialog.projects_comboBox.setCurrentIndex(0)
        
        # asset1's vtypes[0] vtypes[1] vtypes[2] vtypes[3]
        # set to assets
        dialog.tabWidget.setCurrentIndex(0)
        #self.show_dialog(dialog)
        
        # expect to see 6 rows
        self.assertEqual(6, dialog.assets_tableWidget.rowCount())
        
        # expect the assets types listed in the first column
        # first three should be Char
        dialog.assets_tableWidget.setCurrentCell(0, 1)
        self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text())
        dialog.assets_tableWidget.setCurrentCell(1, 1)
        self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text())
        dialog.assets_tableWidget.setCurrentCell(2, 1)
        self.assertEqual('Char', dialog.assets_tableWidget.currentItem().text())
        
        # next should be Environment
        dialog.assets_tableWidget.setCurrentCell(3, 1)
        self.assertEqual(
            'Environment',
            dialog.assets_tableWidget.currentItem().text()
        )
        
        # the next two should be Prop
        dialog.assets_tableWidget.setCurrentCell(4, 1)
        self.assertEqual(
            'Prop',
            dialog.assets_tableWidget.currentItem().text()
        )
        dialog.assets_tableWidget.setCurrentCell(5, 1)
        self.assertEqual(
            'Prop',
            dialog.assets_tableWidget.currentItem().text()
        )