예제 #1
0
    def test_add_alternative_shot_is_working_properly(self):
        """testing if the add_alternative_shot method is working properly
        """

        new_proj = Project("Test Project")
        new_proj.create()

        new_seq = Sequence(new_proj, "Test Sequence", "TEST_SEQ1")
        new_seq.save()

        new_shot = Shot(new_seq, 1)
        new_shot.save()

        # check if the sequence has only one shot
        self.assertEqual(len(new_seq.shots), 1)

        # now create an alternative to this shot
        new_seq.add_alternative_shot(1)

        # now check if the sequence has two shots
        self.assertEqual(len(new_seq.shots), 2)

        # and the second shots number is 1A
        self.assertEqual(new_seq.shots[1].number, "1A")

        # add a new alternative
        new_seq.add_alternative_shot("1")

        # check if there is three shots
        self.assertEqual(len(new_seq.shots), 3)

        # and the third shots number is 1B
        self.assertEqual(new_seq.shots[2].number, "1B")
예제 #2
0
    def test_database_simple_data(self):
        """testing if the database file has the necessary information related to
        the Sequence
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        test_seq_name = "TEST_SEQ1"
        new_seq = Sequence(new_proj, test_seq_name)
        new_seq.save()
        new_seq.create()

        # fill it with some non default values
        description = new_seq.description = "Test description"
        new_seq.save()

        # now check if the database is created correctly
        del new_seq

        # create the seq from scratch and let it read the database
        new_seq = db.session.query(Sequence).first()

        # now check if it was able to get these data
        self.assertEqual(description, new_seq.description)
예제 #3
0
    def test_database_simple_data(self):
        """testing if the database file has the necessary information related to
        the Sequence
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        test_seq_name = "TEST_SEQ1"
        new_seq = Sequence(new_proj, test_seq_name)
        new_seq.save()
        new_seq.create()

        # fill it with some non default values
        description = new_seq.description = "Test description"
        new_seq.save()

        # now check if the database is created correctly
        del new_seq

        # create the seq from scratch and let it read the database
        new_seq = db.session.query(Sequence).first()

        # now check if it was able to get these data
        self.assertEqual(description, new_seq.description)
예제 #4
0
    def test_add_alternative_shot_is_working_properly(self):
        """testing if the add_alternative_shot method is working properly
        """

        new_proj = Project("Test Project")
        new_proj.create()

        new_seq = Sequence(new_proj, "Test Sequence", "TEST_SEQ1")
        new_seq.save()

        new_shot = Shot(new_seq, 1)
        new_shot.save()

        # check if the sequence has only one shot
        self.assertEqual(len(new_seq.shots), 1)

        # now create an alternative to this shot
        new_seq.add_alternative_shot(1)

        # now check if the sequence has two shots
        self.assertEqual(len(new_seq.shots), 2)

        # and the second shots number is 1A
        self.assertEqual(new_seq.shots[1].number, "1A")

        # add a new alternative
        new_seq.add_alternative_shot("1")

        # check if there is three shots
        self.assertEqual(len(new_seq.shots), 3)

        # and the third shots number is 1B
        self.assertEqual(new_seq.shots[2].number, "1B")
예제 #5
0
    def test_UI_will_edit_the_given_Project_instance(self):
        """testing if a Project instance is passed the interface will allow the
        given Project instance to be edited
        """

        new_client = Client(name='Test Client 1')
        new_client.save()

        new_project = Project("Test Project")
        new_project.create()

        dialog = project_properties.MainDialog(project=new_project)

        # now edit the project from the UI
        new_name = "Test Project New Name"
        new_fps = 50
        dialog.name_lineEdit.setText(new_name)
        new_client_2_name = 'Test Client 2'
        dialog.clients_comboBox.lineEdit().setText(new_client_2_name)
        dialog.fps_spinBox.setValue(new_fps)
        dialog.resolution_comboBox.setCurrentIndex(3)
        preset_name = dialog.resolution_comboBox.currentText()
        resolution_data = conf.resolution_presets[preset_name]
        dialog.active_checkBox.setChecked(False)
        dialog.shot_number_prefix_lineEdit.setText("PL")
        dialog.shot_number_padding_spinBox.setValue(5)
        dialog.revision_number_prefix_lineEdit.setText("rev")
        dialog.revision_number_padding_spinBox.setValue(3)
        dialog.version_number_prefix_lineEdit.setText("ver")
        dialog.version_number_padding_spinBox.setValue(5)
        new_structure = "This is the new structure\nwith three lines\n" + \
                        "and this is the third line"
        dialog.structure_textEdit.setText(new_structure)

        # hit ok
        QTest.mouseClick(dialog.buttonBox.buttons()[0], Qt.LeftButton)

        # now check the data
        self.assertEqual(new_project.name, new_name)
        self.assertEqual(new_project.client.name, new_client_2_name)
        # check if a client is created with that name

        new_client_2 = Client.query().filter(
            Client.name == new_client_2_name).first()
        self.assertIsInstance(new_client_2, Client)

        self.assertEqual(new_project.fps, new_fps)
        self.assertEqual(new_project.width, resolution_data[0])
        self.assertEqual(new_project.height, resolution_data[1])
        self.assertEqual(new_project.pixel_aspect, resolution_data[2])
        self.assertEqual(new_project.active, False)
        self.assertEqual(new_project.shot_number_padding, 5)
        self.assertEqual(new_project.shot_number_prefix, "PL")
        self.assertEqual(new_project.rev_number_padding, 3)
        self.assertEqual(new_project.rev_number_prefix, "rev")
        self.assertEqual(new_project.ver_number_padding, 5)
        self.assertEqual(new_project.ver_number_prefix, "ver")
        self.assertEqual(new_project.structure, new_structure)
예제 #6
0
    def test_add_shots_method_creates_shots_based_on_the_given_range_formulat(self):
        """testing if the add_shots will create shots based on the
        shot_range_formula argument
        """

        new_proj = Project(name="Test Project")
        new_proj.create()

        new_seq1 = Sequence(new_proj, "Test Sequence 1", "TEST_SEQ1")
        new_seq1.save()

        expected_shot_numbers = [
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "10",
            "12",
            "13",
            "14",
            "15",
            "304_SB_0403_0040",
        ]

        # assert there is no shots in the sequence
        self.assertTrue(len(new_seq1.shots) == 0)

        # add a new shot
        new_seq1.add_shots("1")
        self.assertTrue(len(new_seq1.shots) == 1)
        self.assertTrue(new_seq1.shots[0].number in expected_shot_numbers)

        # add a couple of shots
        new_seq1.add_shots("2,3,4")
        self.assertTrue(len(new_seq1.shots) == 4)
        self.assertTrue(new_seq1.shots[1].number in expected_shot_numbers)
        self.assertTrue(new_seq1.shots[2].number in expected_shot_numbers)
        self.assertTrue(new_seq1.shots[3].number in expected_shot_numbers)

        # add a couple of more
        # new_seq1.add_shots("5-8,10,12-15")
        new_seq1.add_shots("5,6,7,8,10,12,13,14,15,304_sb_0403_0040")

        self.assertTrue(len(new_seq1.shots) == 14)
        self.assertIn(new_seq1.shots[4].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[5].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[6].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[7].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[8].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[9].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[10].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[11].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[12].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[13].number, expected_shot_numbers)
    def test_UI_will_edit_the_given_Project_instance(self):
        """testing if a Project instance is passed the interface will allow the
        given Project instance to be edited
        """
        
        new_client = Client(name='Test Client 1')
        new_client.save()
        
        new_project = Project("Test Project")
        new_project.create()
        
        dialog = project_properties.MainDialog(project=new_project)
        
        # now edit the project from the UI
        new_name = "Test Project New Name"
        new_fps = 50
        dialog.name_lineEdit.setText(new_name)
        new_client_2_name = 'Test Client 2'
        dialog.clients_comboBox.lineEdit().setText(new_client_2_name)
        dialog.fps_spinBox.setValue(new_fps)
        dialog.resolution_comboBox.setCurrentIndex(3)
        preset_name = dialog.resolution_comboBox.currentText()
        resolution_data = conf.resolution_presets[preset_name]
        dialog.active_checkBox.setChecked(False)
        dialog.shot_number_prefix_lineEdit.setText("PL")
        dialog.shot_number_padding_spinBox.setValue(5)
        dialog.revision_number_prefix_lineEdit.setText("rev")
        dialog.revision_number_padding_spinBox.setValue(3)
        dialog.version_number_prefix_lineEdit.setText("ver")
        dialog.version_number_padding_spinBox.setValue(5)
        new_structure = "This is the new structure\nwith three lines\n" + \
                        "and this is the third line"
        dialog.structure_textEdit.setText(new_structure)
        
        # hit ok
        QTest.mouseClick(dialog.buttonBox.buttons()[0], Qt.LeftButton)

        # now check the data
        self.assertEqual(new_project.name, new_name)
        self.assertEqual(new_project.client.name, new_client_2_name)
        # check if a client is created with that name
        
        new_client_2 = Client.query().filter(Client.name==new_client_2_name).first()
        self.assertIsInstance(new_client_2, Client)
        
        self.assertEqual(new_project.fps, new_fps)
        self.assertEqual(new_project.width, resolution_data[0])
        self.assertEqual(new_project.height, resolution_data[1])
        self.assertEqual(new_project.pixel_aspect, resolution_data[2])
        self.assertEqual(new_project.active, False)
        self.assertEqual(new_project.shot_number_padding, 5)
        self.assertEqual(new_project.shot_number_prefix, "PL")
        self.assertEqual(new_project.rev_number_padding, 3)
        self.assertEqual(new_project.rev_number_prefix, "rev")
        self.assertEqual(new_project.ver_number_padding, 5)
        self.assertEqual(new_project.ver_number_prefix, "ver")
        self.assertEqual(new_project.structure, new_structure)
예제 #8
0
 def test_save_as_sets_the_fps(self):
     """testing if the save_as method sets the fps value correctly
     """
     
     # create two projects with different fps values
     # first create a new scene and save it under the first project
     # and then save it under the other project
     # and check if the fps follows the project values
     
     project1 = Project("FPS_TEST_PROJECT_1")
     project1.fps = 24
     project1.create()
     
     project2 = Project("FPS_TEST_PROJECT_2")
     project2.fps = 30
     project2.save()
     
     # create assets
     asset1 = Asset(project1, "Test Asset 1")
     asset1.save()
     
     asset2 = Asset(project2, "Test Asset 2")
     asset2.save()
     
     # create versions
     version1 = Version(
         version_of=asset1,
         base_name=asset1.code,
         type=self.asset_vtypes[0],
         created_by=self.user1
     )
     
     version2 = Version(
         version_of=asset2,
         base_name=asset2.code,
         type=self.asset_vtypes[0],
         created_by=self.user1
     )
     
     # save the current scene for asset1
     self.mEnv.save_as(version1)
     
     # check the fps value
     self.assertEqual(
         self.mEnv.get_fps(),
         24
     )
     
     # now save it for asset2
     self.mEnv.save_as(version2)
     
     # check the fps value
     self.assertEqual(
         self.mEnv.get_fps(),
         30
     )
    def test_sequences_comboBox_is_filled_with_sequences_from_the_current_project(
            self):
        """testing if the sequences_comboBox is filled with the correct
        sequences from the currently chosen Project instance
        """
        project1 = Project("Test Project 1")
        project2 = Project("Test Project 2")

        project1.create()
        project2.create()

        project1.save()
        project2.save()

        seq1 = Sequence(project1, "Test Sequence 1")
        seq1.save()
        seq2 = Sequence(project1, "Test Sequence 2")
        seq2.save()
        seq3 = Sequence(project2, "Test Sequence 3")
        seq3.save()
        seq4 = Sequence(project2, "Test Sequence 4")
        seq4.save()

        # create dialog
        dialog = project_manager.MainDialog()
        #        self.show_dialog(dialog)

        # set the project to project2
        index = dialog.projects_comboBox.findText(project2.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # check if the sequences_comboBox is filled with correct data
        self.assertEqual(dialog.sequences_comboBox.count(), 2)

        item_texts = []
        for i in range(2):
            dialog.sequences_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.sequences_comboBox.currentText())

        self.assertTrue(seq3.name in item_texts)
        self.assertTrue(seq4.name in item_texts)

        # set the project to project1
        index = dialog.projects_comboBox.findText(project1.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # check if the sequences_comboBox is filled with correct data
        self.assertEqual(dialog.sequences_comboBox.count(), 2)

        item_texts = []
        for i in range(2):
            dialog.sequences_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.sequences_comboBox.currentText())

        self.assertTrue(seq1.name in item_texts)
        self.assertTrue(seq2.name in item_texts)
 def test_code_lineEdit_is_disabled_when_an_existing_Project_is_passed(self):
     """testing if the code_lineEdit is disabled when an existing Project
     instance is passed to the UI
     """
     new_project = Project("Test Project 1")
     new_project.create()
     
     dialog = project_properties.MainDialog(project=new_project)
     
     self.assertFalse(dialog.code_lineEdit.isEnabled())
    def test_sequences_comboBox_is_filled_with_sequences_from_the_current_project(self):
        """testing if the sequences_comboBox is filled with the correct
        sequences from the currently chosen Project instance
        """
        project1 = Project("Test Project 1")
        project2 = Project("Test Project 2")
        
        project1.create()
        project2.create()
        
        project1.save()
        project2.save()
        
        seq1 = Sequence(project1, "Test Sequence 1")
        seq1.save()
        seq2 = Sequence(project1, "Test Sequence 2")
        seq2.save()
        seq3 = Sequence(project2, "Test Sequence 3")
        seq3.save()
        seq4 = Sequence(project2, "Test Sequence 4")
        seq4.save()
        
        # create dialog
        dialog = project_manager.MainDialog()
#        self.show_dialog(dialog)
        
        # set the project to project2
        index = dialog.projects_comboBox.findText(project2.name)
        dialog.projects_comboBox.setCurrentIndex(index)
        
        # check if the sequences_comboBox is filled with correct data
        self.assertEqual(dialog.sequences_comboBox.count(), 2)

        item_texts = []
        for i in range(2):
            dialog.sequences_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.sequences_comboBox.currentText())
        
        self.assertTrue(seq3.name in item_texts)
        self.assertTrue(seq4.name in item_texts)
        
        # set the project to project1
        index = dialog.projects_comboBox.findText(project1.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # check if the sequences_comboBox is filled with correct data
        self.assertEqual(dialog.sequences_comboBox.count(), 2)

        item_texts = []
        for i in range(2):
            dialog.sequences_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.sequences_comboBox.currentText())

        self.assertTrue(seq1.name in item_texts)
        self.assertTrue(seq2.name in item_texts)
예제 #12
0
    def test_code_lineEdit_is_disabled_when_an_existing_Project_is_passed(
            self):
        """testing if the code_lineEdit is disabled when an existing Project
        instance is passed to the UI
        """
        new_project = Project("Test Project 1")
        new_project.create()

        dialog = project_properties.MainDialog(project=new_project)

        self.assertFalse(dialog.code_lineEdit.isEnabled())
    def test_sequences_comboBox_caches_Sequence_instances_in_sequences_attribute(
            self):
        """testing if the sequence_comboBox caches the Sequence instances in
        an attribute called Sequence
        """

        project1 = Project("Test Project 1")
        project1.create()

        project2 = Project("Test Project 2")
        project2.create()

        seq1 = Sequence(project1, "Test Sequence 1")
        seq1.save()

        seq2 = Sequence(project1, "Test Sequence 2")
        seq2.save()

        seq3 = Sequence(project2, "Test Sequence 3")
        seq3.save()

        seq4 = Sequence(project2, "Test Sequence 4")
        seq4.save()

        seq5 = Sequence(project2, "Test Sequence 5")
        seq5.save()

        dialog = project_manager.MainDialog()

        self.assertTrue(hasattr(dialog.sequences_comboBox, "sequences"))

        # set it to project1
        index = dialog.projects_comboBox.findText(project1.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # check if sequences_comboBox.sequences has 3 elements
        self.assertEqual(len(dialog.sequences_comboBox.sequences), 2)

        # check if all the sequences are there
        self.assertTrue(seq1 in dialog.sequences_comboBox.sequences)
        self.assertTrue(seq2 in dialog.sequences_comboBox.sequences)

        # set it to project2
        index = dialog.projects_comboBox.findText(project2.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # check if sequences_comboBox.sequences has 3 elements
        self.assertEqual(len(dialog.sequences_comboBox.sequences), 3)

        # check if all the sequences are there
        self.assertTrue(seq3 in dialog.sequences_comboBox.sequences)
        self.assertTrue(seq4 in dialog.sequences_comboBox.sequences)
        self.assertTrue(seq5 in dialog.sequences_comboBox.sequences)
    def test_sequences_comboBox_caches_Sequence_instances_in_sequences_attribute(self):
        """testing if the sequence_comboBox caches the Sequence instances in
        an attribute called Sequence
        """

        project1 = Project("Test Project 1")
        project1.create()

        project2 = Project("Test Project 2")
        project2.create()

        seq1 = Sequence(project1, "Test Sequence 1")
        seq1.save()
        
        seq2 = Sequence(project1, "Test Sequence 2")
        seq2.save()

        seq3 = Sequence(project2, "Test Sequence 3")
        seq3.save()

        seq4 = Sequence(project2, "Test Sequence 4")
        seq4.save()

        seq5 = Sequence(project2, "Test Sequence 5")
        seq5.save()

        dialog = project_manager.MainDialog()
        
        self.assertTrue(hasattr(dialog.sequences_comboBox, "sequences"))

        # set it to project1
        index = dialog.projects_comboBox.findText(project1.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # check if sequences_comboBox.sequences has 3 elements
        self.assertEqual(len(dialog.sequences_comboBox.sequences), 2)

        # check if all the sequences are there
        self.assertTrue(seq1 in dialog.sequences_comboBox.sequences)
        self.assertTrue(seq2 in dialog.sequences_comboBox.sequences)

        # set it to project2
        index = dialog.projects_comboBox.findText(project2.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # check if sequences_comboBox.sequences has 3 elements
        self.assertEqual(len(dialog.sequences_comboBox.sequences), 3)

        # check if all the sequences are there
        self.assertTrue(seq3 in dialog.sequences_comboBox.sequences)
        self.assertTrue(seq4 in dialog.sequences_comboBox.sequences)
        self.assertTrue(seq5 in dialog.sequences_comboBox.sequences)
예제 #15
0
    def test_add_shots_method_creates_shots_based_on_the_given_range_formulat(
            self):
        """testing if the add_shots will create shots based on the
        shot_range_formula argument
        """

        new_proj = Project(name="Test Project")
        new_proj.create()

        new_seq1 = Sequence(new_proj, "Test Sequence 1", "TEST_SEQ1")
        new_seq1.save()

        expected_shot_numbers = [
            '1', '2', '3', '4', '5', '6', '7', '8', '10', '12', '13', '14',
            '15', '304_SB_0403_0040'
        ]

        # assert there is no shots in the sequence
        self.assertTrue(len(new_seq1.shots) == 0)

        # add a new shot
        new_seq1.add_shots("1")
        self.assertTrue(len(new_seq1.shots) == 1)
        self.assertTrue(new_seq1.shots[0].number in expected_shot_numbers)

        # add a couple of shots
        new_seq1.add_shots("2,3,4")
        self.assertTrue(len(new_seq1.shots) == 4)
        self.assertTrue(new_seq1.shots[1].number in expected_shot_numbers)
        self.assertTrue(new_seq1.shots[2].number in expected_shot_numbers)
        self.assertTrue(new_seq1.shots[3].number in expected_shot_numbers)

        # add a couple of more
        #new_seq1.add_shots("5-8,10,12-15")
        new_seq1.add_shots("5,6,7,8,10,12,13,14,15,304_sb_0403_0040")

        self.assertTrue(len(new_seq1.shots) == 14)
        self.assertIn(new_seq1.shots[4].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[5].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[6].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[7].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[8].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[9].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[10].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[11].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[12].number, expected_shot_numbers)
        self.assertIn(new_seq1.shots[13].number, expected_shot_numbers)
예제 #16
0
    def test_save_as_sets_the_fps(self):
        """testing if the save_as method sets the fps value correctly
        """

        # create two projects with different fps values
        # first create a new scene and save it under the first project
        # and then save it under the other project
        # and check if the fps follows the project values

        project1 = Project("FPS_TEST_PROJECT_1")
        project1.fps = 24
        project1.create()

        project2 = Project("FPS_TEST_PROJECT_2")
        project2.fps = 30
        project2.save()

        # create assets
        asset1 = Asset(project1, "Test Asset 1")
        asset1.save()

        asset2 = Asset(project2, "Test Asset 2")
        asset2.save()

        # create versions
        version1 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=self.asset_vtypes[0],
                           created_by=self.user1)

        version2 = Version(version_of=asset2,
                           base_name=asset2.code,
                           type=self.asset_vtypes[0],
                           created_by=self.user1)

        # save the current scene for asset1
        self.mEnv.save_as(version1)

        # check the fps value
        self.assertEqual(self.mEnv.get_fps(), 24)

        # now save it for asset2
        self.mEnv.save_as(version2)

        # check the fps value
        self.assertEqual(self.mEnv.get_fps(), 30)
예제 #17
0
    def test_calling_create_multiple_times(self):
        """testing if no error will be raised when calling Sequence.create
        multiple times
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        new_seq = Sequence(new_proj, "TEST_SEQ")
        new_seq.save()

        # now call create multiple times
        new_seq.create()
        new_seq.create()
        new_seq.create()
        new_seq.create()
        new_seq.create()
예제 #18
0
    def test_calling_create_multiple_times(self):
        """testing if no error will be raised when calling Sequence.create
        multiple times
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        new_seq = Sequence(new_proj, "TEST_SEQ")
        new_seq.save()

        # now call create multiple times
        new_seq.create()
        new_seq.create()
        new_seq.create()
        new_seq.create()
        new_seq.create()
예제 #19
0
    def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable(
            self):
        """testing if the save_as method updates the references paths with an
        absolute path starting with conf.repository_env_key for references to
        a version in the same project thus the referenced path is relative
        """

        # create project
        proj1 = Project("Proj1")
        proj1.save()
        proj1.create()

        # create assets
        asset1 = Asset(proj1, "Asset 1")
        asset1.save()

        # create a version of asset vtype
        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        # save it
        self.mEnv.save_as(vers1)

        # new scene
        pm.newFile(force=True)

        # create another version with different type
        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()

        # reference the other version
        self.mEnv.reference(vers1)

        # save it
        self.mEnv.save_as(vers2)

        # now check if the referenced vers1 starts with $REPO
        refs = pm.listReferences()

        # there should be only one ref
        self.assertTrue(len(refs) == 1)

        # and the path should start with conf.repository_env_key
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key))
예제 #20
0
 def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable(self):
     """testing if the save_as method updates the references paths with an
     absolute path starting with conf.repository_env_key for references to
     a version in the same project thus the referenced path is relative
     """
     
     # create project
     proj1 = Project("Proj1")
     proj1.save()
     proj1.create()
     
     # create assets
     asset1 = Asset(proj1, "Asset 1")
     asset1.save()
     
     # create a version of asset vtype 
     vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
     vers1.save()
     
     # save it
     self.mEnv.save_as(vers1)
     
     # new scene
     pm.newFile(force=True)
     
     # create another version with different type
     vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
     vers2.save()
     
     # reference the other version
     self.mEnv.reference(vers1)
     
     # save it
     self.mEnv.save_as(vers2)
     
     # now check if the referenced vers1 starts with $REPO
     refs = pm.listReferences()
     
     # there should be only one ref
     self.assertTrue(len(refs)==1)
     
     # and the path should start with conf.repository_env_key
     self.assertTrue(
         refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)
     )
예제 #21
0
    def test_creating_two_different_sequences_and_calling_create(self):
        """testing if no error will be raised when creating two different
        Sequences for the same Project and calling the Sequences.create()
        in mixed order
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        new_seq1 = Sequence(new_proj, "TEST_SEQ1")
        new_seq2 = Sequence(new_proj, "TEST_SEQ2")

        new_seq1.save()
        new_seq2.save()

        #        print "calling new_seq1.create"
        new_seq1.create()
        #        print "calling new_seq2.create"
        new_seq2.create()
예제 #22
0
    def test_creating_two_different_sequences_and_calling_create(self):
        """testing if no error will be raised when creating two different
        Sequences for the same Project and calling the Sequences.create()
        in mixed order
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        new_seq1 = Sequence(new_proj, "TEST_SEQ1")
        new_seq2 = Sequence(new_proj, "TEST_SEQ2")

        new_seq1.save()
        new_seq2.save()

        #        print "calling new_seq1.create"
        new_seq1.create()
        #        print "calling new_seq2.create"
        new_seq2.create()
예제 #23
0
    def test_reference_creates_references_to_Versions_in_other_workspaces_loaded(
            self):
        """testing if reference method creates references to Versions with
        different VersionType and the reference state will be loaded
        """

        proj1 = Project("Test Project 1")
        proj1.create()
        proj1.save()

        asset1 = Asset(proj1, "Test Asset 1")
        asset1.save()

        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()

        self.mEnv.save_as(vers1)

        pm.newFile(force=True)

        self.mEnv.save_as(vers2)

        # refence vers1 to vers2
        self.mEnv.reference(vers1)

        # now check if the referenced files unresolved path is already starting
        # with conf.repository_env_key

        refs = pm.listReferences()

        # there should be only one reference
        self.assertEqual(len(refs), 1)

        # the unresolved path should start with $REPO
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key))

        self.assertTrue(refs[0].isLoaded())
예제 #24
0
 def test_save_as_of_a_scene_with_two_references_to_the_same_version(self):
     """testing if the case where the current maya scene has two references
     to the same file is gracefully handled by assigning the version only
     once
     """
     
     # create project
     proj1 = Project("Proj1")
     proj1.save()
     proj1.create()
     
     # create assets
     asset1 = Asset(proj1, "Asset 1")
     asset1.save()
     
     # create a version of asset vtype 
     vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
     vers1.save()
     
     # save it
     self.mEnv.save_as(vers1)
     
     # new scene
     pm.newFile(force=True)
     
     # create another version with different type
     vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
     vers2.save()
     
     # reference the other version twice
     self.mEnv.reference(vers1)
     self.mEnv.reference(vers1)
     
     # save it and expect no InvalidRequestError
     self.mEnv.save_as(vers2)
     
     self.mEnv.reference(vers1)
     vers3 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
     vers3.save()
     
     self.mEnv.save_as(vers3)
예제 #25
0
    def test_save_as_of_a_scene_with_two_references_to_the_same_version(self):
        """testing if the case where the current maya scene has two references
        to the same file is gracefully handled by assigning the version only
        once
        """

        # create project
        proj1 = Project("Proj1")
        proj1.save()
        proj1.create()

        # create assets
        asset1 = Asset(proj1, "Asset 1")
        asset1.save()

        # create a version of asset vtype
        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        # save it
        self.mEnv.save_as(vers1)

        # new scene
        pm.newFile(force=True)

        # create another version with different type
        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()

        # reference the other version twice
        self.mEnv.reference(vers1)
        self.mEnv.reference(vers1)

        # save it and expect no InvalidRequestError
        self.mEnv.save_as(vers2)

        self.mEnv.reference(vers1)
        vers3 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers3.save()

        self.mEnv.save_as(vers3)
예제 #26
0
 def test_reference_creates_references_to_Versions_in_other_workspaces_loaded(self):
     """testing if reference method creates references to Versions with
     different VersionType and the reference state will be loaded
     """
     
     proj1 = Project("Test Project 1")
     proj1.create()
     proj1.save()
 
     asset1 = Asset(proj1, "Test Asset 1")
     asset1.save()
 
     vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
     vers1.save()
 
     vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
     vers2.save()
 
     self.mEnv.save_as(vers1)
 
     pm.newFile(force=True)
 
     self.mEnv.save_as(vers2)
 
     # refence vers1 to vers2
     self.mEnv.reference(vers1)
 
     # now check if the referenced files unresolved path is already starting
     # with conf.repository_env_key
     
     refs = pm.listReferences()
 
     # there should be only one reference
     self.assertEqual(len(refs), 1)
 
     # the unresolved path should start with $REPO
     self.assertTrue(
         refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)
     )
     
     self.assertTrue(refs[0].isLoaded())
예제 #27
0
    def test_database_recreation_of_sequence_object(self):
        """testing if the database file has the necessary information related to
        the Sequence
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        test_seq_name = "TEST_SEQ1"
        new_seq = Sequence(new_proj, test_seq_name)
        new_seq.save()

        description = new_seq.description

        # now check if the database is created correctly
        del new_seq

        # create the seq from scratch and let it read the database
        new_seq = Sequence(new_proj, test_seq_name)

        # now check if it was able to get these data
        self.assertEqual(new_seq.description, description)
예제 #28
0
    def test_database_recreation_of_sequence_object(self):
        """testing if the database file has the necessary information related to
        the Sequence
        """

        new_proj = Project(name="TEST_PROJECT")
        new_proj.create()

        test_seq_name = "TEST_SEQ1"
        new_seq = Sequence(new_proj, test_seq_name)
        new_seq.save()

        description = new_seq.description

        # now check if the database is created correctly
        del new_seq

        # create the seq from scratch and let it read the database
        new_seq = Sequence(new_proj, test_seq_name)

        # now check if it was able to get these data
        self.assertEqual(new_seq.description, description)
예제 #29
0
    def test___ne___operator(self):
        """testing the __ne__ (not equal) operator
        """

        # create a new project and two sequence
        # then create three new sequence objects to compare each of them
        # with the other

        new_proj = Project("TEST_PROJECT_FOR_NE_TEST")
        new_proj.create()

        seq1 = Sequence(new_proj, "SEQ1")
        seq2 = Sequence(new_proj, "SEQ1")
        seq3 = Sequence(new_proj, "SEQ2")

        new_proj2 = Project("TEST_PROJECT2")
        new_proj2.create()
        seq4 = Sequence(new_proj2, "SEQ3")

        self.assertFalse(seq1 != seq2)
        self.assertTrue(seq1 != seq3)
        self.assertTrue(seq1 != seq4)
        self.assertTrue(seq3 != seq4)
예제 #30
0
    def test___ne___operator(self):
        """testing the __ne__ (not equal) operator
        """

        # create a new project and two sequence
        # then create three new sequence objects to compare each of them
        # with the other

        new_proj = Project("TEST_PROJECT_FOR_NE_TEST")
        new_proj.create()

        seq1 = Sequence(new_proj, "SEQ1")
        seq2 = Sequence(new_proj, "SEQ1")
        seq3 = Sequence(new_proj, "SEQ2")

        new_proj2 = Project("TEST_PROJECT2")
        new_proj2.create()
        seq4 = Sequence(new_proj2, "SEQ3")

        self.assertFalse(seq1 != seq2)
        self.assertTrue(seq1 != seq3)
        self.assertTrue(seq1 != seq4)
        self.assertTrue(seq3 != seq4)
예제 #31
0
class MayaTester(unittest.TestCase):
    """Tests the oyProjectManager.environments.mayaEnv.Maya class
    """
    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)

    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)

        # quit maya
        pm.runtime.Quit()

    def test_save_as_creates_a_maya_file_at_version_full_path(self):
        """testing if the save_as creates a maya file at the Version.full_path
        """

        # check the version file doesn't exists
        self.assertFalse(os.path.exists(self.version1.full_path))

        # save the version
        self.mEnv.save_as(self.version1)

        # check the file exists
        self.assertTrue(os.path.exists(self.version1.full_path))

    def test_save_as_sets_the_version_extension_to_ma(self):
        """testing if the save_as method sets the version extension to ma
        """

        self.version1.extension = ""
        self.mEnv.save_as(self.version1)
        self.assertEqual(self.version1.extension, ".ma")

    def test_save_as_sets_the_render_version_string(self):
        """testing if the save_as method sets the version string in the render
        settings
        """

        self.mEnv.save_as(self.version1)

        # now check if the render settings version is the same with the
        # version.version_number

        render_version = pm.getAttr("defaultRenderGlobals.renderVersion")
        self.assertEqual(render_version,
                         "v%03d" % self.version1.version_number)

    def test_save_as_sets_the_render_format_to_exr_for_mentalray(self):
        """testing if the save_as method sets the render format to exr
        """

        # load mayatomr plugin
        pm.loadPlugin("Mayatomr")

        # set the current renderer to mentalray
        dRG = pm.PyNode("defaultRenderGlobals")

        dRG.setAttr('currentRenderer', 'mentalRay')

        # dirty little maya tricks
        pm.mel.miCreateDefaultNodes()

        mrG = pm.PyNode("mentalrayGlobals")

        self.mEnv.save_as(self.version1)

        # now check if the render format is correctly set to exr with zip
        # compression
        self.assertEqual(dRG.getAttr("imageFormat"), 51)
        self.assertEqual(dRG.getAttr("imfkey"), "exr")
        self.assertEqual(mrG.getAttr("imageCompression"), 4)

    def test_save_as_sets_the_render_file_name_for_Assets(self):
        """testing if the save_as sets the render file name correctly
        """

        self.mEnv.save_as(self.version1)

        # check if the path equals to
        expected_path = self.version1.output_path +\
                        "/<Layer>/"+ self.version1.project.code + "_" +\
                        self.version1.base_name +"_" +\
                        self.version1.take_name +\
                        "_<Layer>_<RenderPass>_<Version>"

        image_path = os.path.join(pm.workspace.path,
                                  pm.workspace.fileRules['image']).replace(
                                      "\\", "/")

        expected_path = utils.relpath(
            image_path,
            expected_path,
        )

        dRG = pm.PyNode("defaultRenderGlobals")

        self.assertEqual(expected_path, dRG.getAttr("imageFilePrefix"))

    def test_save_as_sets_the_render_file_name_for_Shots(self):
        """testing if the save_as sets the render file name correctly
        """

        test_seq = Sequence(self.project, "Test Sequence 1")
        test_seq.save()

        test_shot = Shot(test_seq, 1)
        test_shot.save()

        self.kwargs["type"] = self.shot_vtypes[0]
        self.kwargs["version_of"] = test_shot

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

        self.mEnv.save_as(self.version1)

        # check if the path equals to
        expected_path = self.version1.output_path + \
                        "/<Layer>/"+ self.version1.project.code + "_" + \
                        self.version1.version_of.sequence.code + "_" + \
                        self.version1.base_name +"_" + \
                        self.version1.take_name + \
                            "_<Layer>_<RenderPass>_<Version>"

        image_path = os.path.join(pm.workspace.path,
                                  pm.workspace.fileRules['image']).replace(
                                      "\\", "/")

        expected_path = utils.relpath(
            image_path,
            expected_path,
        )

        dRG = pm.PyNode("defaultRenderGlobals")

        self.assertEqual(expected_path, dRG.getAttr("imageFilePrefix"))

    def test_save_as_replaces_file_image_paths(self):
        """testing if save_as method replaces image paths with REPO relative
        path
        """

        self.mEnv.save_as(self.version1)

        # create file node
        file_node = pm.createNode("file")

        # set it to a path in the workspace
        texture_path = os.path.join(pm.workspace.path,
                                    ".maya_files/textures/test.jpg")
        file_node.fileTextureName.set(texture_path)

        # save a newer version
        version2 = Version(**self.kwargs)
        version2.save()

        self.mEnv.save_as(version2)

        # now check if the file nodes fileTextureName is converted to a
        # relative path to the current workspace

        expected_path = texture_path.replace(os.environ["REPO"], "$REPO")

        self.assertEqual(file_node.getAttr("fileTextureName"), expected_path)

    def test_save_as_sets_the_resolution(self):
        """testing if save_as sets the render resolution for the current scene
        """

        project = self.version1.project

        width = 1920
        height = 1080
        pixel_aspect = 1.0

        project.width = width
        project.height = height
        project.pixel_aspect = pixel_aspect
        project.save()

        # save the scene
        self.mEnv.save_as(self.version1)

        # check the resolutions
        dRes = pm.PyNode("defaultResolution")
        self.assertEqual(dRes.width.get(), width)
        self.assertEqual(dRes.height.get(), height)
        self.assertEqual(dRes.pixelAspect.get(), pixel_aspect)

    def test_save_as_sets_the_resolution_only_for_first_version(self):
        """testing if save_as sets the render resolution for the current scene
        but only for the first version of the asset
        """

        project = self.version1.project

        width = 1920
        height = 1080
        pixel_aspect = 1.0

        project.width = width
        project.height = height
        project.pixel_aspect = pixel_aspect
        project.save()

        # save the scene
        self.mEnv.save_as(self.version1)

        # check the resolutions
        dRes = pm.PyNode("defaultResolution")
        self.assertEqual(dRes.width.get(), width)
        self.assertEqual(dRes.height.get(), height)
        self.assertEqual(dRes.pixelAspect.get(), pixel_aspect)

        # now change the resolution of the maya file
        new_width = 1280
        new_height = 720
        new_pixel_aspect = 1.0
        dRes.width.set(new_width)
        dRes.height.set(new_height)
        dRes.pixelAspect.set(new_pixel_aspect)

        # save the version again
        new_version = Version(**self.kwargs)
        new_version.save()

        self.mEnv.save_as(new_version)

        # test if the resolution is not changed
        self.assertEqual(dRes.width.get(), new_width)
        self.assertEqual(dRes.height.get(), new_height)
        self.assertEqual(dRes.pixelAspect.get(), new_pixel_aspect)

    def test_save_as_fills_the_referenced_versions_list(self):
        """testing if the save_as method updates the Version.references list
        with the current references list from the Maya
        """

        # create a couple of versions and reference them to each other
        # and reference them to the the scene and check if maya updates the
        # Version.references list

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

        # change the take name
        self.kwargs["take_name"] = "Take1"
        version1 = Version(**self.kwargs)
        version1.save()

        self.kwargs["take_name"] = "Take2"
        version2 = Version(**self.kwargs)
        version2.save()

        self.kwargs["take_name"] = "Take3"
        version3 = Version(**self.kwargs)
        version3.save()

        # now create scenes with these files
        self.mEnv.save_as(version1)
        self.mEnv.save_as(version2)
        self.mEnv.save_as(version3)  # this is the dummy version

        # create a new scene
        pm.newFile(force=True)

        # check if the versionBase.references is an empty list
        self.assertTrue(versionBase.references == [])

        # reference the given versions
        self.mEnv.reference(version1)
        self.mEnv.reference(version2)

        # save it as versionBase
        self.mEnv.save_as(versionBase)

        # now check if versionBase.references is updated
        self.assertTrue(len(versionBase.references) == 2)

        self.assertTrue(version1 in versionBase.references)
        self.assertTrue(version2 in versionBase.references)

    def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable(
            self):
        """testing if the save_as method updates the references paths with an
        absolute path starting with conf.repository_env_key for references to
        a version in the same project thus the referenced path is relative
        """

        # create project
        proj1 = Project("Proj1")
        proj1.save()
        proj1.create()

        # create assets
        asset1 = Asset(proj1, "Asset 1")
        asset1.save()

        # create a version of asset vtype
        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        # save it
        self.mEnv.save_as(vers1)

        # new scene
        pm.newFile(force=True)

        # create another version with different type
        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()

        # reference the other version
        self.mEnv.reference(vers1)

        # save it
        self.mEnv.save_as(vers2)

        # now check if the referenced vers1 starts with $REPO
        refs = pm.listReferences()

        # there should be only one ref
        self.assertTrue(len(refs) == 1)

        # and the path should start with conf.repository_env_key
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key))

    def test_save_as_of_a_scene_with_two_references_to_the_same_version(self):
        """testing if the case where the current maya scene has two references
        to the same file is gracefully handled by assigning the version only
        once
        """

        # create project
        proj1 = Project("Proj1")
        proj1.save()
        proj1.create()

        # create assets
        asset1 = Asset(proj1, "Asset 1")
        asset1.save()

        # create a version of asset vtype
        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        # save it
        self.mEnv.save_as(vers1)

        # new scene
        pm.newFile(force=True)

        # create another version with different type
        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()

        # reference the other version twice
        self.mEnv.reference(vers1)
        self.mEnv.reference(vers1)

        # save it and expect no InvalidRequestError
        self.mEnv.save_as(vers2)

        self.mEnv.reference(vers1)
        vers3 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers3.save()

        self.mEnv.save_as(vers3)

    def test_save_as_will_not_save_the_file_if_there_are_file_textures_with_local_path(
            self):
        """testing if save_as will raise a RuntimeError if there are file
        textures with local path
        """
        # create a texture file with local path
        new_texture_file = pm.nt.File()
        # generate a local path
        local_file_full_path = os.path.join(tempfile.gettempdir(), "temp.png")
        new_texture_file.fileTextureName.set(local_file_full_path)

        # now try to save it as a new version and expect a RuntimeError
        self.assertRaises(RuntimeError, self.mEnv.save_as, self.version1)

    def test_open_updates_the_referenced_versions_list(self):
        """testing if the open method updates the Version.references list with
        the current references list from the Maya
        """

        # create a couple of versions and reference them to each other
        # and reference them to the the scene and check if maya updates the
        # Version.references list

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

        # change the take naem
        self.kwargs["take_name"] = "Take1"
        version1 = Version(**self.kwargs)
        version1.save()

        self.kwargs["take_name"] = "Take2"
        version2 = Version(**self.kwargs)
        version2.save()

        self.kwargs["take_name"] = "Take3"
        version3 = Version(**self.kwargs)
        version3.save()

        # now create scenes with these files
        self.mEnv.save_as(version1)
        self.mEnv.save_as(version2)
        self.mEnv.save_as(version3)  # this is the dummy version

        # create a new scene
        pm.newFile(force=True)

        # check if the versionBase.references is an empty list
        self.assertTrue(versionBase.references == [])

        # reference the given versions
        self.mEnv.reference(version1)
        self.mEnv.reference(version2)

        # save it as versionBase
        self.mEnv.save_as(versionBase)

        # now check if versionBase.references is updated
        # this part is already tested in save_as
        self.assertTrue(len(versionBase.references) == 2)
        self.assertTrue(version1 in versionBase.references)
        self.assertTrue(version2 in versionBase.references)

        # now remove references
        ref_data = self.mEnv.get_referenced_versions()
        for data in ref_data:
            ref_node = data[1]
            ref_node.remove()

        # do a save (not save_as)
        pm.saveFile()

        # clean scene
        pm.newFile(force=True)

        # open the same asset
        self.mEnv.open_(versionBase, force=True)

        # and check the references is updated
        self.assertEqual(len(versionBase.references), 0)
        self.assertEqual(versionBase.references, [])

    def test_open_loads_the_references(self):
        """testing if the open method loads the references
        """

        # create a couple of versions and reference them to each other
        # and reference them to the the scene and check if maya updates the
        # Version.references list

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

        # change the take naem
        self.kwargs["take_name"] = "Take1"
        version1 = Version(**self.kwargs)
        version1.save()

        self.kwargs["take_name"] = "Take2"
        version2 = Version(**self.kwargs)
        version2.save()

        self.kwargs["take_name"] = "Take3"
        version3 = Version(**self.kwargs)
        version3.save()

        # now create scenes with these files
        self.mEnv.save_as(version1)
        self.mEnv.save_as(version2)
        self.mEnv.save_as(version3)  # this is the dummy version

        # create a new scene
        pm.newFile(force=True)

        # check if the versionBase.references is an empty list
        self.assertTrue(versionBase.references == [])

        # reference the given versions
        self.mEnv.reference(version1)
        self.mEnv.reference(version2)

        # save it as versionBase
        self.mEnv.save_as(versionBase)

        # clean scene
        pm.newFile(force=True)

        # re-open the file
        self.mEnv.open_(versionBase, force=True)
        self.mEnv.post_open(versionBase)

        # check if the references are loaded
        ref_data = self.mEnv.get_referenced_versions()
        for data in ref_data:
            ref_node = data[1]
            self.assertTrue(ref_node.isLoaded())

    def test_save_as_in_another_project_updates_paths_correctly(self):
        """testing if the external paths are updated correctly if the document
        is created in one maya project but it is saved under another one.
        """

        # create a new scene
        # save it under one Asset Version with name Asset1

        asset1 = Asset(self.project, "Asset 1")
        asset1.save()

        self.kwargs["version_of"] = asset1
        self.kwargs["base_name"] = asset1.code
        version1 = Version(**self.kwargs)
        version1.save()

        self.kwargs["take_name"] = "References1"
        version_ref1 = Version(**self.kwargs)
        version_ref1.save()

        self.kwargs["take_name"] = "References2"
        version_ref2 = Version(**self.kwargs)
        version_ref2.save()

        # save a maya file with this references
        self.mEnv.save_as(version_ref1)
        self.mEnv.save_as(version_ref2)

        # save the original version
        self.mEnv.save_as(version1)

        # create a couple of file textures
        file_texture1 = pm.createNode("file")
        file_texture2 = pm.createNode("file")

        path1 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/a.jpg"
        path2 = os.path.dirname(version1.path) + "/.maya_files/TEXTURES/b.jpg"

        # set them to some relative paths
        file_texture1.fileTextureName.set(path1)
        file_texture2.fileTextureName.set(path2)

        # create a couple of references in the same project
        self.mEnv.reference(version_ref1)
        self.mEnv.reference(version_ref2)

        # save again
        self.mEnv.save_as(version1)

        # then save it under another Asset with name Asset2
        # because with this new system all the Assets folders are a maya
        # project, the references should be updated correctly
        asset2 = Asset(self.project, "Asset 2")
        asset2.save()

        # create a new Version for Asset 2
        self.kwargs["version_of"] = asset2
        self.kwargs["base_name"] = asset2.code
        version2 = Version(**self.kwargs)

        # now save it under that asset
        self.mEnv.save_as(version2)

        # check if the paths are updated
        self.assertEqual(
            file_texture1.fileTextureName.get(),
            "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/a.jpg")

        self.assertEqual(
            file_texture2.fileTextureName.get(),
            "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/b.jpg")

    def test_save_as_sets_the_fps(self):
        """testing if the save_as method sets the fps value correctly
        """

        # create two projects with different fps values
        # first create a new scene and save it under the first project
        # and then save it under the other project
        # and check if the fps follows the project values

        project1 = Project("FPS_TEST_PROJECT_1")
        project1.fps = 24
        project1.create()

        project2 = Project("FPS_TEST_PROJECT_2")
        project2.fps = 30
        project2.save()

        # create assets
        asset1 = Asset(project1, "Test Asset 1")
        asset1.save()

        asset2 = Asset(project2, "Test Asset 2")
        asset2.save()

        # create versions
        version1 = Version(version_of=asset1,
                           base_name=asset1.code,
                           type=self.asset_vtypes[0],
                           created_by=self.user1)

        version2 = Version(version_of=asset2,
                           base_name=asset2.code,
                           type=self.asset_vtypes[0],
                           created_by=self.user1)

        # save the current scene for asset1
        self.mEnv.save_as(version1)

        # check the fps value
        self.assertEqual(self.mEnv.get_fps(), 24)

        # now save it for asset2
        self.mEnv.save_as(version2)

        # check the fps value
        self.assertEqual(self.mEnv.get_fps(), 30)

    def test_reference_creates_references_with_paths_starting_with_repository_env_key(
            self):
        """testing if reference method creates references with unresolved paths
        starting with conf.repository_env_key
        """

        proj1 = Project("Test Project 1")
        proj1.create()
        proj1.save()

        asset1 = Asset(proj1, "Test Asset 1")
        asset1.save()

        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        vers2 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers2.save()

        self.mEnv.save_as(vers1)

        pm.newFile(force=True)

        self.mEnv.save_as(vers2)

        # refence vers1 to vers2
        self.mEnv.reference(vers1)

        # now check if the referenced files unresolved path is already starting
        # with conf.repository_env_key

        refs = pm.listReferences()

        # there should be only one reference
        self.assertEqual(len(refs), 1)

        # the unresolved path should start with $REPO
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key))

        self.assertTrue(refs[0].isLoaded())

    def test_reference_creates_references_to_Versions_in_other_workspaces_loaded(
            self):
        """testing if reference method creates references to Versions with
        different VersionType and the reference state will be loaded
        """

        proj1 = Project("Test Project 1")
        proj1.create()
        proj1.save()

        asset1 = Asset(proj1, "Test Asset 1")
        asset1.save()

        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()

        self.mEnv.save_as(vers1)

        pm.newFile(force=True)

        self.mEnv.save_as(vers2)

        # refence vers1 to vers2
        self.mEnv.reference(vers1)

        # now check if the referenced files unresolved path is already starting
        # with conf.repository_env_key

        refs = pm.listReferences()

        # there should be only one reference
        self.assertEqual(len(refs), 1)

        # the unresolved path should start with $REPO
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key))

        self.assertTrue(refs[0].isLoaded())

    def test_save_as_replaces_imagePlane_filename_with_env_variable(self):
        """testing if save_as replaces the imagePlane filename with repository
        environment variable
        """

        # create a camera
        # create an image plane
        # set it to something
        # save the scene
        # check if the path is replaced with repository environment variable

        self.fail("test is not implemented yet")

    def test_save_as_creates_the_workspace_mel_file_in_the_given_path(self):
        """testing if save_as creates the workspace.mel file in the Asset or
        Shot root
        """
        # check if the workspace.mel file does not exist yet
        workspace_mel_full_path = os.path.join(
            os.path.dirname(self.version1.path), 'workspace.mel')
        self.assertFalse(os.path.exists(workspace_mel_full_path))
        self.mEnv.save_as(self.version1)
        self.assertTrue(os.path.exists(workspace_mel_full_path))

    def test_save_as_creates_the_workspace_fileRule_folders(self):
        """testing if save_as creates the fileRule folders
        """
        # first prove that the folders doesn't exist
        for key in pm.workspace.fileRules.keys():
            file_rule_partial_path = pm.workspace.fileRules[key]
            file_rule_full_path = os.path.join(
                os.path.dirname(self.version1.path), file_rule_partial_path)
            self.assertFalse(os.path.exists(file_rule_full_path))

        self.mEnv.save_as(self.version1)

        # save_as and now expect the folders to be created
        for key in pm.workspace.fileRules.keys():
            file_rule_partial_path = pm.workspace.fileRules[key]
            file_rule_full_path = os.path.join(
                os.path.dirname(self.version1.path), file_rule_partial_path)
            self.assertTrue(os.path.exists(file_rule_full_path))
    def test_shots_comboBox_is_filled_with_the_shots_from_the_current_sequence(
            self):
        """testing if the shots_comboBox is filled with the shots from the
        currently selected Sequence instance
        """

        # projects
        project1 = Project("Test Project 1")
        project1.create()

        project2 = Project("Test Project 2")
        project2.create()

        # sequences
        seq1 = Sequence(project1, "Test Sequence 1")
        seq1.save()

        seq2 = Sequence(project1, "Test Sequence 2")
        seq2.save()

        seq3 = Sequence(project2, "Test Sequence 3")
        seq3.save()

        seq4 = Sequence(project2, "Test Sequence 4")
        seq4.save()

        # shots
        shot1 = Shot(seq1, 1)
        shot2 = Shot(seq1, 2)
        shot3 = Shot(seq1, 3)

        shot4 = Shot(seq2, 4)
        shot5 = Shot(seq2, 5)
        shot6 = Shot(seq2, 6)

        shot7 = Shot(seq3, 7)
        shot8 = Shot(seq3, 8)
        shot9 = Shot(seq3, 9)

        shot10 = Shot(seq4, 10)
        shot11 = Shot(seq4, 11)
        shot12 = Shot(seq4, 12)

        db.session.add_all([
            shot1, shot2, shot3, shot4, shot5, shot6, shot7, shot8, shot9,
            shot10, shot11, shot12
        ])
        db.session.commit()

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

        # set to project1
        index = dialog.projects_comboBox.findText(project1.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # set to seq1
        index = dialog.sequences_comboBox.findText(seq1.name)
        dialog.sequences_comboBox.setCurrentIndex(index)

        # check if shots_comboBox has 3 entries
        self.assertEqual(dialog.shots_comboBox.count(), 3)

        # check if shot1, shot2, shot3 are in the comboBox
        item_texts = []
        for i in range(3):
            dialog.shots_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.shots_comboBox.currentText())

        self.assertTrue(shot1.code in item_texts)
        self.assertTrue(shot2.code in item_texts)
        self.assertTrue(shot3.code in item_texts)

        # set to project2
        index = dialog.projects_comboBox.findText(project2.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # set to seq4
        index = dialog.sequences_comboBox.findText(seq4.name)
        dialog.sequences_comboBox.setCurrentIndex(index)

        # check if shots_comboBox has 3 entries
        self.assertEqual(dialog.shots_comboBox.count(), 3)

        # check if shot10, shot11, shot12 are in the comboBox
        item_texts = []
        for i in range(3):
            dialog.shots_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.shots_comboBox.currentText())

        self.assertTrue(shot10.code in item_texts)
        self.assertTrue(shot11.code in item_texts)
        self.assertTrue(shot12.code in item_texts)
예제 #33
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)
예제 #34
0
class MainDialog(QtGui.QDialog, project_properties_UI.Ui_Dialog):
    """Dialog to edit project properties
    
    If a :class:`~oyProjectManager.models.project.Project` instance is also
    passed it will edit the given project.
    
    If no Project is passed then it will create and return a new one.
    """
    
    def __init__(self, parent=None, project=None):
        super(MainDialog, self).__init__(parent)
        self.setupUi(self)
        
        if db.session is None:
            db.setup()
        
        self.resolution_presets = conf.resolution_presets
        self.project = project
        
        self._setup_signals()
        self._setup_defaults()
        
        self.update_UI_from_project(self.project)
    
    def _setup_signals(self):
        """sets up signals
        """

        # cancel button
        QtCore.QObject.connect(
            self.buttonBox,
            QtCore.SIGNAL("rejected()"),
            self.close
        )
        
        # ok button
        QtCore.QObject.connect(
            self.buttonBox,
            QtCore.SIGNAL("accepted()"),
            self.button_box_ok_clicked
        )
        
        # changing the name of the project should also update the code
        # if the code field is empty
        QtCore.QObject.connect(
            self.name_lineEdit,
            QtCore.SIGNAL("textChanged(QString)"),
            self.name_edited
        )

    def set_resolution_to_default(self):
        # set the resolution to the default preset
        index = self.resolution_comboBox.findText(
            conf.default_resolution_preset
        )
        self.resolution_comboBox.setCurrentIndex(index)
    
    def _setup_defaults(self):
        """sets up the default values
        """
        
        self.resolution_comboBox.addItems(
            sorted(conf.resolution_presets.keys())
        )
        self.set_resolution_to_default()
        
        # clients
        clients = map(
            lambda x: x.name,
            Client.query().order_by(Client.name.asc()).all()
        )
        self.clients_comboBox.clear()
        self.clients_comboBox.addItems(clients)
        
        # set the fps to conf.default_fps
        self.fps_spinBox.setValue(conf.default_fps)
        
        # set active_checkBox to true
        self.active_checkBox.setChecked(True)
        
        # if a project is given don't let the user to try to change the code
        # attribute
        if self.project is not None:
            self.code_lineEdit.setEnabled(False)
        
        # advanced properties
        self.shot_number_padding_spinBox.setValue(conf.shot_number_padding)
        self.shot_number_prefix_lineEdit.setText(conf.shot_number_prefix)
        self.revision_number_padding_spinBox.setValue(conf.rev_number_padding)
        self.revision_number_prefix_lineEdit.setText(conf.rev_number_prefix)
        self.version_number_padding_spinBox.setValue(conf.ver_number_padding)
        self.version_number_prefix_lineEdit.setText(conf.ver_number_prefix)
        self.structure_textEdit.setText(conf.project_structure)
    
    def update_UI_from_project(self, project):
        """Updates the UI with the info from the given project instance
        
        :param project: The :class:`~oyProjectManager.models.project.Project`
          instance which the UI data will be read from.
        """
        # if a project is given update the UI with the given project info
        
        if project is None:
            return
        
        self.name_lineEdit.setText(project.name)
        self.code_lineEdit.setText(project.code)
        
        if project.client:
            index = self.clients_comboBox.findText(project.client.name)
            if index != -1:
                self.clients_comboBox.setCurrentIndex(index)
        
        self.fps_spinBox.setValue(project.fps)
        self.active_checkBox.setChecked(project.active)
        
        # advanced properties
        self.shot_number_prefix_lineEdit.setText(project.shot_number_prefix)
        self.shot_number_padding_spinBox.setValue(project.shot_number_padding)
        self.revision_number_prefix_lineEdit.setText(project.rev_number_prefix)
        self.revision_number_padding_spinBox.setValue(
            project.rev_number_padding
        )
        self.version_number_prefix_lineEdit.setText(project.ver_number_prefix)
        self.version_number_padding_spinBox.setValue(project.ver_number_padding)
        self.structure_textEdit.setText(project.structure)
        
        # set the resolution
        preset_key = None
        for key in conf.resolution_presets.keys():
            if conf.resolution_presets[key] == [project.width,
                                                project.height,
                                                project.pixel_aspect]:
                preset_key = key
                break
        
        if preset_key is not None:
            index = self.resolution_comboBox.findText(preset_key)
            self.resolution_comboBox.setCurrentIndex(index)
        else:
            # set it to custom
            self.resolution_comboBox.setCurrentIndex(
                self.resolution_comboBox.count()-1
            )
    
    def button_box_ok_clicked(self):
        """runs when the ok button clicked
        """
        
        # if there is no project given create a new one and return it
        
        # create_project
        # get the data from the input fields
        name = self.name_lineEdit.text()
        code = self.code_lineEdit.text()
        # check if the code is empty
        if code=="":
            # raise an error please
            QtGui.QMessageBox.critical(
                self,
                "Error",
                "Code field can not be empty,\n"
                "Please enter a proper Code!!!"
            )
            return
        
        client_name = self.clients_comboBox.currentText()
        client = Client.query().filter(Client.name==client_name).first()
        if not client:
            # just create the client
            client = Client(name=client_name)
            client.save()
        
        resolution_name = self.resolution_comboBox.currentText()
        resolution_data = conf.resolution_presets[resolution_name]
        fps = self.fps_spinBox.value()
        active = self.active_checkBox.isChecked()
        
        # advanced properties
        shot_number_padding = self.shot_number_padding_spinBox.value()
        shot_number_prefix = self.shot_number_prefix_lineEdit.text()
        rev_number_padding = self.revision_number_padding_spinBox.value()
        rev_number_prefix = self.revision_number_prefix_lineEdit.text()
        ver_number_padding = self.version_number_padding_spinBox.value()
        ver_number_prefix = self.version_number_prefix_lineEdit.text()
        structure_code = self.structure_textEdit.toPlainText()
        
        is_new_project = False
        
        if self.project is None:
            logger.debug("no project is given creating new one")
            # create the project
            
            self.project  = Project(name=name, code=code)
            is_new_project = True
            
        else:
            logger.debug("updating the given project")
           
        # update the project
        self.project.name = name
        self.project.client = client
        self.project.fps = fps
        self.project.width = resolution_data[0]
        self.project.height = resolution_data[1]
        self.project.pixel_aspect = resolution_data[2]
        self.project.active = active
        self.project.shot_number_padding = shot_number_padding
        self.project.shot_number_prefix = shot_number_prefix
        self.project.rev_number_padding = rev_number_padding
        self.project.rev_number_prefix = rev_number_prefix
        self.project.ver_number_padding = ver_number_padding
        self.project.ver_number_prefix = ver_number_prefix
        self.project.structure = structure_code
        
        if is_new_project:
            self.project.create()
        else:
            self.project.save()
        
        # and close the dialog
        self.close()
    
    def name_edited(self, new_name):
        """called by the ui event when the text in project name lineEdit
        changed, it updates the code field if the code field is empty
        :param new_name: the changed name
        """
        
        # update only if the code field is empty
        import re
        new_code = re.sub(r'([^A-Z0-9]+)([\-\s]*)', '_', new_name.upper())
        self.code_lineEdit.setText(new_code)
예제 #35
0
class MayaTester(unittest.TestCase):
    """Tests the oyProjectManager.environments.mayaEnv.Maya class
    """

    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)

    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)
        
        # quit maya
        pm.runtime.Quit()
    
    def test_save_as_creates_a_maya_file_at_version_full_path(self):
        """testing if the save_as creates a maya file at the Version.full_path
        """
        
        # check the version file doesn't exists
        self.assertFalse(os.path.exists(self.version1.full_path))
        
        # save the version
        self.mEnv.save_as(self.version1)
        
        # check the file exists
        self.assertTrue(os.path.exists(self.version1.full_path))
    
    def test_save_as_sets_the_version_extension_to_ma(self):
        """testing if the save_as method sets the version extension to ma
        """
        
        self.version1.extension = ""
        self.mEnv.save_as(self.version1)
        self.assertEqual(self.version1.extension, ".ma")
    
    def test_save_as_sets_the_render_version_string(self):
        """testing if the save_as method sets the version string in the render
        settings
        """
        
        self.mEnv.save_as(self.version1)
        
        # now check if the render settings version is the same with the
        # version.version_number
        
        render_version = pm.getAttr("defaultRenderGlobals.renderVersion")
        self.assertEqual(render_version, "v%03d" % self.version1.version_number)
    
    def test_save_as_sets_the_render_format_to_exr_for_mentalray(self):
        """testing if the save_as method sets the render format to exr
        """
        
        # load mayatomr plugin
        pm.loadPlugin("Mayatomr")
        
        # set the current renderer to mentalray
        dRG = pm.PyNode("defaultRenderGlobals")
        
        dRG.setAttr('currentRenderer', 'mentalRay')
        
        # dirty little maya tricks
        pm.mel.miCreateDefaultNodes()
        
        mrG = pm.PyNode("mentalrayGlobals")
        
        self.mEnv.save_as(self.version1)
        
        # now check if the render format is correctly set to exr with zip
        # compression
        self.assertEqual(dRG.getAttr("imageFormat"), 51)
        self.assertEqual(dRG.getAttr("imfkey"), "exr")
        self.assertEqual(mrG.getAttr("imageCompression"), 4)
    
    def test_save_as_sets_the_render_file_name_for_Assets(self):
        """testing if the save_as sets the render file name correctly
        """
        
        self.mEnv.save_as(self.version1)
        
        # check if the path equals to
        expected_path = self.version1.output_path +\
                        "/<Layer>/"+ self.version1.project.code + "_" +\
                        self.version1.base_name +"_" +\
                        self.version1.take_name +\
                        "_<Layer>_<RenderPass>_<Version>"

        image_path = os.path.join(
            pm.workspace.path,
            pm.workspace.fileRules['image']
        ).replace("\\", "/")

        expected_path = utils.relpath(
            image_path,
            expected_path,
        )

        dRG = pm.PyNode("defaultRenderGlobals")

        self.assertEqual(
            expected_path,
            dRG.getAttr("imageFilePrefix")
        )
    
    def test_save_as_sets_the_render_file_name_for_Shots(self):
        """testing if the save_as sets the render file name correctly
        """
        
        test_seq = Sequence(self.project, "Test Sequence 1")
        test_seq.save()
        
        test_shot = Shot(test_seq, 1)
        test_shot.save()
        
        self.kwargs["type"] = self.shot_vtypes[0]
        self.kwargs["version_of"] = test_shot
        
        self.version1 = Version(**self.kwargs)
        
        self.mEnv.save_as(self.version1)
        
        # check if the path equals to
        expected_path = self.version1.output_path + \
                        "/<Layer>/"+ self.version1.project.code + "_" + \
                        self.version1.version_of.sequence.code + "_" + \
                        self.version1.base_name +"_" + \
                        self.version1.take_name + \
                            "_<Layer>_<RenderPass>_<Version>"
        
        image_path = os.path.join(
            pm.workspace.path,
            pm.workspace.fileRules['image']
        ).replace("\\", "/")
        
        expected_path = utils.relpath(
            image_path,
            expected_path,
        )
        
        dRG = pm.PyNode("defaultRenderGlobals")
        
        self.assertEqual(
            expected_path,
            dRG.getAttr("imageFilePrefix")
        )
    
    def test_save_as_replaces_file_image_paths(self):
        """testing if save_as method replaces image paths with REPO relative
        path
        """
        
        self.mEnv.save_as(self.version1)
        
        # create file node
        file_node = pm.createNode("file")
        
        # set it to a path in the workspace
        texture_path = os.path.join(
            pm.workspace.path, ".maya_files/textures/test.jpg"
        )
        file_node.fileTextureName.set(texture_path)
        
        # save a newer version
        version2 = Version(**self.kwargs)
        version2.save()
        
        self.mEnv.save_as(version2)
        
        # now check if the file nodes fileTextureName is converted to a
        # relative path to the current workspace
        
        expected_path = texture_path.replace(os.environ["REPO"], "$REPO")
        
        self.assertEqual(
            file_node.getAttr("fileTextureName"),
            expected_path
        )

    def test_save_as_sets_the_resolution(self):
        """testing if save_as sets the render resolution for the current scene
        """

        project = self.version1.project

        width = 1920
        height = 1080
        pixel_aspect = 1.0

        project.width = width
        project.height = height
        project.pixel_aspect = pixel_aspect
        project.save()

        # save the scene
        self.mEnv.save_as(self.version1)

        # check the resolutions
        dRes = pm.PyNode("defaultResolution")
        self.assertEqual(dRes.width.get(), width)
        self.assertEqual(dRes.height.get(), height)
        self.assertEqual(dRes.pixelAspect.get(), pixel_aspect)

    def test_save_as_sets_the_resolution_only_for_first_version(self):
        """testing if save_as sets the render resolution for the current scene
        but only for the first version of the asset
        """
        
        project = self.version1.project
        
        width = 1920
        height = 1080
        pixel_aspect = 1.0
        
        project.width = width
        project.height = height
        project.pixel_aspect = pixel_aspect
        project.save()
        
        # save the scene
        self.mEnv.save_as(self.version1)
        
        # check the resolutions
        dRes = pm.PyNode("defaultResolution")
        self.assertEqual(dRes.width.get(), width)
        self.assertEqual(dRes.height.get(), height)
        self.assertEqual(dRes.pixelAspect.get(), pixel_aspect)
        
        # now change the resolution of the maya file
        new_width = 1280
        new_height = 720
        new_pixel_aspect = 1.0
        dRes.width.set(new_width)
        dRes.height.set(new_height)
        dRes.pixelAspect.set(new_pixel_aspect)
        
        # save the version again
        new_version = Version(**self.kwargs)
        new_version.save()
        
        self.mEnv.save_as(new_version)
        
        # test if the resolution is not changed
        self.assertEqual(dRes.width.get(), new_width)
        self.assertEqual(dRes.height.get(), new_height)
        self.assertEqual(dRes.pixelAspect.get(), new_pixel_aspect)

    def test_save_as_fills_the_referenced_versions_list(self):
        """testing if the save_as method updates the Version.references list
        with the current references list from the Maya
        """
        
        # create a couple of versions and reference them to each other
        # and reference them to the the scene and check if maya updates the
        # Version.references list
        
        versionBase = Version(**self.kwargs)
        versionBase.save()
        
        # change the take name
        self.kwargs["take_name"] = "Take1"
        version1 = Version(**self.kwargs)
        version1.save()
        
        self.kwargs["take_name"] = "Take2"
        version2 = Version(**self.kwargs)
        version2.save()
        
        self.kwargs["take_name"] = "Take3"
        version3 = Version(**self.kwargs)
        version3.save()
        
        # now create scenes with these files
        self.mEnv.save_as(version1)
        self.mEnv.save_as(version2)
        self.mEnv.save_as(version3) # this is the dummy version
        
        # create a new scene
        pm.newFile(force=True)
        
        # check if the versionBase.references is an empty list
        self.assertTrue(versionBase.references==[])
        
        # reference the given versions
        self.mEnv.reference(version1)
        self.mEnv.reference(version2)
        
        # save it as versionBase
        self.mEnv.save_as(versionBase)
        
        # now check if versionBase.references is updated
        self.assertTrue(len(versionBase.references)==2)
        
        self.assertTrue(version1 in versionBase.references)
        self.assertTrue(version2 in versionBase.references)
    
    def test_save_as_references_to_a_version_in_same_workspace_are_replaced_with_abs_path_with_env_variable(self):
        """testing if the save_as method updates the references paths with an
        absolute path starting with conf.repository_env_key for references to
        a version in the same project thus the referenced path is relative
        """
        
        # create project
        proj1 = Project("Proj1")
        proj1.save()
        proj1.create()
        
        # create assets
        asset1 = Asset(proj1, "Asset 1")
        asset1.save()
        
        # create a version of asset vtype 
        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()
        
        # save it
        self.mEnv.save_as(vers1)
        
        # new scene
        pm.newFile(force=True)
        
        # create another version with different type
        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()
        
        # reference the other version
        self.mEnv.reference(vers1)
        
        # save it
        self.mEnv.save_as(vers2)
        
        # now check if the referenced vers1 starts with $REPO
        refs = pm.listReferences()
        
        # there should be only one ref
        self.assertTrue(len(refs)==1)
        
        # and the path should start with conf.repository_env_key
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)
        )
    
    def test_save_as_of_a_scene_with_two_references_to_the_same_version(self):
        """testing if the case where the current maya scene has two references
        to the same file is gracefully handled by assigning the version only
        once
        """
        
        # create project
        proj1 = Project("Proj1")
        proj1.save()
        proj1.create()
        
        # create assets
        asset1 = Asset(proj1, "Asset 1")
        asset1.save()
        
        # create a version of asset vtype 
        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()
        
        # save it
        self.mEnv.save_as(vers1)
        
        # new scene
        pm.newFile(force=True)
        
        # create another version with different type
        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()
        
        # reference the other version twice
        self.mEnv.reference(vers1)
        self.mEnv.reference(vers1)
        
        # save it and expect no InvalidRequestError
        self.mEnv.save_as(vers2)
        
        self.mEnv.reference(vers1)
        vers3 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers3.save()
        
        self.mEnv.save_as(vers3)
    
    def test_save_as_will_not_save_the_file_if_there_are_file_textures_with_local_path(self):
        """testing if save_as will raise a RuntimeError if there are file
        textures with local path
        """
        # create a texture file with local path
        new_texture_file = pm.nt.File()
        # generate a local path
        local_file_full_path = os.path.join(
            tempfile.gettempdir(),
            "temp.png"
        )
        new_texture_file.fileTextureName.set(local_file_full_path)
        
        # now try to save it as a new version and expect a RuntimeError
        self.assertRaises(
            RuntimeError,
            self.mEnv.save_as,
            self.version1
        )
    
    def test_open_updates_the_referenced_versions_list(self):
        """testing if the open method updates the Version.references list with
        the current references list from the Maya
        """

        # create a couple of versions and reference them to each other
        # and reference them to the the scene and check if maya updates the
        # Version.references list

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

        # change the take naem
        self.kwargs["take_name"] = "Take1"
        version1 = Version(**self.kwargs)
        version1.save()

        self.kwargs["take_name"] = "Take2"
        version2 = Version(**self.kwargs)
        version2.save()

        self.kwargs["take_name"] = "Take3"
        version3 = Version(**self.kwargs)
        version3.save()

        # now create scenes with these files
        self.mEnv.save_as(version1)
        self.mEnv.save_as(version2)
        self.mEnv.save_as(version3) # this is the dummy version

        # create a new scene
        pm.newFile(force=True)

        # check if the versionBase.references is an empty list
        self.assertTrue(versionBase.references==[])

        # reference the given versions
        self.mEnv.reference(version1)
        self.mEnv.reference(version2)

        # save it as versionBase
        self.mEnv.save_as(versionBase)

        # now check if versionBase.references is updated
        # this part is already tested in save_as
        self.assertTrue(len(versionBase.references)==2)
        self.assertTrue(version1 in versionBase.references)
        self.assertTrue(version2 in versionBase.references)
        
        # now remove references
        ref_data = self.mEnv.get_referenced_versions()
        for data in ref_data:
            ref_node = data[1]
            ref_node.remove()

        # do a save (not save_as)
        pm.saveFile()
        
        # clean scene
        pm.newFile(force=True)
        
        # open the same asset
        self.mEnv.open_(versionBase, force=True)
        
        # and check the references is updated
        self.assertEqual(len(versionBase.references), 0)
        self.assertEqual(versionBase.references, [])

    def test_open_loads_the_references(self):
        """testing if the open method loads the references
        """

        # create a couple of versions and reference them to each other
        # and reference them to the the scene and check if maya updates the
        # Version.references list

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

        # change the take naem
        self.kwargs["take_name"] = "Take1"
        version1 = Version(**self.kwargs)
        version1.save()

        self.kwargs["take_name"] = "Take2"
        version2 = Version(**self.kwargs)
        version2.save()

        self.kwargs["take_name"] = "Take3"
        version3 = Version(**self.kwargs)
        version3.save()

        # now create scenes with these files
        self.mEnv.save_as(version1)
        self.mEnv.save_as(version2)
        self.mEnv.save_as(version3) # this is the dummy version

        # create a new scene
        pm.newFile(force=True)

        # check if the versionBase.references is an empty list
        self.assertTrue(versionBase.references==[])

        # reference the given versions
        self.mEnv.reference(version1)
        self.mEnv.reference(version2)
        
        # save it as versionBase
        self.mEnv.save_as(versionBase)

        # clean scene
        pm.newFile(force=True)
        
        # re-open the file
        self.mEnv.open_(versionBase, force=True)
        self.mEnv.post_open(versionBase)
        
        # check if the references are loaded
        ref_data = self.mEnv.get_referenced_versions()
        for data in ref_data:
            ref_node = data[1]
            self.assertTrue(ref_node.isLoaded())
    
    def test_save_as_in_another_project_updates_paths_correctly(self):
        """testing if the external paths are updated correctly if the document
        is created in one maya project but it is saved under another one.
        """
        
        # create a new scene
        # save it under one Asset Version with name Asset1
        
        asset1 = Asset(self.project, "Asset 1")
        asset1.save()
        
        self.kwargs["version_of"] = asset1
        self.kwargs["base_name"] = asset1.code
        version1 = Version(**self.kwargs)
        version1.save()
        
        self.kwargs["take_name"] = "References1"
        version_ref1 = Version(**self.kwargs)
        version_ref1.save()
        
        self.kwargs["take_name"] = "References2"
        version_ref2 = Version(**self.kwargs)
        version_ref2.save()
        
        # save a maya file with this references
        self.mEnv.save_as(version_ref1)
        self.mEnv.save_as(version_ref2)
        
        # save the original version
        self.mEnv.save_as(version1)
        
        # create a couple of file textures
        file_texture1 = pm.createNode("file")
        file_texture2 = pm.createNode("file")
        
        path1 = os.path.dirname(version1.path) +  "/.maya_files/TEXTURES/a.jpg"
        path2 = os.path.dirname(version1.path) +  "/.maya_files/TEXTURES/b.jpg"
        
        # set them to some relative paths
        file_texture1.fileTextureName.set(path1)
        file_texture2.fileTextureName.set(path2)
        
        # create a couple of references in the same project
        self.mEnv.reference(version_ref1)
        self.mEnv.reference(version_ref2)
        
        # save again
        self.mEnv.save_as(version1)

        # then save it under another Asset with name Asset2
        # because with this new system all the Assets folders are a maya
        # project, the references should be updated correctly
        asset2 = Asset(self.project, "Asset 2")
        asset2.save()
        
        # create a new Version for Asset 2
        self.kwargs["version_of"] = asset2
        self.kwargs["base_name"] = asset2.code
        version2 = Version(**self.kwargs)
        
        # now save it under that asset
        self.mEnv.save_as(version2)
        
        # check if the paths are updated
        self.assertEqual(
            file_texture1.fileTextureName.get(),
            "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/a.jpg"
        )

        self.assertEqual(
            file_texture2.fileTextureName.get(),
            "$REPO/TEST_PROJECT/Assets/Asset_1/.maya_files/TEXTURES/b.jpg"
        )
    
    def test_save_as_sets_the_fps(self):
        """testing if the save_as method sets the fps value correctly
        """
        
        # create two projects with different fps values
        # first create a new scene and save it under the first project
        # and then save it under the other project
        # and check if the fps follows the project values
        
        project1 = Project("FPS_TEST_PROJECT_1")
        project1.fps = 24
        project1.create()
        
        project2 = Project("FPS_TEST_PROJECT_2")
        project2.fps = 30
        project2.save()
        
        # create assets
        asset1 = Asset(project1, "Test Asset 1")
        asset1.save()
        
        asset2 = Asset(project2, "Test Asset 2")
        asset2.save()
        
        # create versions
        version1 = Version(
            version_of=asset1,
            base_name=asset1.code,
            type=self.asset_vtypes[0],
            created_by=self.user1
        )
        
        version2 = Version(
            version_of=asset2,
            base_name=asset2.code,
            type=self.asset_vtypes[0],
            created_by=self.user1
        )
        
        # save the current scene for asset1
        self.mEnv.save_as(version1)
        
        # check the fps value
        self.assertEqual(
            self.mEnv.get_fps(),
            24
        )
        
        # now save it for asset2
        self.mEnv.save_as(version2)
        
        # check the fps value
        self.assertEqual(
            self.mEnv.get_fps(),
            30
        )
    
    def test_reference_creates_references_with_paths_starting_with_repository_env_key(self):
        """testing if reference method creates references with unresolved paths
        starting with conf.repository_env_key
        """

        proj1 = Project("Test Project 1")
        proj1.create()
        proj1.save()

        asset1 = Asset(proj1, "Test Asset 1")
        asset1.save()

        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()

        vers2 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers2.save()

        self.mEnv.save_as(vers1)

        pm.newFile(force=True)

        self.mEnv.save_as(vers2)

        # refence vers1 to vers2
        self.mEnv.reference(vers1)

        # now check if the referenced files unresolved path is already starting
        # with conf.repository_env_key

        refs = pm.listReferences()

        # there should be only one reference
        self.assertEqual(len(refs), 1)

        # the unresolved path should start with $REPO
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)
        )

        self.assertTrue(refs[0].isLoaded())

    def test_reference_creates_references_to_Versions_in_other_workspaces_loaded(self):
        """testing if reference method creates references to Versions with
        different VersionType and the reference state will be loaded
        """
        
        proj1 = Project("Test Project 1")
        proj1.create()
        proj1.save()
    
        asset1 = Asset(proj1, "Test Asset 1")
        asset1.save()
    
        vers1 = Version(asset1, asset1.code, self.asset_vtypes[0], self.user1)
        vers1.save()
    
        vers2 = Version(asset1, asset1.code, self.asset_vtypes[1], self.user1)
        vers2.save()
    
        self.mEnv.save_as(vers1)
    
        pm.newFile(force=True)
    
        self.mEnv.save_as(vers2)
    
        # refence vers1 to vers2
        self.mEnv.reference(vers1)
    
        # now check if the referenced files unresolved path is already starting
        # with conf.repository_env_key
        
        refs = pm.listReferences()
    
        # there should be only one reference
        self.assertEqual(len(refs), 1)
    
        # the unresolved path should start with $REPO
        self.assertTrue(
            refs[0].unresolvedPath().startswith("$" + conf.repository_env_key)
        )
        
        self.assertTrue(refs[0].isLoaded())
    
    def test_save_as_replaces_imagePlane_filename_with_env_variable(self):
        """testing if save_as replaces the imagePlane filename with repository
        environment variable
        """
        
        # create a camera
        # create an image plane
        # set it to something
        # save the scene
        # check if the path is replaced with repository environment variable
        
        self.fail("test is not implemented yet")
    
    def test_save_as_creates_the_workspace_mel_file_in_the_given_path(self):
        """testing if save_as creates the workspace.mel file in the Asset or
        Shot root
        """
        # check if the workspace.mel file does not exist yet
        workspace_mel_full_path = os.path.join(
            os.path.dirname(self.version1.path),
            'workspace.mel'
        )
        self.assertFalse(os.path.exists(workspace_mel_full_path))
        self.mEnv.save_as(self.version1)
        self.assertTrue(os.path.exists(workspace_mel_full_path))
    
    def test_save_as_creates_the_workspace_fileRule_folders(self):
        """testing if save_as creates the fileRule folders
        """
        # first prove that the folders doesn't exist
        for key in pm.workspace.fileRules.keys():
            file_rule_partial_path = pm.workspace.fileRules[key]
            file_rule_full_path = os.path.join(
                os.path.dirname(self.version1.path),
                file_rule_partial_path
            )
            self.assertFalse(os.path.exists(file_rule_full_path))
        
        self.mEnv.save_as(self.version1)
        
        # save_as and now expect the folders to be created
        for key in pm.workspace.fileRules.keys():
            file_rule_partial_path = pm.workspace.fileRules[key]
            file_rule_full_path = os.path.join(
                os.path.dirname(self.version1.path),
                file_rule_partial_path
            )
            self.assertTrue(os.path.exists(file_rule_full_path))
예제 #36
0
class MainDialog(QtGui.QDialog, project_properties_UI.Ui_Dialog):
    """Dialog to edit project properties
    
    If a :class:`~oyProjectManager.models.project.Project` instance is also
    passed it will edit the given project.
    
    If no Project is passed then it will create and return a new one.
    """
    def __init__(self, parent=None, project=None):
        super(MainDialog, self).__init__(parent)
        self.setupUi(self)

        if db.session is None:
            db.setup()

        self.resolution_presets = conf.resolution_presets
        self.project = project

        self._setup_signals()
        self._setup_defaults()

        self.update_UI_from_project(self.project)

    def _setup_signals(self):
        """sets up signals
        """

        # cancel button
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"),
                               self.close)

        # ok button
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"),
                               self.button_box_ok_clicked)

        # changing the name of the project should also update the code
        # if the code field is empty
        QtCore.QObject.connect(self.name_lineEdit,
                               QtCore.SIGNAL("textChanged(QString)"),
                               self.name_edited)

    def set_resolution_to_default(self):
        # set the resolution to the default preset
        index = self.resolution_comboBox.findText(
            conf.default_resolution_preset)
        self.resolution_comboBox.setCurrentIndex(index)

    def _setup_defaults(self):
        """sets up the default values
        """

        self.resolution_comboBox.addItems(
            sorted(conf.resolution_presets.keys()))
        self.set_resolution_to_default()

        # clients
        clients = map(lambda x: x.name,
                      Client.query().order_by(Client.name.asc()).all())
        self.clients_comboBox.clear()
        self.clients_comboBox.addItems(clients)

        # set the fps to conf.default_fps
        self.fps_spinBox.setValue(conf.default_fps)

        # set active_checkBox to true
        self.active_checkBox.setChecked(True)

        # if a project is given don't let the user to try to change the code
        # attribute
        if self.project is not None:
            self.code_lineEdit.setEnabled(False)

        # advanced properties
        self.shot_number_padding_spinBox.setValue(conf.shot_number_padding)
        self.shot_number_prefix_lineEdit.setText(conf.shot_number_prefix)
        self.revision_number_padding_spinBox.setValue(conf.rev_number_padding)
        self.revision_number_prefix_lineEdit.setText(conf.rev_number_prefix)
        self.version_number_padding_spinBox.setValue(conf.ver_number_padding)
        self.version_number_prefix_lineEdit.setText(conf.ver_number_prefix)
        self.structure_textEdit.setText(conf.project_structure)

    def update_UI_from_project(self, project):
        """Updates the UI with the info from the given project instance
        
        :param project: The :class:`~oyProjectManager.models.project.Project`
          instance which the UI data will be read from.
        """
        # if a project is given update the UI with the given project info

        if project is None:
            return

        self.name_lineEdit.setText(project.name)
        self.code_lineEdit.setText(project.code)

        if project.client:
            index = self.clients_comboBox.findText(project.client.name)
            if index != -1:
                self.clients_comboBox.setCurrentIndex(index)

        self.fps_spinBox.setValue(project.fps)
        self.active_checkBox.setChecked(project.active)

        # advanced properties
        self.shot_number_prefix_lineEdit.setText(project.shot_number_prefix)
        self.shot_number_padding_spinBox.setValue(project.shot_number_padding)
        self.revision_number_prefix_lineEdit.setText(project.rev_number_prefix)
        self.revision_number_padding_spinBox.setValue(
            project.rev_number_padding)
        self.version_number_prefix_lineEdit.setText(project.ver_number_prefix)
        self.version_number_padding_spinBox.setValue(
            project.ver_number_padding)
        self.structure_textEdit.setText(project.structure)

        # set the resolution
        preset_key = None
        for key in conf.resolution_presets.keys():
            if conf.resolution_presets[key] == [
                    project.width, project.height, project.pixel_aspect
            ]:
                preset_key = key
                break

        if preset_key is not None:
            index = self.resolution_comboBox.findText(preset_key)
            self.resolution_comboBox.setCurrentIndex(index)
        else:
            # set it to custom
            self.resolution_comboBox.setCurrentIndex(
                self.resolution_comboBox.count() - 1)

    def button_box_ok_clicked(self):
        """runs when the ok button clicked
        """

        # if there is no project given create a new one and return it

        # create_project
        # get the data from the input fields
        name = self.name_lineEdit.text()
        code = self.code_lineEdit.text()
        # check if the code is empty
        if code == "":
            # raise an error please
            QtGui.QMessageBox.critical(
                self, "Error", "Code field can not be empty,\n"
                "Please enter a proper Code!!!")
            return

        client_name = self.clients_comboBox.currentText()
        client = Client.query().filter(Client.name == client_name).first()
        if not client:
            # just create the client
            client = Client(name=client_name)
            client.save()

        resolution_name = self.resolution_comboBox.currentText()
        resolution_data = conf.resolution_presets[resolution_name]
        fps = self.fps_spinBox.value()
        active = self.active_checkBox.isChecked()

        # advanced properties
        shot_number_padding = self.shot_number_padding_spinBox.value()
        shot_number_prefix = self.shot_number_prefix_lineEdit.text()
        rev_number_padding = self.revision_number_padding_spinBox.value()
        rev_number_prefix = self.revision_number_prefix_lineEdit.text()
        ver_number_padding = self.version_number_padding_spinBox.value()
        ver_number_prefix = self.version_number_prefix_lineEdit.text()
        structure_code = self.structure_textEdit.toPlainText()

        is_new_project = False

        if self.project is None:
            logger.debug("no project is given creating new one")
            # create the project

            self.project = Project(name=name, code=code)
            is_new_project = True

        else:
            logger.debug("updating the given project")

        # update the project
        self.project.name = name
        self.project.client = client
        self.project.fps = fps
        self.project.width = resolution_data[0]
        self.project.height = resolution_data[1]
        self.project.pixel_aspect = resolution_data[2]
        self.project.active = active
        self.project.shot_number_padding = shot_number_padding
        self.project.shot_number_prefix = shot_number_prefix
        self.project.rev_number_padding = rev_number_padding
        self.project.rev_number_prefix = rev_number_prefix
        self.project.ver_number_padding = ver_number_padding
        self.project.ver_number_prefix = ver_number_prefix
        self.project.structure = structure_code

        if is_new_project:
            self.project.create()
        else:
            self.project.save()

        # and close the dialog
        self.close()

    def name_edited(self, new_name):
        """called by the ui event when the text in project name lineEdit
        changed, it updates the code field if the code field is empty
        :param new_name: the changed name
        """

        # update only if the code field is empty
        import re
        new_code = re.sub(r'([^A-Z0-9]+)([\-\s]*)', '_', new_name.upper())
        self.code_lineEdit.setText(new_code)
    def test_shots_comboBox_is_filled_with_the_shots_from_the_current_sequence(self):
        """testing if the shots_comboBox is filled with the shots from the
        currently selected Sequence instance
        """
        
        # projects
        project1 = Project("Test Project 1")
        project1.create()

        project2 = Project("Test Project 2")
        project2.create()
        
        # sequences
        seq1 = Sequence(project1, "Test Sequence 1")
        seq1.save()
        
        seq2 = Sequence(project1, "Test Sequence 2")
        seq2.save()

        seq3 = Sequence(project2, "Test Sequence 3")
        seq3.save()
        
        seq4 = Sequence(project2, "Test Sequence 4")
        seq4.save()
        
        # shots
        shot1 = Shot(seq1, 1)
        shot2 = Shot(seq1, 2)
        shot3 = Shot(seq1, 3)

        shot4 = Shot(seq2, 4)
        shot5 = Shot(seq2, 5)
        shot6 = Shot(seq2, 6)

        shot7 = Shot(seq3, 7)
        shot8 = Shot(seq3, 8)
        shot9 = Shot(seq3, 9)

        shot10 = Shot(seq4, 10)
        shot11 = Shot(seq4, 11)
        shot12 = Shot(seq4, 12)
        
        db.session.add_all(
            [shot1, shot2, shot3, shot4, shot5, shot6, shot7, shot8, shot9,
             shot10, shot11, shot12]
        )
        db.session.commit()
        
        dialog = project_manager.MainDialog()
#        self.show_dialog(dialog)
        
        # set to project1
        index = dialog.projects_comboBox.findText(project1.name)
        dialog.projects_comboBox.setCurrentIndex(index)
        
        # set to seq1
        index = dialog.sequences_comboBox.findText(seq1.name)
        dialog.sequences_comboBox.setCurrentIndex(index)
        
        # check if shots_comboBox has 3 entries
        self.assertEqual(dialog.shots_comboBox.count(), 3)
        
        # check if shot1, shot2, shot3 are in the comboBox
        item_texts = []
        for i in range(3):
            dialog.shots_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.shots_comboBox.currentText())
        
        self.assertTrue(shot1.code in item_texts)
        self.assertTrue(shot2.code in item_texts)
        self.assertTrue(shot3.code in item_texts)

        # set to project2
        index = dialog.projects_comboBox.findText(project2.name)
        dialog.projects_comboBox.setCurrentIndex(index)

        # set to seq4
        index = dialog.sequences_comboBox.findText(seq4.name)
        dialog.sequences_comboBox.setCurrentIndex(index)

        # check if shots_comboBox has 3 entries
        self.assertEqual(dialog.shots_comboBox.count(), 3)

        # check if shot10, shot11, shot12 are in the comboBox
        item_texts = []
        for i in range(3):
            dialog.shots_comboBox.setCurrentIndex(i)
            item_texts.append(dialog.shots_comboBox.currentText())

        self.assertTrue(shot10.code in item_texts)
        self.assertTrue(shot11.code in item_texts)
        self.assertTrue(shot12.code in item_texts)
예제 #38
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)