From 52c9335218635d5e79717356cfd907cb368ca353 Mon Sep 17 00:00:00 2001 From: Erkan Ozgur Yilmaz Date: Wed, 1 Jan 2020 12:40:28 +0300 Subject: [PATCH] * **New:** ``Repository`` instances now have a ``code`` attribute which is used for generating the environment variables where in previous versions the ``id`` attribute has been used which caused difficulties in transferring the data to a different installation of Stalker. Also to make the system backwards compatible, Stalker will still set the old ``id`` based environment variables. But when asked for an environment variable it will return the ``code`` based one. The ``code`` argument as usual has to be initialized on ``Repository`` instance creation. That's why this version is slightly backwards incompatible and needs the database to be updated with Alembic (with the command ``alembic update head``). --- CHANGELOG.rst | 14 ++ alembic.ini | 2 +- ...7e6a234b4_added_revision_code_attribute.py | 42 ++++ docs/source/tutorial.rst | 11 +- docs/source/tutorial_files/tutorial.py | 3 +- stalker/config.py | 3 +- stalker/db/__init__.py | 7 +- stalker/models/repository.py | 72 +++++-- tests/benchmarks/task_total_logged_seonds.py | 1 + tests/db/test_db.py | 45 +++-- tests/mixins/test_declarativeProjectMixin.py | 5 +- tests/mixins/test_projectMixin.py | 1 + tests/models/test_asset.py | 1 + tests/models/test_budget.py | 1 + tests/models/test_client.py | 3 +- tests/models/test_daily.py | 4 +- tests/models/test_entity_group.py | 1 + tests/models/test_invoice.py | 13 +- tests/models/test_payment.py | 1 + tests/models/test_project.py | 10 +- tests/models/test_project_client.py | 3 +- tests/models/test_project_user.py | 3 +- tests/models/test_repository.py | 182 ++++++++++++++---- tests/models/test_review.py | 1 + tests/models/test_scene.py | 1 + tests/models/test_sequence.py | 1 + tests/models/test_shot.py | 1 + tests/models/test_simple_entity.py | 3 +- tests/models/test_studio.py | 1 + tests/models/test_task.py | 2 + tests/models/test_taskJuggler_scheduler.py | 1 + tests/models/test_task_dependency.py | 3 +- tests/models/test_task_status_workflow.py | 2 + tests/models/test_ticket.py | 2 +- tests/models/test_time_log.py | 2 +- tests/models/test_user.py | 1 + tests/models/test_version.py | 2 + tests/models/test_wiki.py | 1 + tests/test_readme_tutorial.py | 1 + 39 files changed, 367 insertions(+), 86 deletions(-) create mode 100644 alembic/versions/bf67e6a234b4_added_revision_code_attribute.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1b1a688..df0ac8d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,20 @@ Stalker Changes =============== +0.2.24 +====== + +* **New:** ``Repository`` instances now have a ``code`` attribute which is + used for generating the environment variables where in previous versions the + ``id`` attribute has been used which caused difficulties in transferring the + data to a different installation of Stalker. Also to make the system + backwards compatible, Stalker will still set the old ``id`` based environment + variables. But when asked for an environment variable it will return the + ``code`` based one. The ``code`` argument as usual has to be initialized on + ``Repository`` instance creation. That's why this version is slightly + backwards incompatible and needs the database to be updated with Alembic + (with the command ``alembic update head``). + 0.2.23 ====== diff --git a/alembic.ini b/alembic.ini index 0d86549..90e709d 100644 --- a/alembic.ini +++ b/alembic.ini @@ -12,7 +12,7 @@ script_location = alembic # revision_environment = false #sqlalchemy.url = sqlite:///%(here)s/stalker.db -sqlalchemy.url = postgresql://stalker_admin:stalker@localhost:5432/stalker +sqlalchemy.url = postgresql://stalker_admin:stalker@localhost:5432/stalker_home # Logging configuration diff --git a/alembic/versions/bf67e6a234b4_added_revision_code_attribute.py b/alembic/versions/bf67e6a234b4_added_revision_code_attribute.py new file mode 100644 index 0000000..bc4bb57 --- /dev/null +++ b/alembic/versions/bf67e6a234b4_added_revision_code_attribute.py @@ -0,0 +1,42 @@ +"""Added Revision.code attribute + +Revision ID: bf67e6a234b4 +Revises: ed0167fff399 +Create Date: 2020-01-01 09:50:19.086342 + +""" + +# revision identifiers, used by Alembic. +revision = 'bf67e6a234b4' +down_revision = 'ed0167fff399' + +from alembic import op +import sqlalchemy as sa + +import logging +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) + + +def upgrade(): + # add the column + logger.info("creating code column in Repositories table") + op.add_column( + 'Repositories', + sa.Column('code', sa.String(length=256), nullable=True) + ) + + # copy the name as code + logger.info("filling data to the code column in Repositories table from Repositories.name column") + op.execute("""UPDATE "Repositories" +SET code = ( + SELECT REGEXP_REPLACE(name, '\s+', '') from "SimpleEntities" where id="Repositories".id +) +""") + logger.info("set code column to not nullable") + op.alter_column('Repositories', 'code', nullable=False) + + +def downgrade(): + logger.info("removing code column from Repositories table") + op.drop_column('Repositories', 'code') diff --git a/docs/source/tutorial.rst b/docs/source/tutorial.rst index a8b04c8..744e5d8 100644 --- a/docs/source/tutorial.rst +++ b/docs/source/tutorial.rst @@ -229,9 +229,18 @@ workstations/render farmers:: # and the repository itself commercial_repo = Repository( - name="Commercial Repository" + name="Commercial Repository", + code="CR" ) +.. versionadded:: 0.2.24 + + Starting with Stalker version 0.2.24 :class:`.Repository` instances have + :attr:`stalker.models.repository.Repository.code` attribute to help + generating universal paths (both across OSes and different installations of + Stalker). + + :class:`.Repository` class will be explained in detail in upcoming sections. So:: diff --git a/docs/source/tutorial_files/tutorial.py b/docs/source/tutorial_files/tutorial.py index d4b5f62..e01761e 100644 --- a/docs/source/tutorial_files/tutorial.py +++ b/docs/source/tutorial_files/tutorial.py @@ -78,7 +78,8 @@ # and the repository itself commercial_repo = Repository( - name="Commercial Repository" + name="Commercial Repository", + code="CR" ) new_project = Project( diff --git a/stalker/config.py b/stalker/config.py index 17ce851..8877f87 100644 --- a/stalker/config.py +++ b/stalker/config.py @@ -136,7 +136,8 @@ class Config(ConfigBase): # Storage for uploaded files server_side_storage_path=os.path.expanduser('~/Stalker_Storage'), - repo_env_var_template='REPO%(id)s', + repo_env_var_template='REPO%(code)s', + repo_env_var_template_old='REPO%(id)s', # # Tells Stalker to create an admin by default diff --git a/stalker/db/__init__.py b/stalker/db/__init__.py index f0f134e..33323a2 100644 --- a/stalker/db/__init__.py +++ b/stalker/db/__init__.py @@ -191,7 +191,12 @@ def create_repo_vars(): from stalker import defaults, Repository all_repos = Repository.query.all() for repo in all_repos: - os.environ[defaults.repo_env_var_template % {'id': repo.id}] = \ + os.environ[repo.env_var] = repo.path + + # TODO: Remove this in upcoming versions. + # This is added for backwards compatibility + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id}] = \ repo.path diff --git a/stalker/models/repository.py b/stalker/models/repository.py index 89fbdde..2222156 100644 --- a/stalker/models/repository.py +++ b/stalker/models/repository.py @@ -21,6 +21,7 @@ from sqlalchemy import event, Column, Integer, ForeignKey, String from sqlalchemy.orm import validates from stalker.models.entity import Entity +from stalker.models.mixins import CodeMixin from stalker.log import logging_level import logging @@ -29,7 +30,7 @@ logger.setLevel(logging_level) -class Repository(Entity): +class Repository(Entity, CodeMixin): """Manages fileserver/repository related data. A repository is a network share that all users have access to. @@ -44,6 +45,27 @@ class Repository(Entity): Setting a path that contains backward slashes ("\\"), will be converted to a path with forward slashes. + .. versionadded:: 0.2.24 + Code attribute + + Starting with v0.2.24 Repository instances have a new :attr:`.code` + attribute whose value is used by the + :class:`stalker.models.studio.Studio` to generate environment variables + that contains the path of this + :class:`stalker.models.repository.Repository` (i.e. + $REPOCP/path/to/asset.ma ``CP`` here is the ``Repository.code``) so that + instead of using absolute full paths one can use the + :attr:`.make_relative`` path to generate a universal path that can be + used across OSes and different installations of Stalker. + + :param code: The code of the :class:`stalker.models.repository.Repository`. + This attribute value is used by the :class:`stalker.models.studio.Studio` + to generate environment variables that contains the path of this + ``Repository`` (i.e. $REPOCP/path/to/asset.ma) so that instead of using + absolute full paths one can use the ``repository_relative`` path to + generate a universal path that can be used across OSes and different + installations of Stalker. + :param linux_path: shows the linux path of the repository root, should be a string @@ -84,11 +106,14 @@ class Repository(Entity): osx_path = Column(String(256)) # / def __init__(self, + code="", linux_path="", windows_path="", osx_path="", **kwargs): + kwargs['code'] = code super(Repository, self).__init__(**kwargs) + CodeMixin.__init__(self, **kwargs) self.linux_path = linux_path self.windows_path = windows_path @@ -109,11 +134,19 @@ def _validate_linux_path(self, key, linux_path): linux_path = linux_path.replace("\\", "/") + if self.code is not None and platform.system() == "Linux": + # update the environment variable + from stalker import defaults + os.environ[ + defaults.repo_env_var_template % {'code': self.code} + ] = linux_path + if self.id is not None and platform.system() == "Linux": # update the environment variable from stalker import defaults - os.environ[defaults.repo_env_var_template % {'id': self.id}] = \ - linux_path + os.environ[ + defaults.repo_env_var_template_old % {'id': self.id} + ] = linux_path return linux_path @@ -132,14 +165,19 @@ def _validate_osx_path(self, key, osx_path): osx_path = osx_path.replace("\\", "/") - if self.id is not None and platform.system() == "Darwin": + from stalker import defaults + if self.code is not None and platform.system() == "Darwin": # update the environment variable - from stalker import defaults - os.environ[defaults.repo_env_var_template % {'id': self.id}] = \ - osx_path + os.environ[ + defaults.repo_env_var_template % {'code': self.code} + ] = osx_path - return osx_path + if self.id is not None and platform.system() == "Darwin": + os.environ[ + defaults.repo_env_var_template_old % {'id': self.id} + ] = osx_path + return osx_path @validates("windows_path") def _validate_windows_path(self, key, windows_path): @@ -158,11 +196,19 @@ def _validate_windows_path(self, key, windows_path): if not windows_path.endswith('/'): windows_path += '/' + if self.code is not None and platform.system() == "Windows": + # update the environment variable + from stalker import defaults + os.environ[ + defaults.repo_env_var_template % {'code': self.code} + ] = windows_path + if self.id is not None and platform.system() == "Windows": # update the environment variable from stalker import defaults - os.environ[defaults.repo_env_var_template % {'id': self.id}] = \ - windows_path + os.environ[ + defaults.repo_env_var_template_old % {'id': self.id} + ] = windows_path return windows_path @@ -325,7 +371,7 @@ def env_var(self): """returns the env var of this repo """ from stalker import defaults - return defaults.repo_env_var_template % {'id': self.id} + return defaults.repo_env_var_template % {'code': self.code} def __eq__(self, other): """the equality operator @@ -348,4 +394,6 @@ def receive_after_insert(mapper, connection, repo): """ logger.debug('auto creating env var for Repository with id: %s' % repo.id) from stalker import defaults - os.environ[defaults.repo_env_var_template % {'id': repo.id}] = repo.path + os.environ[defaults.repo_env_var_template % {'code': repo.id}] = repo.path + os.environ[defaults.repo_env_var_template_old % + {'id': repo.id}] = repo.path diff --git a/tests/benchmarks/task_total_logged_seonds.py b/tests/benchmarks/task_total_logged_seonds.py index ec1a272..dec779b 100644 --- a/tests/benchmarks/task_total_logged_seonds.py +++ b/tests/benchmarks/task_total_logged_seonds.py @@ -88,6 +88,7 @@ test_repository = Repository( name="Test Repository", + code="TR", type=test_repository_type, linux_path='/mnt/T/', windows_path='T:/', diff --git a/tests/db/test_db.py b/tests/db/test_db.py index 5e9b356..b2e8c12 100644 --- a/tests/db/test_db.py +++ b/tests/db/test_db.py @@ -907,9 +907,9 @@ def test_initialization_of_repo_environment_variables(self): """ # create a couple of repositories from stalker import db, Repository - repo1 = Repository(name='Repo1') - repo2 = Repository(name='Repo2') - repo3 = Repository(name='Repo3') + repo1 = Repository(name='Repo1', code='R1') + repo2 = Repository(name='Repo2', code='R2') + repo3 = Repository(name='Repo3', code='R3') all_repos = [repo1, repo2, repo3] from stalker.db.session import DBSession @@ -920,14 +920,14 @@ def test_initialization_of_repo_environment_variables(self): import os for repo in all_repos: try: - os.environ.pop('REPO%s' % repo.id) + os.environ.pop('REPO%s' % repo.code) except KeyError: pass # check if all removed for repo in all_repos: # check if environment vars are created - assert ('REPO%s' % repo.id) not in os.environ + assert ('REPO%s' % repo.code) not in os.environ # remove db connection DBSession.remove() @@ -939,7 +939,7 @@ def test_initialization_of_repo_environment_variables(self): for repo in all_repos: # check if environment vars are created - assert ('REPO%s' % repo.id) in os.environ + assert ('REPO%s' % repo.code) in os.environ def test_db_init_with_studio_instance(self): """testing db.init() using existing Studio instance for config values @@ -1121,6 +1121,7 @@ def test_persistence_of_Asset(self): test_repository = Repository( name='Test Repository A', + code='TRA', type=test_repository_type ) @@ -1266,6 +1267,7 @@ def test_persistence_of_Budget_and_BudgetEntry(self): from stalker import Repository test_repository = Repository( name='Test Repository A', + code='TRA', type=test_repository_type ) @@ -1403,6 +1405,7 @@ def test_persistence_of_Invoice(self): from stalker import Repository test_repository = Repository( name='Test Repository A', + code='TRA', type=test_repository_type ) @@ -1548,6 +1551,7 @@ def test_persistence_of_Payment(self): from stalker import Repository test_repository = Repository( name='Test Repository A', + code='TRA', type=test_repository_type ) @@ -1702,6 +1706,7 @@ def test_persistence_of_Page(self): from stalker import Repository test_repository = Repository( name='Test Repository A', + code='TRA', type=test_repository_type ) @@ -1822,6 +1827,7 @@ def test_persistence_of_TimeLog(self): from stalker import Repository repo = Repository( name='Commercials Repository', + code='CR', linux_path='/mnt/shows', windows_path='S:/', osx_path='/mnt/shows' @@ -1914,6 +1920,7 @@ def test_persistence_of_TimeLog_raw_sql(self): from stalker import Repository repo = Repository( name='Commercials Repository', + code='CR', linux_path='/mnt/shows', windows_path='S:/', osx_path='/mnt/shows' @@ -2145,7 +2152,7 @@ def test_persistence_of_Daily(self): ) from stalker import Repository, Project - test_repo = Repository(name='Test Repository') + test_repo = Repository(name='Test Repository', code='TR') test_project = Project( name='Test Project', code='TP', @@ -2546,6 +2553,7 @@ def test_persistence_of_EntityGroup(self): from stalker import Repository repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/M/JOBs', windows_path='M:/JOBs', osx_path='/Users/Shared/Servers/M', @@ -2826,7 +2834,7 @@ def test_persistence_of_Link(self): # use it as a task reference from stalker import Repository, Project, Task - repo1 = Repository(name='test repo') + repo1 = Repository(name='test repo', code='TR') project1 = Project( name='Test Project 1', @@ -3154,6 +3162,7 @@ def test_persistence_of_Project(self): repo = Repository( name="Commercials Repository", + code='CR', linux_path="/mnt/M/Projects", windows_path="M:/Projects", osx_path="/mnt/M/Projects" @@ -3354,6 +3363,7 @@ def test_persistence_of_Repository(self): # create a new Repository object and try to read it back kwargs = { "name": "Movie-Repo", + "code": "MR", "description": "test repository", "linux_path": "/mnt/M", "osx_path": "/mnt/M", @@ -3371,6 +3381,7 @@ def test_persistence_of_Repository(self): # store attributes created_by = repo.created_by + code = repo.code date_created = repo.date_created date_updated = repo.date_updated description = repo.description @@ -3395,6 +3406,7 @@ def test_persistence_of_Repository(self): assert (isinstance(repo_db, Repository)) assert repo_db.created_by == created_by + assert repo_db.code == code assert repo_db.date_created == date_created assert repo_db.date_updated == date_updated assert repo_db.description == description @@ -3413,7 +3425,8 @@ def test_persistence_of_Scene(self): """ from stalker import Repository, User, Type, Project repo1 = Repository( - name="Commercial Repository" + name="Commercial Repository", + code='CR', ) user1 = User( @@ -3509,7 +3522,8 @@ def test_persistence_of_Sequence(self): """ from stalker import Project, Repository, Type, User repo1 = Repository( - name="Commercial Repository" + name="Commercial Repository", + code='CR' ) commercial_project_type = Type( @@ -3639,7 +3653,8 @@ def test_persistence_of_Shot(self): ) repo1 = Repository( - name="Commercial Repository" + name="Commercial Repository", + code='CR' ) lead = User( @@ -4189,6 +4204,7 @@ def test_persistence_of_Task(self): from stalker import Repository, Project repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/M/JOBs', windows_path='M:/JOBs', osx_path='/Users/Shared/Servers/M', @@ -4452,6 +4468,7 @@ def test_persistence_of_Review(self): from stalker import Repository repo = Repository( name='Test Repo', + code='TR', linux_path='/some/random/path', windows_path='/some/random/path', osx_path='/some/random/path', @@ -4618,7 +4635,8 @@ def test_persistence_of_Ticket(self): """ from stalker import Repository repo = Repository( - name='Test Repository' + name='Test Repository', + code='TR' ) from stalker import Structure @@ -4803,7 +4821,7 @@ def test_persistence_of_User(self): # create a test project from stalker import Repository - repo1 = Repository(name='Test Repo') + repo1 = Repository(name='Test Repo', code='TR') from stalker import Project, Task, TimeLog project1 = Project( name='Test Project', @@ -5031,6 +5049,7 @@ def test_persistence_of_Version(self): code='tp', repository=Repository( name='Film Projects', + code='FP', windows_path='M:/', linux_path='/mnt/M/', osx_path='/Users/Volumes/M/', diff --git a/tests/mixins/test_declarativeProjectMixin.py b/tests/mixins/test_declarativeProjectMixin.py index ee0e4c0..30d4cd1 100644 --- a/tests/mixins/test_declarativeProjectMixin.py +++ b/tests/mixins/test_declarativeProjectMixin.py @@ -77,17 +77,18 @@ def setUp(self): self.test_project_statuses = StatusList( name="Project Statuses", statuses=[self.test_stat2, self.test_stat3], - target_entity_type=Project + target_entity_type='Project' ) self.test_project_type = Type( name='Test Project Type', code='testproj', - target_entity_type=Project, + target_entity_type='Project', ) self.test_repository = Repository( name="Test Repo", + code='TR', ) self.test_project = Project( diff --git a/tests/mixins/test_projectMixin.py b/tests/mixins/test_projectMixin.py index 5654abc..7ca6306 100644 --- a/tests/mixins/test_projectMixin.py +++ b/tests/mixins/test_projectMixin.py @@ -53,6 +53,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code='TR', type=self.repository_type, ) diff --git a/tests/models/test_asset.py b/tests/models/test_asset.py index 1b6ff68..0c5accf 100644 --- a/tests/models/test_asset.py +++ b/tests/models/test_asset.py @@ -87,6 +87,7 @@ def setUp(self): from stalker import Repository self.repository = Repository( name="Test Repository", + code='TR', type=self.repository_type, ) DBSession.add(self.repository) diff --git a/tests/models/test_budget.py b/tests/models/test_budget.py index 6ec9f5e..e99c209 100644 --- a/tests/models/test_budget.py +++ b/tests/models/test_budget.py @@ -91,6 +91,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code='TR', type=self.test_repository_type, linux_path='/mnt/T/', windows_path='T:/', diff --git a/tests/models/test_client.py b/tests/models/test_client.py index 4cd1aa0..d7795e8 100644 --- a/tests/models/test_client.py +++ b/tests/models/test_client.py @@ -93,7 +93,8 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( - name="Test Repository" + name="Test Repository", + code="TR" ) from stalker import Project diff --git a/tests/models/test_daily.py b/tests/models/test_daily.py index 82c8615..43c6bea 100644 --- a/tests/models/test_daily.py +++ b/tests/models/test_daily.py @@ -64,7 +64,7 @@ def setUp(self): ) from stalker import Repository, Project - self.test_repo = Repository(name='Test Repository') + self.test_repo = Repository(name='Test Repository', code='TR') self.test_project = Project( name='Test Project', @@ -264,7 +264,7 @@ def setUp(self): StatusList.query.filter_by(target_entity_type='Task').first() from stalker import Repository, Project - self.test_repo = Repository(name='Test Repository') + self.test_repo = Repository(name='Test Repository', code='TR') from stalker.db.session import DBSession DBSession.add(self.test_repo) diff --git a/tests/models/test_entity_group.py b/tests/models/test_entity_group.py index a83b074..3f3fc6c 100644 --- a/tests/models/test_entity_group.py +++ b/tests/models/test_entity_group.py @@ -71,6 +71,7 @@ def setUp(self): self.repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/M/JOBs', windows_path='M:/JOBs', osx_path='/Users/Shared/Servers/M', diff --git a/tests/models/test_invoice.py b/tests/models/test_invoice.py index 3a876d1..a4c6f52 100644 --- a/tests/models/test_invoice.py +++ b/tests/models/test_invoice.py @@ -74,18 +74,19 @@ def setUp(self): self.test_movie_project_type = Type( name="Movie Project", code='movie', - target_entity_type=Project, + target_entity_type='Project', ) from stalker import Repository self.test_repository_type = Type( name="Test Repository Type", code='test', - target_entity_type=Repository, + target_entity_type='Repository', ) self.test_repository = Repository( name="Test Repository", + code='TR', type=self.test_repository_type, ) @@ -182,7 +183,7 @@ def test_budget_argument_is_None(self): """ from stalker import Invoice with pytest.raises(TypeError) as cm: - test_invoice = Invoice( + Invoice( budget=None, client=self.test_client, amount=1500, @@ -215,7 +216,7 @@ def test_budget_argument_is_not_a_budget_instance(self): """ from stalker import Invoice with pytest.raises(TypeError) as cm: - test_invoice = Invoice( + Invoice( budget='Not a budget instance', client=self.test_client, amount=1500, @@ -276,7 +277,7 @@ def test_client_argument_is_None(self): """ from stalker import Invoice with pytest.raises(TypeError) as cm: - test_invoice = Invoice( + Invoice( budget=self.test_budget, client=None, amount=100, @@ -309,7 +310,7 @@ def test_client_argument_is_not_a_client_instance(self): """ from stalker import Invoice with pytest.raises(TypeError) as cm: - test_invoice = Invoice( + Invoice( budget=self.test_budget, client='not a client instance', amount=100, diff --git a/tests/models/test_payment.py b/tests/models/test_payment.py index a49f69c..582473d 100644 --- a/tests/models/test_payment.py +++ b/tests/models/test_payment.py @@ -86,6 +86,7 @@ def setUp(self): self.test_repository = Repository( name="Test Repository", + code='TR', type=self.test_repository_type, ) diff --git a/tests/models/test_project.py b/tests/models/test_project.py index 97117ec..52fc7b8 100644 --- a/tests/models/test_project.py +++ b/tests/models/test_project.py @@ -179,10 +179,12 @@ def setUp(self): from stalker import Repository self.test_repo1 = Repository( name="Commercials Repository 1", + code="CR1", ) self.test_repo2 = Repository( name="Commercials Repository 2", + code="CR2" ) from stalker import Client @@ -921,6 +923,7 @@ def test_repositories_attribute_is_working_properly(self): from stalker import Repository new_repo1 = Repository( name='Some Random Repo', + code='SRP', linux_path='/mnt/S/random/repo', windows_path='S:/random/repo', osx_path='/Volumes/S/random/repo' @@ -934,9 +937,9 @@ def test_repositories_attribute_value_order_is_not_changing(self): """testing if the order of the repositories attribute is not changing """ from stalker import Repository, Project - repo1 = Repository(name='Repo1') - repo2 = Repository(name='Repo2') - repo3 = Repository(name='Repo3') + repo1 = Repository(name='Repo1', code='R1') + repo2 = Repository(name='Repo2', code='R1') + repo3 = Repository(name='Repo3', code='R1') from stalker.db.session import DBSession DBSession.add_all([repo1, repo2, repo3]) @@ -2107,6 +2110,7 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( name="Commercials Repository", + code="CR", ) # create a project object diff --git a/tests/models/test_project_client.py b/tests/models/test_project_client.py index 59c4980..163ccea 100644 --- a/tests/models/test_project_client.py +++ b/tests/models/test_project_client.py @@ -32,7 +32,8 @@ def setUp(self): from stalker import Status, Repository self.test_repo = Repository( - name='Test Repo' + name='Test Repo', + code='TR' ) self.status_new = Status(name='New', code='NEW') self.status_wip = Status(name='Work In Progress', code='WIP') diff --git a/tests/models/test_project_user.py b/tests/models/test_project_user.py index f180bf9..d635337 100644 --- a/tests/models/test_project_user.py +++ b/tests/models/test_project_user.py @@ -32,7 +32,8 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( - name='Test Repo' + name='Test Repo', + code='TR' ) from stalker.db.session import DBSession diff --git a/tests/models/test_repository.py b/tests/models/test_repository.py index b3d6ba1..eea01b0 100644 --- a/tests/models/test_repository.py +++ b/tests/models/test_repository.py @@ -37,6 +37,7 @@ def setUp(self): self.kwargs = { "name": "a repository", + "code": "R1", "description": "this is for testing purposes", "tags": [self.test_tag1, self.test_tag2], "linux_path": "/mnt/M/Projects", @@ -56,7 +57,14 @@ def tearDown(self): self.patcher.restore() super(RepositoryTester, self).tearDown() - def test___auto_name__class_attribute_is_set_to_False(self): + def test_code_mixin_as_super(self): + """testing if CodeMixin is one of the supers of the Repository class + """ + from stalker import Repository, CodeMixin + repo = Repository(**self.kwargs) + assert isinstance(repo, CodeMixin) + + def test___auto_name__class_attribute_is_set_to_false(self): """testing if the __auto_name__ class attribute is set to False for Repository class """ @@ -906,7 +914,7 @@ def test_to_os_independent_path_is_working_properly(self): test_path = '%s/%s' % (self.test_repo.path, relative_part) from stalker import Repository assert Repository.to_os_independent_path(test_path) == \ - '$REPO%s/%s' % (self.test_repo.id, relative_part) + '$REPO%s/%s' % (self.test_repo.code, relative_part) def test_find_repo_is_working_properly(self): """testing if the find_repo class method is working properly @@ -919,6 +927,7 @@ def test_find_repo_is_working_properly(self): from stalker import Repository new_repo1 = Repository( name='New Repository', + code='NR', linux_path='/mnt/T/Projects', osx_path='/Volumes/T/Projects', windows_path='T:/Projects' @@ -944,6 +953,7 @@ def test_find_repo_is_working_properly_with_env_vars(self): from stalker import Repository new_repo1 = Repository( name='New Repository', + code='NR', linux_path='/mnt/T/Projects', osx_path='/Volumes/T/Projects', windows_path='T:/Projects' @@ -951,6 +961,14 @@ def test_find_repo_is_working_properly_with_env_vars(self): DBSession.add(new_repo1) DBSession.commit() + # Test with env var + test_path = '$REPO%s/some/path/to/a/file.ma' % self.test_repo.code + assert Repository.find_repo(test_path) == self.test_repo + + test_path = '$REPO%s/some/path/to/a/file.ma' % new_repo1.code + assert Repository.find_repo(test_path) == new_repo1 + + # Test with old env var test_path = '$REPO%s/some/path/to/a/file.ma' % self.test_repo.id assert Repository.find_repo(test_path) == self.test_repo @@ -960,7 +978,7 @@ def test_find_repo_is_working_properly_with_env_vars(self): def test_env_var_property_is_working_properly(self): """testing if the env_var property is working properly """ - assert self.test_repo.env_var == 'REPO31' + assert self.test_repo.env_var == 'REPOR1' def test_creating_and_committing_a_new_repository_instance_will_create_env_var(self): """testing if an environment variable will be created when a new @@ -970,6 +988,7 @@ def test_creating_and_committing_a_new_repository_instance_will_create_env_var(s from stalker.db.session import DBSession repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/T', osx_path='/Volumes/T', windows_path='T:/' @@ -978,10 +997,14 @@ def test_creating_and_committing_a_new_repository_instance_will_create_env_var(s DBSession.commit() import os - assert defaults.repo_env_var_template % {'id': repo.id} in os.environ + assert defaults.repo_env_var_template % {'code': repo.code} in \ + os.environ + + # check the old ID based env var assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - repo.path + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == repo.path def test_updating_a_repository_will_update_repo_path(self): """testing if the environment variable will be updated when the @@ -990,6 +1013,7 @@ def test_updating_a_repository_will_update_repo_path(self): from stalker import defaults, Repository repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/T', osx_path='/Volumes/T', windows_path='T:/' @@ -999,7 +1023,10 @@ def test_updating_a_repository_will_update_repo_path(self): DBSession.commit() import os - assert defaults.repo_env_var_template % {'id': repo.id} in os.environ + assert defaults.repo_env_var_template % {'code': repo.code} \ + in os.environ + assert defaults.repo_env_var_template_old % {'id': repo.id} \ + in os.environ # now update the repository test_value = '/mnt/S/' @@ -1007,8 +1034,13 @@ def test_updating_a_repository_will_update_repo_path(self): # expect the environment variable is also updated assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - test_value + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == test_value + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == test_value def test_updating_windows_path_only_update_repo_path_if_on_windows(self): """testing if updating the windows path will only update the path if @@ -1018,6 +1050,7 @@ def test_updating_windows_path_only_update_repo_path_if_on_windows(self): from stalker import Repository repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/T', osx_path='/Volumes/T', windows_path='T:/' @@ -1028,7 +1061,10 @@ def test_updating_windows_path_only_update_repo_path_if_on_windows(self): import os from stalker import defaults - assert defaults.repo_env_var_template % {'id': repo.id} in os.environ + assert \ + defaults.repo_env_var_template % {'code': repo.code} in os.environ + assert \ + defaults.repo_env_var_template_old % {'id': repo.id} in os.environ # now update the repository test_value = 'S:/' @@ -1036,11 +1072,22 @@ def test_updating_windows_path_only_update_repo_path_if_on_windows(self): # expect the environment variable not updated assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] != \ - test_value + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] != test_value + assert \ + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == repo.linux_path + + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] != test_value assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - repo.linux_path + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == repo.linux_path # make it windows self.patcher.patch('Windows') @@ -1051,11 +1098,21 @@ def test_updating_windows_path_only_update_repo_path_if_on_windows(self): # expect the environment variable not updated assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - test_value + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == test_value + assert \ + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == repo.windows_path assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - repo.windows_path + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == test_value + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == repo.windows_path def test_updating_osx_path_only_update_repo_path_if_on_osx(self): """testing if updating the osx path will only update the path if the @@ -1066,6 +1123,7 @@ def test_updating_osx_path_only_update_repo_path_if_on_osx(self): from stalker import defaults, Repository repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/T', osx_path='/Volumes/T', windows_path='T:/' @@ -1075,7 +1133,10 @@ def test_updating_osx_path_only_update_repo_path_if_on_osx(self): DBSession.commit() import os - assert defaults.repo_env_var_template % {'id': repo.id} in os.environ + assert \ + defaults.repo_env_var_template % {'code': repo.code} in os.environ + assert \ + defaults.repo_env_var_template_old % {'id': repo.id} in os.environ # now update the repository test_value = '/Volumes/S/' @@ -1083,11 +1144,22 @@ def test_updating_osx_path_only_update_repo_path_if_on_osx(self): # expect the environment variable not updated assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] != \ - test_value + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] != test_value + assert \ + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == repo.windows_path + + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] != test_value assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - repo.windows_path + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == repo.windows_path # make it osx self.patcher.patch('Darwin') @@ -1098,11 +1170,22 @@ def test_updating_osx_path_only_update_repo_path_if_on_osx(self): # expect the environment variable not updated assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - test_value + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == test_value assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - repo.osx_path + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == repo.osx_path + + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == test_value + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == repo.osx_path def test_updating_linux_path_only_update_repo_path_if_on_linux(self): """testing if updating the linux path will only update the path if the @@ -1113,6 +1196,7 @@ def test_updating_linux_path_only_update_repo_path_if_on_linux(self): from stalker import defaults, Repository repo = Repository( name='Test Repo', + code='TR', linux_path='/mnt/T', osx_path='/Volumes/T', windows_path='T:/' @@ -1122,7 +1206,10 @@ def test_updating_linux_path_only_update_repo_path_if_on_linux(self): DBSession.commit() import os - assert defaults.repo_env_var_template % {'id': repo.id} in os.environ + assert \ + defaults.repo_env_var_template % {'code': repo.code} in os.environ + assert \ + defaults.repo_env_var_template_old % {'id': repo.id} in os.environ # now update the repository test_value = '/mnt/S/' @@ -1130,11 +1217,22 @@ def test_updating_linux_path_only_update_repo_path_if_on_linux(self): # expect the environment variable not updated assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] != \ - test_value + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] != test_value + assert \ + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == repo.osx_path + + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] != test_value assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - repo.osx_path + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == repo.osx_path # make it linux self.patcher.patch('Linux') @@ -1145,8 +1243,20 @@ def test_updating_linux_path_only_update_repo_path_if_on_linux(self): # expect the environment variable not updated assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - test_value + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == test_value + assert \ + os.environ[ + defaults.repo_env_var_template % {'code': repo.code} + ] == repo.linux_path + + # expect the environment variable not updated + assert \ + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == test_value assert \ - os.environ[defaults.repo_env_var_template % {'id': repo.id}] == \ - repo.linux_path + os.environ[ + defaults.repo_env_var_template_old % {'id': repo.id} + ] == repo.linux_path diff --git a/tests/models/test_review.py b/tests/models/test_review.py index ac780b2..f50ef5f 100644 --- a/tests/models/test_review.py +++ b/tests/models/test_review.py @@ -75,6 +75,7 @@ def setUp(self): from stalker import Repository self.repo = Repository( name='Test Repository', + code='TR', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/' diff --git a/tests/models/test_scene.py b/tests/models/test_scene.py index 692eec2..8e0e023 100644 --- a/tests/models/test_scene.py +++ b/tests/models/test_scene.py @@ -47,6 +47,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code="TR", type=self.repository_type, ) diff --git a/tests/models/test_sequence.py b/tests/models/test_sequence.py index 0a5ce01..b879633 100644 --- a/tests/models/test_sequence.py +++ b/tests/models/test_sequence.py @@ -50,6 +50,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code="TR", type=self.repository_type, ) DBSession.add(self.test_repository) diff --git a/tests/models/test_shot.py b/tests/models/test_shot.py index f4aca7b..d3db42d 100644 --- a/tests/models/test_shot.py +++ b/tests/models/test_shot.py @@ -58,6 +58,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code="TR", type=self.test_repository_type, ) DBSession.add(self.test_repository) diff --git a/tests/models/test_simple_entity.py b/tests/models/test_simple_entity.py index 2178bfb..4ebdbfb 100644 --- a/tests/models/test_simple_entity.py +++ b/tests/models/test_simple_entity.py @@ -932,7 +932,8 @@ def test_generic_data_attribute_can_hold_a_wide_variety_of_object_types(self): from stalker import Repository test_repo = Repository( - name='Test Repository' + name='Test Repository', + code='TR', ) from stalker import Structure diff --git a/tests/models/test_studio.py b/tests/models/test_studio.py index 3b102e2..ce89f99 100644 --- a/tests/models/test_studio.py +++ b/tests/models/test_studio.py @@ -87,6 +87,7 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( name='Test Repository', + code='TR', windows_path='T:/', linux_path='/mnt/T/', osx_path='/Volumes/T/' diff --git a/tests/models/test_task.py b/tests/models/test_task.py index 976c602..d1043c7 100644 --- a/tests/models/test_task.py +++ b/tests/models/test_task.py @@ -85,6 +85,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code="TR", type=self.test_repository_type, linux_path='/mnt/T/', windows_path='T:/', @@ -4304,6 +4305,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code="TR", type=self.test_repository_type, linux_path='/mnt/T/', windows_path='T:/', diff --git a/tests/models/test_taskJuggler_scheduler.py b/tests/models/test_taskJuggler_scheduler.py index 5daae2d..1e330d3 100644 --- a/tests/models/test_taskJuggler_scheduler.py +++ b/tests/models/test_taskJuggler_scheduler.py @@ -100,6 +100,7 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( name='Test Repository', + code='TR', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/' diff --git a/tests/models/test_task_dependency.py b/tests/models/test_task_dependency.py index cde1aba..c9bf240 100644 --- a/tests/models/test_task_dependency.py +++ b/tests/models/test_task_dependency.py @@ -57,7 +57,8 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( - name='Test Repository' + name='Test Repository', + code='TR', ) DBSession.add(self.test_repo) diff --git a/tests/models/test_task_status_workflow.py b/tests/models/test_task_status_workflow.py index 0f93b63..1b3ef87 100644 --- a/tests/models/test_task_status_workflow.py +++ b/tests/models/test_task_status_workflow.py @@ -105,6 +105,7 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( name='Test Repository', + code='TR', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T' @@ -2247,6 +2248,7 @@ def setUp(self): from stalker import Repository self.test_repo = Repository( name='Test Repository', + code='TR', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T' diff --git a/tests/models/test_ticket.py b/tests/models/test_ticket.py index be789a3..2ee1fc8 100644 --- a/tests/models/test_ticket.py +++ b/tests/models/test_ticket.py @@ -57,7 +57,7 @@ def setUp(self): # create a Repository from stalker import Repository - self.test_repo = Repository(name="Test Repo") + self.test_repo = Repository(name="Test Repo", code='TR') # create a Project Type self.test_project_type = Type( diff --git a/tests/models/test_time_log.py b/tests/models/test_time_log.py index e7df45f..494a784 100644 --- a/tests/models/test_time_log.py +++ b/tests/models/test_time_log.py @@ -67,7 +67,7 @@ def setUp(self): DBSession.add(self.test_resource2) from stalker import Repository - self.test_repo = Repository(name="test repository") + self.test_repo = Repository(name="test repository", code="tr") DBSession.add(self.test_repo) # create a Project diff --git a/tests/models/test_user.py b/tests/models/test_user.py index 2795638..de24c07 100644 --- a/tests/models/test_user.py +++ b/tests/models/test_user.py @@ -91,6 +91,7 @@ def setUp(self): # a repository self.test_repository = Repository( name="Test Repository", + code="TR", type=self.test_repository_type ) diff --git a/tests/models/test_version.py b/tests/models/test_version.py index 2bbb4f8..aaf2832 100644 --- a/tests/models/test_version.py +++ b/tests/models/test_version.py @@ -57,6 +57,7 @@ def setUp(self): from stalker import Repository, Type self.test_repo = Repository( name='Test Repository', + code='TR', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/' @@ -1711,6 +1712,7 @@ def setUp(self): from stalker import Repository, Type self.test_repo = Repository( name='Test Repository', + code='TR', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/' diff --git a/tests/models/test_wiki.py b/tests/models/test_wiki.py index bbdf5e5..3ee281f 100644 --- a/tests/models/test_wiki.py +++ b/tests/models/test_wiki.py @@ -43,6 +43,7 @@ def setUp(self): from stalker import Repository self.test_repository = Repository( name="Test Repository", + code="TR", type=self.repository_type, ) diff --git a/tests/test_readme_tutorial.py b/tests/test_readme_tutorial.py index 25178b5..c2de4bf 100644 --- a/tests/test_readme_tutorial.py +++ b/tests/test_readme_tutorial.py @@ -41,6 +41,7 @@ def test_readme_tutorial_code(setup_sqlite3): from stalker import Repository repo = Repository( name='Commercial Projects Repository', + code='CPR', windows_path='Z:/Projects', linux_path='/mnt/Z/Projects', osx_path='/Volumes/Z/Projects'