Пример #1
0
    def test_asset_attribute_returns_a_list_of_assets_related_to_this_project(
            self):
        """testing if the asset attribute returns a list of assets which are
        related to this project
        """
        new_proj1 = Project("Test Project 1")
        new_proj1.create()

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

        new_proj3 = Project("Test Project 3")
        new_proj3.create()

        asset1 = Asset(new_proj1, "Asset 1")
        asset1.save()

        asset2 = Asset(new_proj1, "Asset 2")
        asset2.save()

        asset3 = Asset(new_proj2, "Asset 3")
        asset3.save()

        asset4 = Asset(new_proj2, "Asset 4")
        asset4.save()

        self.assertItemsEqual(new_proj1.assets, [asset1, asset2])
        self.assertItemsEqual(new_proj2.assets, [asset3, asset4])
        self.assertItemsEqual(new_proj3.assets, [])
Пример #2
0
    def test_deleting_an_asset_will_not_delete_the_other_assets_in_the_related_project(
            self):
        """testing if deleting an asset will not delete the other assets in the
        related project
        """
        proj1 = Project('test project 1')
        proj1.save()

        asset1 = Asset(proj1, 'test asset 1')
        asset1.save()

        asset2 = Asset(proj1, 'test asset 2')
        asset2.save()

        asset3 = Asset(proj1, 'test asset 3')
        asset3.save()

        # check if they are properly in the db.session
        self.assertIn(proj1, db.session)
        self.assertIn(asset1, db.session)
        self.assertIn(asset2, db.session)
        self.assertIn(asset3, db.session)

        # delete asset1
        db.session.delete(asset1)
        db.session.commit()

        # check if the asset1 is deleted
        self.assertNotIn(asset1, db.session)

        # and the others are in place
        self.assertIn(proj1, db.session)
        self.assertIn(asset2, db.session)
        self.assertIn(asset3, db.session)
Пример #3
0
    def test_deleting_a_project_deletes_the_related_assets(self):
        """testing if deleting a project also deletes all Assets related to it
        """
        proj1 = Project("Test Project1")
        proj1.save()

        proj2 = Project("Test Project2")
        proj2.save()

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

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

        asset3 = Asset(proj2, "Test Asset 3")
        asset3.save()

        # confirm assets are in session
        self.assertIn(asset1, db.session)
        self.assertIn(asset2, db.session)

        db.session.delete(proj1)
        db.session.commit()

        # now check if asset1 and asset2 are also deleted
        assets = db.session.query(Asset).all()
        self.assertNotIn(asset1, assets)
        self.assertNotIn(asset2, assets)
        self.assertNotIn(asset1, db.session)
        self.assertNotIn(asset2, db.session)

        # check if proj2 and asset3 are  still there
        self.assertIn(proj2, db.session)
        self.assertIn(asset3, db.session)
Пример #4
0
 def test_name_argument_formatting(self):
     """testing if the name argument will be formatted correctly
     """
     for test_value in self._name_test_values:
         self.kwargs["name"] = test_value[0]
         new_asset = Asset(**self.kwargs)
         self.assertEqual(new_asset.name, test_value[1])
Пример #5
0
 def test_code_argument_is_not_unique(self):
     """testing if an IntegrityError will be raised when the code argument
     is not unique
     """
     self.kwargs["name"] = "Another_Asset_Name"
     new_asset = Asset(**self.kwargs)
     self.assertRaises(IntegrityError, new_asset.save)
Пример #6
0
 def test_type_argument_is_None(self):
     """testing if setting the type argument to None will set the type
     attribute to conf.default_asset_type_name
     """
     self.kwargs['type'] = None
     new_asset = Asset(**self.kwargs)
     self.assertEqual(new_asset.type, conf.default_asset_type_name)
Пример #7
0
 def test_code_argument_formatting(self):
     """testing if the code argument is formatted correctly
     """
     for test_value in self._code_test_values:
         self.kwargs["code"] = test_value[0]
         new_asset = Asset(**self.kwargs)
         self.assertEqual(new_asset.code, test_value[1])
Пример #8
0
 def test_type_argument_is_skipped(self):
     """testing if skipping the type argument the type attribute will be set
     to conf.default_asset_type_name
     """
     self.kwargs.pop('type')
     new_asset = Asset(**self.kwargs)
     self.assertEqual(new_asset.type, conf.default_asset_type_name)
Пример #9
0
 def test_name_argument_is_working_properly(self):
     """test if the name attribute initialized correctly with the value of
     the name argument
     """
     test_value = "Test Value"
     self.kwargs["name"] = test_value
     new_asset = Asset(**self.kwargs)
     self.assertEqual(new_asset.name, test_value)
Пример #10
0
 def test_type_argument_formatting(self):
     """testing if the type argument is formatted correctly
     """
     for test_values in self._code_test_values:
         input_value = test_values[0]
         expected_value = test_values[1]
         self.kwargs['type'] = input_value
         new_asset = Asset(**self.kwargs)
         self.assertEqual(new_asset.type, expected_value)
Пример #11
0
 def test_code_argument_is_None(self):
     """testing if the code attribute will be get from the name attribute if
     the code argument is None
     """
     self.kwargs["name"] = "Test Value"
     self.kwargs["code"] = None
     expected_value = "Test_Value"
     new_asset = Asset(**self.kwargs)
     self.assertEqual(new_asset.code, expected_value)
Пример #12
0
    def test_inequality_of_assets(self):
        """testing if two assets are inequal if their names are different and
        or their projects are different
        """

        proj1 = Project("EQUALITY_TEST_PROJECT_1")
        proj1.create()

        proj2 = Project("EQUALITY_TEST_PROJECT_2")
        proj2.create()

        asset1 = Asset(proj1, "TEST_ASSET1")
        asset2 = Asset(proj1, "TEST_ASSET1")

        asset3 = Asset(proj1, "TEST_ASSET3")
        asset4 = Asset(proj2, "TEST_ASSET3")

        self.assertFalse(asset1 != asset2)
        self.assertTrue(asset1 != asset3)
        self.assertTrue(asset3 != asset4)
Пример #13
0
    def test_equality_of_assets(self):
        """testing if two assets are equal if their names and projects are also
        equal
        """

        proj1 = Project("EQUALITY_TEST_PROJECT_1")
        proj1.create()

        proj2 = Project("EQUALITY_TEST_PROJECT_2")
        proj2.create()

        asset1 = Asset(proj1, "TEST_ASSET1")
        asset2 = Asset(proj1, "TEST_ASSET1")

        asset3 = Asset(proj1, "TEST_ASSET3")
        asset4 = Asset(proj2, "TEST_ASSET3")

        self.assertTrue(asset1 == asset2)
        self.assertFalse(asset1 == asset3)
        self.assertFalse(asset3 == asset4)
Пример #14
0
    def setUp(self):
        """setup the test settings with environment variables
        """
        # -----------------------------------------------------------------
        # 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

        self.test_proj = Project("TEST_PROJ1")
        self.test_proj.create()

        self.kwargs = {
            "project": self.test_proj,
            "name": "Test Asset",
            "code": "TEST_ASSET",
            'type': 'Prop',
        }

        self.test_asset = Asset(**self.kwargs)
        self.test_asset.save()

        self._name_test_values = [
            ("Test Asset", "Test Asset"),
            ("23Test_Asset", "23Test_Asset"),
            ("TEST_ASSET", "TEST_ASSET"),
            ("£#$£#$AB", "AB"),
            ("'^+'^%^+%&&AB3£#$£½'^+'3'^+'4", "AB334"),
            ("afasfas fasf asdf67", "Afasfas fasf asdf67"),
            ("45a", "45a"),
            ("45acafs", "45acafs"),
            ("45'^+'^+a 234", "45a 234"),
            ("45asf78wr", "45asf78wr"),
            ("'^+'afsd2342'^+'asdFGH", "Afsd2342asdFGH"),
        ]

        self._code_test_values = [
            ("Test Asset", "Test_Asset"),
            ("23Test_Asset", "23Test_Asset"),
            ("TEST_ASSET", "TEST_ASSET"),
            ("£#$£#$AB", "AB"),
            ("'^+'^%^+%&&AB3£#$£½'^+'3'^+'4", "AB334"),
            ("afasfas fasf asdf67", "Afasfas_fasf_asdf67"),
            ("45a", "45a"),
            ("45acafs", "45acafs"),
            ("45'^+'^+a 234", "45a_234"),
            ("45asf78wr", "45asf78wr"),
            ("'^+'afsd2342'^+'asdFGH", "Afsd2342asdFGH"),
        ]
Пример #15
0
    def test_deleting_an_asset_will_not_delete_the_related_project(self):
        """testing if deleting an asset will not delete the related project
        """
        proj1 = Project('test project 1')
        proj1.save()

        asset = Asset(proj1, 'Test asset')
        asset.save()

        # check if they are in the session
        self.assertIn(proj1, db.session)
        self.assertIn(asset, db.session)

        # delete the asset
        db.session.delete(asset)
        db.session.commit()

        # check if it is removed from the session
        self.assertNotIn(asset, db.session)

        # and the project is there
        self.assertIn(proj1, db.session)
Пример #16
0
    def test_deleting_an_asset_will_delete_all_the_related_versions_but_keep_references(
            self):
        """testing if deleting an asset will only delete the version of that
        asset and will keep the referenced versions.
        """
        proj1 = Project('test project 1')
        proj1.save()

        asset1 = Asset(proj1, 'test asset 1')
        asset1.save()

        asset2 = Asset(proj1, 'test asset 2')
        asset2.save()

        asset_vtypes = VersionType.query().filter_by(type_for="Asset").all()

        user = User.query().first()

        vers1 = Version(version_of=asset1,
                        base_name=asset1.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers1.save()

        vers2 = Version(version_of=asset1,
                        base_name=asset1.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers2.save()

        vers3 = Version(version_of=asset1,
                        base_name=asset1.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers3.save()

        vers4 = Version(version_of=asset2,
                        base_name=asset2.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers4.save()

        vers5 = Version(version_of=asset2,
                        base_name=asset2.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers5.save()

        vers6 = Version(version_of=asset2,
                        base_name=asset2.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers6.save()

        # reference vers4, vers5 and vers6 to vers1, vers2 and vers3
        vers1.references.append(vers4)
        vers1.references.append(vers5)
        vers1.references.append(vers6)

        vers2.references.append(vers4)
        vers2.references.append(vers5)
        vers2.references.append(vers6)

        vers3.references.append(vers4)
        vers3.references.append(vers5)
        vers3.references.append(vers6)

        # check if all are in the session
        self.assertIn(proj1, db.session)
        self.assertIn(asset1, db.session)
        self.assertIn(asset2, db.session)
        self.assertIn(vers1, db.session)
        self.assertIn(vers2, db.session)
        self.assertIn(vers3, db.session)
        self.assertIn(vers4, db.session)
        self.assertIn(vers5, db.session)
        self.assertIn(vers6, db.session)

        # there should be 9 entries in the secondary table
        result = db.session\
            .query('referencer_id', 'reference_id')\
            .from_statement("SELECT referencer_id, reference_id "
                            "FROM Version_References").all()
        self.assertEqual(len(result), 9)

        # delete the asset
        db.session.delete(asset1)
        db.session.commit()

        # check if it is not in the session anymore
        self.assertNotIn(asset1, db.session)

        # check if the versions are also deleted
        self.assertNotIn(vers1, db.session)
        self.assertNotIn(vers2, db.session)
        self.assertNotIn(vers3, db.session)

        # check if the others are still there
        self.assertIn(proj1, db.session)
        self.assertIn(asset2, db.session)
        self.assertIn(vers4, db.session)
        self.assertIn(vers5, db.session)
        self.assertIn(vers6, db.session)

        # to be sure check the secondary table
        result = db.session\
            .query('referencer_id', 'reference_id')\
            .from_statement("SELECT referencer_id, reference_id "
                            "FROM Version_References").all()
        self.assertEqual(len(result), 0)
Пример #17
0
    def test_deleting_an_asset_will_delete_all_the_related_versions(self):
        """testing if deleting an asset will also delete the related versions
        """
        proj1 = Project('test project 1')
        proj1.save()

        asset1 = Asset(proj1, 'test asset 1')
        asset1.save()

        asset2 = Asset(proj1, 'test asset 2')
        asset2.save()

        asset_vtypes = VersionType.query().filter_by(type_for="Asset").all()

        user = User.query().first()

        vers1 = Version(version_of=asset1,
                        base_name=asset1.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers1.save()

        vers2 = Version(version_of=asset1,
                        base_name=asset1.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers2.save()

        vers3 = Version(version_of=asset1,
                        base_name=asset1.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers3.save()

        vers4 = Version(version_of=asset2,
                        base_name=asset2.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers4.save()

        vers5 = Version(version_of=asset2,
                        base_name=asset2.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers5.save()

        vers6 = Version(version_of=asset2,
                        base_name=asset2.code,
                        type=asset_vtypes[0],
                        created_by=user)
        vers6.save()

        # check if all are in the session
        self.assertIn(proj1, db.session)
        self.assertIn(asset1, db.session)
        self.assertIn(asset2, db.session)
        self.assertIn(vers1, db.session)
        self.assertIn(vers2, db.session)
        self.assertIn(vers3, db.session)
        self.assertIn(vers4, db.session)
        self.assertIn(vers5, db.session)
        self.assertIn(vers6, db.session)

        # delete the asset
        db.session.delete(asset1)
        db.session.commit()

        # check if it is not in the session anymore
        self.assertNotIn(asset1, db.session)

        # check if the versions are also deleted
        self.assertNotIn(vers1, db.session)
        self.assertNotIn(vers2, db.session)
        self.assertNotIn(vers3, db.session)

        # check if the others are still there
        self.assertIn(proj1, db.session)
        self.assertIn(asset2, db.session)
        self.assertIn(vers4, db.session)
        self.assertIn(vers5, db.session)
        self.assertIn(vers6, db.session)
Пример #18
0
 def _createAssetObjectFromOpenFields(self):
     """retriewes the file name from the open asset fields
     """
     assetFileName = unicode(self.assetFile_comboBox.currentText())
     self._asset = Asset(self._project, self._sequence, assetFileName)
     self._environment.asset = self._asset
Пример #19
0
 def test_type_argument_is_working_properly(self):
     """testing if the type attribute is set with the type argument
     """
     self.kwargs['type'] = "Test_Type_1"
     new_asset = Asset(**self.kwargs)
     self.assertEqual(self.kwargs['type'], new_asset.type)
Пример #20
0
 def test_code_argument_is_working_properly(self):
     """testing if the code attribute is set from the code argument
     """
     self.kwargs["code"] = "TEST_VALUE"
     new_asset = Asset(**self.kwargs)
     self.assertEqual(new_asset.code, self.kwargs["code"])
Пример #21
0
 def test_name_argument_is_not_unique(self):
     """testing if a IntegrityError will be raised when the name is unique
     """
     # create an asset with the same name
     new_asset = Asset(**self.kwargs)
     self.assertRaises(IntegrityError, new_asset.save)