def setUp(self): """create test data """ super(LinkViewsFunctionalTestCase, self).setUp() from stalker import db, Link self.test_link1 = Link(name='Test Link 1', full_path='/some/full/path/to/a/file.txt', original_filename='the_original_file_name.txt', created_by=self.admin) db.DBSession.add(self.test_link1) self.test_link2 = Link(name='Test Link 2', full_path='/some/full/path/to/a/file.txt', original_filename='the_original_file_name.txt', created_by=self.admin) db.DBSession.add(self.test_link2) self.test_link3 = Link(name='Test Link 3', full_path='/some/full/path/to/a/file.txt', original_filename='the_original_file_name.txt', created_by=self.admin) db.DBSession.add(self.test_link3) db.DBSession.commit()
def test_ReferenceMixin_initialization(self): """testing if the ReferenceMixin part is initialized correctly """ from stalker import Link, Type link_type_1 = Type( name="Image", code='image', target_entity_type="Link" ) link1 = Link( name="Artwork 1", full_path="/mnt/M/JOBs/TEST_PROJECT", filename="a.jpg", type=link_type_1 ) link2 = Link( name="Artwork 2", full_path="/mnt/M/JOBs/TEST_PROJECT", filename="b.jbg", type=link_type_1 ) references = [link1, link2] self.kwargs["code"] = "SH12314" self.kwargs["references"] = references from stalker import Asset new_asset = Asset(**self.kwargs) assert new_asset.references == references
def test_ReferenceMixin_initialization(self): """testing if the ReferenceMixin part is initialized correctly """ from stalker import Type, Link, Sequence link_type_1 = Type( name="Image", code='image', target_entity_type="Link" ) link1 = Link( name="Artwork 1", full_path="/mnt/M/JOBs/TEST_PROJECT", filename="a.jpg", type=link_type_1 ) link2 = Link( name="Artwork 2", full_path="/mnt/M/JOBs/TEST_PROJECT", filename="b.jbg", type=link_type_1 ) references = [link1, link2] self.kwargs["references"] = references new_sequence = Sequence(**self.kwargs) self.assertEqual(new_sequence.references, references)
def setUpClass(cls): """setup once """ db.setup() db.init() cls.status_new = Status.query.filter_by(code='NEW').first() cls.status_wip = Status.query.filter_by(code='WIP').first() cls.status_cmpl = Status.query.filter_by(code='CMPL').first() cls.test_project_status_list = StatusList( name='Project Statuses', target_entity_type='Project', statuses=[cls.status_new, cls.status_wip, cls.status_cmpl]) cls.test_repo = Repository(name='Test Repository') cls.test_project = Project(name='Test Project', code='TP', repository=cls.test_repo, status_list=cls.test_project_status_list) cls.test_task1 = Task(name='Test Task 1', project=cls.test_project) cls.test_task2 = Task(name='Test Task 2', project=cls.test_project) cls.test_task3 = Task(name='Test Task 3', project=cls.test_project) cls.test_version1 = Version(task=cls.test_task1) db.DBSession.add(cls.test_version1) db.DBSession.commit() cls.test_version2 = Version(task=cls.test_task1) db.DBSession.add(cls.test_version2) db.DBSession.commit() cls.test_version3 = Version(task=cls.test_task1) db.DBSession.add(cls.test_version3) db.DBSession.commit() cls.test_version4 = Version(task=cls.test_task2) db.DBSession.add(cls.test_version4) db.DBSession.commit() cls.test_link1 = Link(original_filename='test_render1.jpg') cls.test_link2 = Link(original_filename='test_render2.jpg') cls.test_link3 = Link(original_filename='test_render3.jpg') cls.test_link4 = Link(original_filename='test_render4.jpg') cls.test_version1.outputs = [ cls.test_link1, cls.test_link2, cls.test_link3 ] cls.test_version4.outputs = [cls.test_link4] db.DBSession.add_all([ cls.test_task1, cls.test_task2, cls.test_task3, cls.test_version1, cls.test_version2, cls.test_version3, cls.test_version4, cls.test_link1, cls.test_link2, cls.test_link3, cls.test_link4 ]) db.DBSession.commit()
def test_equality_of_two_links(self): """testing the equality operator """ # with same parameters mock_link1 = Link(**self.kwargs) self.assertTrue(self.test_link == mock_link1) # with different parameters self.kwargs['type'] = self.test_link_type2 mock_link2 = Link(**self.kwargs) self.assertFalse(self.test_link == mock_link2)
def test_inequality_of_two_links(self): """testing the inequality operator """ # with same parameters mock_link1 = Link(**self.kwargs) assert self.test_link == mock_link1 # with different parameters self.kwargs['type'] = self.test_link_type2 mock_link2 = Link(**self.kwargs) assert not self.test_link != mock_link1 assert self.test_link != mock_link2
def setUp(self): """setup the test """ super(LinkTester, self).setUp() # create a mock LinkType object from stalker import db, Type self.test_link_type1 = Type( name='Test Type 1', code='test type1', target_entity_type=Link, ) db.DBSession.add(self.test_link_type1) self.test_link_type2 = Type( name='Test Type 2', code='test type2', target_entity_type=Link, ) db.DBSession.add(self.test_link_type2) self.kwargs = { 'name': 'An Image Link', 'full_path': 'C:/A_NEW_PROJECT/td/dsdf/' '22-fdfffsd-32342-dsf2332-dsfd-3.exr', 'original_filename': 'this_is_an_image.jpg', 'type': self.test_link_type1 } self.test_link = Link(**self.kwargs) db.DBSession.add(self.test_link) db.DBSession.commit()
def test_full_path_argument_is_None(self): """testing if setting the full_path argument to None will set the full_path attribute to an empty string """ self.kwargs['full_path'] = None new_link = Link(**self.kwargs) self.assertEqual(new_link.full_path, '')
def test_full_path_argument_is_empty_an_empty_string(self): """testing if setting the full_path attribute will be an empty string if full_path argument is an empty string """ self.kwargs['full_path'] = '' new_link = Link(**self.kwargs) self.assertEqual(new_link.full_path, '')
def upload_thumbnail(task, thumbnail_full_path): """Uploads the given thumbnail for the given entity :param task: An instance of :class:`~stalker.models.entity.SimpleEntity` or a derivative. :param str thumbnail_full_path: A string which is showing the path of the thumbnail image """ extension = os.path.splitext(thumbnail_full_path)[-1] # move the file to the task thumbnail folder # and mimic StalkerPyramids output format thumbnail_original_file_name = 'thumbnail%s' % extension thumbnail_final_full_path = os.path.join(task.absolute_path, 'Thumbnail', thumbnail_original_file_name) try: os.makedirs(os.path.dirname(thumbnail_final_full_path)) except OSError: pass # # convert the thumbnail to jpg if it is a format that is not supported by # # browsers # ext_not_supported_by_browsers = ['.bmp', '.tga', '.tif', '.tiff', '.exr'] # if extension in ext_not_supported_by_browsers: # # use MediaManager to convert them # from anima.utils import MediaManager # mm = MediaManager() # thumbnail_full_path = mm.generate_image_thumbnail(thumbnail_full_path) import shutil shutil.copy(thumbnail_full_path, thumbnail_final_full_path) from stalker import Link, Version, Repository thumbnail_os_independent_path = \ Repository.to_os_independent_path(thumbnail_final_full_path) l_thumb = Link.query\ .filter(Link.full_path == thumbnail_os_independent_path).first() if not l_thumb: l_thumb = Link(full_path=thumbnail_os_independent_path, original_filename=thumbnail_original_file_name) task.thumbnail = l_thumb # get a version of this Task from stalker.db.session import DBSession v = Version.query.filter(Version.task == task).first() if v: for naming_parent in v.naming_parents: if not naming_parent.thumbnail: naming_parent.thumbnail = l_thumb DBSession.add(naming_parent) DBSession.add(l_thumb) DBSession.commit()
def test_original_filename_argument_is_None(self): """testing if the original_filename attribute value will be set to the filename part of the full_path attribute if the original_filename argument is None """ self.kwargs['original_filename'] = None new_link = Link(**self.kwargs) filename = os.path.basename(new_link.full_path) self.assertEqual(new_link.original_filename, filename)
def test_thumbnail_attribute_is_working_properly(self): """testing if the thumbnail attribute is working properly """ from stalker import Link thumb = Link(full_path='some path') self.assertNotEqual(self.test_simple_entity.thumbnail, thumb) self.test_simple_entity.thumbnail = thumb self.assertEqual(self.test_simple_entity.thumbnail, thumb)
def test_original_filename_argument_is_empty_string(self): """testing if setting the original_filename argument to an empty string will set the original_filename attribute value to the filename part of the full_path """ self.kwargs['original_filename'] = '' new_link = Link(**self.kwargs) filename = os.path.basename(new_link.full_path) self.assertEqual(new_link.original_filename, filename)
def test_thumbnail_argument_is_working_properly(self): """testing if the thumbnail argument value is passed to the thumbnail attribute correctly """ from stalker import Link thumb = Link(full_path='some path') self.kwargs['thumbnail'] = thumb new_simple_entity = SimpleEntity(**self.kwargs) self.assertEqual(new_simple_entity.thumbnail, thumb)
def test_original_filename_argument_accepts_string_only(self): """testing if original_filename argument accepts string only and raises TypeError for other types """ test_value = 1 self.kwargs['original_filename'] = test_value with pytest.raises(TypeError) as cm: Link(**self.kwargs) assert str(cm.value) == \ 'Link.original_filename should be an instance of str and not int'
def test_full_path_argument_is_not_a_string(self): """testing if a TypeError will be raised when the full_path argument is not a string """ test_value = 1 self.kwargs["full_path"] = test_value with pytest.raises(TypeError) as cm: Link(**self.kwargs) assert str(cm.value) == \ 'Link.full_path should be an instance of string not int'
def test_full_path_argument_is_not_a_string(self): """testing if a TypeError will be raised when the full_path argument is not a string """ test_value = 1 self.kwargs["full_path"] = test_value with self.assertRaises(TypeError) as cm: Link(**self.kwargs) self.assertEqual( str(cm.exception), 'Link.full_path should be an instance of string not int')
def upload_thumbnail(task, thumbnail_full_path): """Uploads the given thumbnail for the given entity :param task: An instance of :class:`~stalker.models.entity.SimpleEntity` or a derivative. :param str thumbnail_full_path: A string which is showing the path of the thumbnail image """ extension = os.path.splitext(thumbnail_full_path)[-1] # move the file to the task thumbnail folder # and mimic StalkerPyramids output format thumbnail_original_file_name = 'thumbnail%s' % extension thumbnail_final_full_path = os.path.join(task.absolute_path, 'Thumbnail', thumbnail_original_file_name) try: os.makedirs(os.path.dirname(thumbnail_final_full_path)) except OSError: pass shutil.copy(thumbnail_full_path, thumbnail_final_full_path) from stalker import db, Link, Version, Repository thumbnail_os_independent_path = \ Repository.to_os_independent_path(thumbnail_final_full_path) l_thumb = Link.query\ .filter(Link.full_path == thumbnail_os_independent_path).first() if not l_thumb: l_thumb = Link(full_path=thumbnail_os_independent_path, original_filename=thumbnail_original_file_name) task.thumbnail = l_thumb # get a version of this Task v = Version.query.filter(Version.task == task).first() if v: for naming_parent in v.naming_parents: if not naming_parent.thumbnail: naming_parent.thumbnail = l_thumb db.DBSession.add(naming_parent) db.DBSession.add(l_thumb) db.DBSession.commit()
def setUp(self): """setup the test """ # create a mock LinkType object self.test_link_type1 = Type( name='Test Type 1', code='test type1', target_entity_type=Link, ) self.test_link_type2 = Type( name='Test Type 2', code='test type2', target_entity_type=Link, ) self.kwargs = { 'name': 'An Image Link', 'full_path': 'C:/A_NEW_PROJECT/td/dsdf/' '22-fdfffsd-32342-dsf2332-dsfd-3.exr', 'original_filename': 'this_is_an_image.jpg', 'type': self.test_link_type1 } self.test_link = Link(**self.kwargs)
def setUp(self): super(DailyTestBase, self).setUp() from stalker import db, Status, StatusList self.status_new = Status.query.filter_by(code='NEW').first() self.status_wip = Status.query.filter_by(code='WIP').first() self.status_cmpl = Status.query.filter_by(code='CMPL').first() self.test_project_status_list = StatusList( name='Project Statuses', target_entity_type='Project', statuses=[self.status_new, self.status_wip, self.status_cmpl]) db.DBSession.add(self.test_project_status_list) from stalker import Repository, Project self.test_repo = Repository(name='Test Repository') db.DBSession.add(self.test_repo) self.test_project = Project(name='Test Project', code='TP', repository=self.test_repo, status_list=self.test_project_status_list) db.DBSession.add(self.test_project) from stalker import Task self.test_task1 = Task(name='Test Task 1', project=self.test_project) db.DBSession.add(self.test_task1) self.test_task2 = Task(name='Test Task 2', project=self.test_project) db.DBSession.add(self.test_task2) self.test_task3 = Task(name='Test Task 3', project=self.test_project) db.DBSession.add(self.test_task3) from stalker import Version self.test_version1 = Version(task=self.test_task1) db.DBSession.add(self.test_version1) db.DBSession.commit() self.test_version2 = Version(task=self.test_task1) db.DBSession.add(self.test_version2) db.DBSession.commit() self.test_version3 = Version(task=self.test_task1) db.DBSession.add(self.test_version3) db.DBSession.commit() self.test_version4 = Version(task=self.test_task2) db.DBSession.add(self.test_version4) db.DBSession.commit() from stalker import Link self.test_link1 = Link(original_filename='test_render1.jpg') self.test_link2 = Link(original_filename='test_render2.jpg') self.test_link3 = Link(original_filename='test_render3.jpg') self.test_link4 = Link(original_filename='test_render4.jpg') self.test_version1.outputs = [ self.test_link1, self.test_link2, self.test_link3 ] self.test_version4.outputs = [self.test_link4] db.DBSession.add_all([ self.test_task1, self.test_task2, self.test_task3, self.test_version1, self.test_version2, self.test_version3, self.test_version4, self.test_link1, self.test_link2, self.test_link3, self.test_link4 ]) db.DBSession.commit()
def upload_reference(self, task, file_object, filename): """Uploads a reference for the given task to Task.path/References/Stalker_Pyramid/ folder and create a Link object to there. Again the Link object will have a Repository root relative path. It will also create a thumbnail under {{Task.absolute_path}}/References/Stalker_Pyramid/Thumbs folder and a web friendly version (PNG for images, WebM for video files) under {{Task.absolute_path}}/References/Stalker_Pyramid/ForWeb folder. :param task: The task that a reference is uploaded to. Should be an instance of :class:`.Task` class. :type task: :class:`.Task` :param file_object: The file like object holding the content of the uploaded file. :param str filename: The original filename. :returns: :class:`.Link` instance. """ ############################################################ # ORIGINAL ############################################################ file_path = os.path.join(os.path.join(task.absolute_path), self.reference_path) # upload it reference_file_full_path = \ self.upload_file(file_object, file_path, filename) reference_file_file_name = os.path.basename(reference_file_full_path) reference_file_base_name = \ os.path.splitext(reference_file_file_name)[0] # create a Link instance and return it. # use a Repository relative path repo = task.project.repository from stalker import Repository, Link assert isinstance(repo, Repository) relative_full_path = repo.make_relative(reference_file_full_path) link = Link(full_path=relative_full_path, original_filename=filename) # create a thumbnail for the given reference # don't forget that the first thumbnail is the Web viewable version # and the second thumbnail is the thumbnail ############################################################ # WEB VERSION ############################################################ web_version_temp_full_path = \ self.generate_media_for_web(reference_file_full_path) web_version_extension = \ os.path.splitext(web_version_temp_full_path)[-1] web_version_file_name = '%s%s' % (reference_file_base_name, web_version_extension) web_version_full_path = \ os.path.join( os.path.dirname(reference_file_full_path), 'ForWeb', web_version_file_name ) web_version_repo_relative_full_path = \ repo.make_relative(web_version_full_path) web_version_link = Link(full_path=web_version_repo_relative_full_path, original_filename=web_version_file_name) # move it to repository try: os.makedirs(os.path.dirname(web_version_full_path)) except OSError: # path exists pass shutil.move(web_version_temp_full_path, web_version_full_path) ############################################################ # THUMBNAIL ############################################################ # finally generate a Thumbnail thumbnail_temp_full_path = \ self.generate_thumbnail(reference_file_full_path) thumbnail_extension = os.path.splitext(thumbnail_temp_full_path)[-1] thumbnail_file_name = '%s%s' % (reference_file_base_name, thumbnail_extension) thumbnail_full_path = \ os.path.join( os.path.dirname(reference_file_full_path), 'Thumbnail', thumbnail_file_name ) thumbnail_repo_relative_full_path = \ repo.make_relative(thumbnail_full_path) thumbnail_link = Link(full_path=thumbnail_repo_relative_full_path, original_filename=thumbnail_file_name) # move it to repository try: os.makedirs(os.path.dirname(thumbnail_full_path)) except OSError: # path exists pass shutil.move(thumbnail_temp_full_path, thumbnail_full_path) ############################################################ # LINK Objects ############################################################ # link them # assign it as a reference to the given task task.references.append(link) link.thumbnail = web_version_link web_version_link.thumbnail = thumbnail_link return link
def upload_version_output(self, version, file_object, filename): """Uploads a file as an output for the given :class:`.Version` instance. Will store the file in {{Version.absolute_path}}/Outputs/Stalker_Pyramid/ folder. It will also generate a thumbnail in {{Version.absolute_path}}/Outputs/Stalker_Pyramid/Thumbs folder and a web friendly version (PNG for images, WebM for video files) under {{Version.absolute_path}}/Outputs/Stalker_Pyramid/ForWeb folder. :param version: A :class:`.Version` instance that the output is uploaded for. :type version: :class:`.Version` :param file_object: The file like object holding the content of the uploaded file. :param str filename: The original filename. :returns: :class:`.Link` instance. """ ############################################################ # ORIGINAL ############################################################ file_path = os.path.join(os.path.join(version.absolute_path), self.version_output_path) # upload it version_output_file_full_path = \ self.upload_file(file_object, file_path, filename) version_output_file_name = \ os.path.basename(version_output_file_full_path) version_output_base_name = \ os.path.splitext(version_output_file_name)[0] # create a Link instance and return it. # use a Repository relative path repo = version.task.project.repository from stalker import Link full_path = str(version_output_file_full_path) link = Link(full_path=repo.to_os_independent_path(full_path), original_filename=str(filename)) # create a thumbnail for the given version output # don't forget that the first thumbnail is the Web viewable version # and the second thumbnail is the thumbnail ############################################################ # WEB VERSION ############################################################ web_version_link = None try: web_version_temp_full_path = \ self.generate_media_for_web(version_output_file_full_path) web_version_extension = \ os.path.splitext(web_version_temp_full_path)[-1] web_version_full_path = \ os.path.join( os.path.dirname(version_output_file_full_path), 'ForWeb', version_output_base_name + web_version_extension ) web_version_link = Link( full_path=repo.to_os_independent_path(web_version_full_path), original_filename=filename) # move it to repository try: os.makedirs(os.path.dirname(web_version_full_path)) except OSError: # path exists pass shutil.move(web_version_temp_full_path, web_version_full_path) except RuntimeError: # not an image or video so skip it pass ############################################################ # THUMBNAIL ############################################################ # finally generate a Thumbnail thumbnail_link = None try: thumbnail_temp_full_path = \ self.generate_thumbnail(version_output_file_full_path) thumbnail_extension = os.path.splitext( thumbnail_temp_full_path)[-1] thumbnail_full_path = \ os.path.join( os.path.dirname(version_output_file_full_path), 'Thumbnail', version_output_base_name + thumbnail_extension ) thumbnail_link = Link( full_path=repo.to_os_independent_path(thumbnail_full_path), original_filename=filename) # move it to repository try: os.makedirs(os.path.dirname(thumbnail_full_path)) except OSError: # path exists pass shutil.move(thumbnail_temp_full_path, thumbnail_full_path) except RuntimeError: # not an image or video so skip it pass ############################################################ # LINK Objects ############################################################ # link them # assign it as an output to the given version version.outputs.append(link) if web_version_link: link.thumbnail = web_version_link if thumbnail_link: web_version_link.thumbnail = thumbnail_link return link
def setUp(self): super(DailyTestBase, self).setUp() from stalker import Status, StatusList self.status_new = Status(name='Mew', code='NEW') self.status_wfd = Status(name='Waiting For Dependency', code='WFD') self.status_rts = Status(name='Ready To Start', code='RTS') self.status_wip = Status(name='Work In Progress', code='WIP') self.status_prev = Status(name='Pending Review', code='PREV') self.status_hrev = Status(name='Has Revision', code='HREV') self.status_drev = Status(name='Dependency Has Revision', code='DREV') self.status_cmpl = Status(name='Completed', code='CMPL') self.status_open = Status(name='Open', code='OPEN') self.status_cls = Status(name='Closed', code='CLS') self.daily_status_list = StatusList( name='Daily Statuses', statuses=[self.status_open, self.status_cls], target_entity_type='Daily') self.task_status_list = StatusList( name='Task Statuses', statuses=[ self.status_wfd, self.status_rts, self.status_wip, self.status_prev, self.status_hrev, self.status_drev, self.status_cmpl ], target_entity_type='Task') self.test_project_status_list = StatusList( name='Project Statuses', target_entity_type='Project', statuses=[self.status_new, self.status_wip, self.status_cmpl]) from stalker import Repository, Project self.test_repo = Repository(name='Test Repository', code='TR') self.test_project = Project(name='Test Project', code='TP', repository=self.test_repo, status_list=self.test_project_status_list) from stalker import Task self.test_task1 = Task(name='Test Task 1', project=self.test_project, status_list=self.task_status_list) self.test_task2 = Task(name='Test Task 2', project=self.test_project, status_list=self.task_status_list) self.test_task3 = Task(name='Test Task 3', project=self.test_project, status_list=self.task_status_list) from stalker import Version self.test_version1 = Version(task=self.test_task1) self.test_version2 = Version(task=self.test_task1) self.test_version3 = Version(task=self.test_task1) self.test_version4 = Version(task=self.test_task2) from stalker import Link self.test_link1 = Link(original_filename='test_render1.jpg') self.test_link2 = Link(original_filename='test_render2.jpg') self.test_link3 = Link(original_filename='test_render3.jpg') self.test_link4 = Link(original_filename='test_render4.jpg') self.test_version1.outputs = [ self.test_link1, self.test_link2, self.test_link3 ] self.test_version4.outputs = [self.test_link4]
def setUp(self): super(DailyDBTestDBCase, self).setUp() from stalker import Status, StatusList self.status_new = Status.query.filter_by(code='NEW').first() self.status_wfd = Status.query.filter_by(code='WFD').first() self.status_rts = Status.query.filter_by(code='RTS').first() self.status_wip = Status.query.filter_by(code='WIP').first() self.status_prev = Status.query.filter_by(code='PREV').first() self.status_hrev = Status.query.filter_by(code='HREV').first() self.status_drev = Status.query.filter_by(code='DREV').first() self.status_cmpl = Status.query.filter_by(code='CMPL').first() self.status_open = Status.query.filter_by(code='OPEN').first() self.status_cls = Status.query.filter_by(code='CLS').first() self.daily_status_list = \ StatusList.query.filter_by(target_entity_type='Daily').first() self.task_status_list = \ StatusList.query.filter_by(target_entity_type='Task').first() from stalker import Repository, Project self.test_repo = Repository(name='Test Repository', code='TR') from stalker.db.session import DBSession DBSession.add(self.test_repo) self.test_project = Project( name='Test Project', code='TP', repository=self.test_repo, ) DBSession.add(self.test_project) from stalker import Task self.test_task1 = Task(name='Test Task 1', project=self.test_project, status_list=self.task_status_list) DBSession.add(self.test_task1) self.test_task2 = Task(name='Test Task 2', project=self.test_project, status_list=self.task_status_list) DBSession.add(self.test_task2) self.test_task3 = Task(name='Test Task 3', project=self.test_project, status_list=self.task_status_list) DBSession.add(self.test_task3) DBSession.commit() from stalker import Version self.test_version1 = Version(task=self.test_task1) DBSession.add(self.test_version1) DBSession.commit() self.test_version2 = Version(task=self.test_task1) DBSession.add(self.test_version2) DBSession.commit() self.test_version3 = Version(task=self.test_task1) DBSession.add(self.test_version3) DBSession.commit() self.test_version4 = Version(task=self.test_task2) DBSession.add(self.test_version4) DBSession.commit() from stalker import Link self.test_link1 = Link(original_filename='test_render1.jpg') self.test_link2 = Link(original_filename='test_render2.jpg') self.test_link3 = Link(original_filename='test_render3.jpg') self.test_link4 = Link(original_filename='test_render4.jpg') DBSession.add_all([ self.test_link1, self.test_link2, self.test_link3, self.test_link4 ]) self.test_version1.outputs = [ self.test_link1, self.test_link2, self.test_link3 ] self.test_version4.outputs = [self.test_link4] DBSession.commit()
def test_get_entity_view_is_working_properly(self): """testing if GET /api/entities/{id} view is working properly """ # create a test entity from stalker import db, Entity, Type test_type = Type(name='Test User', code='testuser', target_entity_type='User') db.DBSession.add(test_type) from stalker import Link test_thumbnail = Link(full_path='/some/full/path') db.DBSession.add(test_thumbnail) import datetime date_created = datetime.datetime(2016, 6, 20, 13, 55) test_entity = Entity(name='Test Entity', description='This is a test description', created_by=self.admin, type=test_type, date_created=date_created, thumbnail=test_thumbnail) db.DBSession.add(test_entity) db.DBSession.commit() response = self.test_app.get('/api/entities/%s' % test_entity.id, status=200) from stalker_pyramid.views import EntityViewBase import stalker self.maxDiff = None self.assertEqual( response.json_body, { 'created_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, 'date_created': EntityViewBase.milliseconds_since_epoch(date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch(date_created), 'description': 'This is a test description', 'entity_type': 'Entity', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % test_entity.id, 'length': 0 }, 'id': test_entity.id, 'name': 'Test Entity', 'notes': { '$ref': '/api/entities/%s/notes' % test_entity.id, 'length': 0 }, 'stalker_version': stalker.__version__, 'tags': { '$ref': '/api/entities/%s/tags' % test_entity.id, 'length': 0 }, 'thumbnail': { 'id': test_thumbnail.id, '$ref': '/api/links/%s' % test_thumbnail.id, 'name': test_thumbnail.name, 'entity_type': 'Link' }, 'type': { 'id': test_entity.type_id, '$ref': '/api/types/%s' % test_entity.type_id, 'name': test_entity.type.name, 'entity_type': 'Type' }, 'updated_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': 'User' }, })
def test_get_entities_view_is_working_properly(self): """testing if GET /api/entities view is working properly """ # create a couple of test entities from stalker import db, Entity, Type test_type = Type(name='Test User', code='testuser', target_entity_type='User') db.DBSession.add(test_type) from stalker import Link test_thumbnail = Link(full_path='/some/full/path') db.DBSession.add(test_thumbnail) import datetime date_created = datetime.datetime(2016, 6, 20, 13, 55) # Test Entity 1 test_entity1 = Entity(name='Test Entity 1', description='This is a test description', created_by=self.admin, type=test_type, date_created=date_created, thumbnail=test_thumbnail) db.DBSession.add(test_entity1) # Test Entity 2 test_entity2 = Entity(name='Test Entity 2', description='This is a test description', created_by=self.admin, type=test_type, date_created=date_created, thumbnail=test_thumbnail) db.DBSession.add(test_entity2) # Test Entity 3 test_entity3 = Entity(name='Test Entity 3', description='This is a test description', created_by=self.admin, type=test_type, date_created=date_created, thumbnail=test_thumbnail) db.DBSession.add(test_entity3) # commit data db.DBSession.commit() response = self.test_app.get('/api/entities', status=200) # admins department admins_department = Entity.query \ .filter(Entity.name == 'admins') \ .filter(Entity.entity_type == 'Department') \ .first() # admins group admins_group = Entity.query \ .filter(Entity.name == 'admins') \ .filter(Entity.entity_type == 'Group') \ .first() # Statuses status_new = Entity.query \ .filter(Entity.name == 'New').first() status_accepted = Entity.query \ .filter(Entity.name == 'Accepted').first() status_assigned = Entity.query \ .filter(Entity.name == 'Assigned').first() status_reopened = Entity.query \ .filter(Entity.name == 'Reopened').first() status_closed = Entity.query \ .filter(Entity.name == 'Closed').first() status_open = Entity.query \ .filter(Entity.name == 'Open').first() status_wfd = Entity.query \ .filter(Entity.name == 'Waiting For Dependency').first() status_rts = Entity.query \ .filter(Entity.name == 'Ready To Start').first() status_wip = Entity.query \ .filter(Entity.name == 'Work In Progress').first() status_prev = Entity.query \ .filter(Entity.name == 'Pending Review').first() status_hrev = Entity.query \ .filter(Entity.name == 'Has Revision').first() status_drev = Entity.query \ .filter(Entity.name == 'Dependency Has Revision').first() status_oh = Entity.query \ .filter(Entity.name == 'On Hold').first() status_stop = Entity.query \ .filter(Entity.name == 'Stopped').first() status_cmpl = Entity.query \ .filter(Entity.name == 'Completed').first() status_rrev = Entity.query \ .filter(Entity.name == 'Requested Revision').first() status_app = Entity.query \ .filter(Entity.name == 'Approved').first() # Status Lists ticket_statuses = Entity.query \ .filter(Entity.name == 'Ticket Statuses').first() daily_statuses = Entity.query \ .filter(Entity.name == 'Daily Statuses').first() task_statuses = Entity.query \ .filter(Entity.name == 'Task Statuses').first() asset_statuses = Entity.query \ .filter(Entity.name == 'Asset Statuses').first() shot_statuses = Entity.query \ .filter(Entity.name == 'Shot Statuses').first() sequence_statuses = Entity.query \ .filter(Entity.name == 'Sequence Statuses').first() review_statuses = Entity.query \ .filter(Entity.name == 'Review Statuses').first() # Types type_defect = Entity.query \ .filter(Entity.name == 'Defect').first() type_enhancement = Entity.query \ .filter(Entity.name == 'Enhancement').first() all_data = [ test_entity1, test_entity2, test_entity3, admins_department, admins_group, self.admin, status_new, status_accepted, status_assigned, status_reopened, status_closed, status_open, status_wfd, status_rts, status_wip, status_prev, status_hrev, status_drev, status_oh, status_stop, status_cmpl, status_rrev, status_app, ticket_statuses, daily_statuses, task_statuses, asset_statuses, shot_statuses, sequence_statuses, review_statuses, type_defect, type_enhancement, test_type, test_thumbnail, ] self.maxDiff = None from stalker_pyramid import entity_type_to_url expected_response = [{ 'id': r.id, '$ref': '%s/%s' % (entity_type_to_url[r.entity_type], r.id), 'name': r.name, 'entity_type': r.entity_type } for r in all_data] self.assertEqual(sorted(response.json_body, key=lambda x: x['id']), sorted(expected_response, key=lambda x: x['id']))