def find_repo(cls, path): """returns the repository from the given path :param str path: path in a repository :return: stalker.models.repository.Repository """ # first find the repository from stalker import Repository return Repository.find_repo(path)
def test_find_repo_is_working_properly(self): """testing if the find_repo class method is working properly """ from stalker.db.session import DBSession DBSession.add(self.test_repo) DBSession.commit() # add some other repositories from stalker import Repository new_repo1 = Repository(name='New Repository', linux_path='/mnt/T/Projects', osx_path='/Volumes/T/Projects', windows_path='T:/Projects') DBSession.add(new_repo1) DBSession.commit() test_path = '%s/some/path/to/a/file.ma' % self.test_repo.path assert Repository.find_repo(test_path) == self.test_repo test_path = '%s/some/path/to/a/file.ma' % new_repo1.windows_path assert Repository.find_repo(test_path) == new_repo1
def test_find_repo_is_working_properly_with_env_vars(self): """testing if the find_repo class method is working properly with paths containing env vars """ from stalker import db db.setup() db.DBSession.add(self.test_repo) db.DBSession.commit() # add some other repositories new_repo1 = Repository(name='New Repository', linux_path='/mnt/T/Projects', osx_path='/Volumes/T/Projects', windows_path='T:/Projects') db.DBSession.add(new_repo1) db.DBSession.commit() test_path = '$REPO%s/some/path/to/a/file.ma' % self.test_repo.id self.assertEqual(Repository.find_repo(test_path), self.test_repo) test_path = '$REPO%s/some/path/to/a/file.ma' % new_repo1.id self.assertEqual(Repository.find_repo(test_path), new_repo1)