def test_update_project(self): with requests_mock.mock() as mock: project = { "id": fakeid("project-1"), "name": "project-1", "team": [fakeid("person-1")], "asset_types": [fakeid("asset-type-1")], "task_statuses": [fakeid("task-status-1")], "task_types": [fakeid("task-type-1")], } mock_route( mock, "PUT", "data/projects/%s" % fakeid("project-1"), text=project, ) self.assertEqual(gazu.project.update_project(project), project)
def test_update_asset(self): result = { "id": fakeid("asset-1"), "episode_id": fakeid("episode_1"), "source_id": fakeid("episode_1"), } with requests_mock.mock() as mock: mock_route( mock, "PUT", "data/entities/%s" % fakeid("asset-1"), text=result, ) asset = { "id": fakeid("asset-1"), "episode_id": fakeid("episode_1"), } self.assertEqual(gazu.asset.update_asset(asset), result)
def test_get_metadata_descriptor(self): with requests_mock.mock() as mock: mock_route( mock, "GET", "data/projects/%s/metadata-descriptors/%s" % (fakeid("project-1"), fakeid("metadata-descriptor-1")), text={ "id": fakeid("metadata-descriptor-1"), "name": "metadata-descriptor-1", }, ), metadata_descriptor = gazu.project.get_metadata_descriptor( fakeid("project-1"), {"id": fakeid("metadata-descriptor-1")}) self.assertEqual(metadata_descriptor["name"], "metadata-descriptor-1") self.assertEqual(metadata_descriptor["id"], fakeid("metadata-descriptor-1"))
def test_all_asset_instances_for_asset(self): with requests_mock.mock() as mock: mock.get( gazu.client.get_full_url( "data/assets/{}/asset-asset-instances".format( fakeid("asset-01"))), text=json.dumps([{ "asset_id": fakeid("asset-02"), "target_asset_id": fakeid("asset-01"), "number": 1, }]), ) asset_instances = gazu.asset.all_asset_instances_for_asset( fakeid("asset-01")) asset_instance = asset_instances[0] self.assertEqual(asset_instance["asset_id"], fakeid("asset-02")) self.assertEqual(asset_instance["target_asset_id"], fakeid("asset-01")) self.assertEqual(asset_instance["number"], 1)
def test_all_previews_for_shot(self): with requests_mock.mock() as mock: mock.get( gazu.client.get_full_url("data/shots/%s/preview-files" % fakeid("shot-1")), text=json.dumps([ { "id": fakeid("preview-1"), "name": "preview-1" }, { "id": fakeid("preview-2"), "name": "preview-2" }, ]), ) previews = gazu.shot.all_previews_for_shot(fakeid("shot-1")) self.assertEqual(len(previews), 2) self.assertEqual(previews[0]["id"], fakeid("preview-1")) self.assertEqual(previews[1]["id"], fakeid("preview-2"))
def test_all_metadata_descriptors(self): with requests_mock.mock() as mock: mock_route( mock, "GET", "data/projects/%s/metadata-descriptors" % fakeid("project-1"), text=[ { "id": fakeid("metadata-descriptor-1"), }, { "id": fakeid("metadata-descriptor-2"), }, ], ), metadata_descriptors = gazu.project.all_metadata_descriptors( fakeid("project-1")) self.assertEqual(len(metadata_descriptors), 2) self.assertEqual(metadata_descriptors[0]["id"], fakeid("metadata-descriptor-1")) self.assertEqual(metadata_descriptors[1]["id"], fakeid("metadata-descriptor-2"))
def test_update_project_data(self): with requests_mock.mock() as mock: mock.get( gazu.client.get_full_url("data/projects/%s" % fakeid("project-1")), text=json.dumps({ "id": fakeid("project-1"), "name": "project-1", }), ) mock.put( gazu.client.get_full_url("data/projects/%s" % fakeid("project-1")), text=json.dumps({ "id": fakeid("project-1"), "name": "project-1", "data": {}, }), ) project = gazu.project.update_project_data(fakeid("project-1")) self.assertEqual(project["id"], fakeid("project-1")) self.assertEqual(project["data"], {})
def test_exports_assets_with_csv(self): with requests_mock.mock() as mock: csv = ";;;;" mock_route( mock, "GET", "export/csv/projects/%s/assets.csv?episode_id=%s&assigned_to=%s" % ( fakeid("project-1"), fakeid("episode-1"), fakeid("person-1"), ), text=csv, ) gazu.asset.export_assets_with_csv( fakeid("project-1"), "./test.csv", fakeid("episode-1"), fakeid("person-1"), ) with open("./test.csv", "r") as export_csv: self.assertEqual(csv, export_csv.read()) os.remove("./test.csv")
def test_get_asset_instances_for_shot(self): with requests_mock.mock() as mock: mock.get( gazu.client.get_full_url("data/shots/%s/asset-instances" % fakeid("shot-1")), text=json.dumps([ { "id": fakeid("asset_instance-1"), "name": "asset_instance-1", }, { "id": fakeid("asset_instance-2"), "name": "asset_instance-2", }, ]), ) asset_instances = gazu.shot.get_asset_instances_for_shot( fakeid("shot-1")) self.assertEqual(len(asset_instances), 2) self.assertEqual(asset_instances[0]["id"], fakeid("asset_instance-1")) self.assertEqual(asset_instances[1]["id"], fakeid("asset_instance-2"))
def test_normalize_list_of_models_for_links(self): self.assertEqual( helpers.normalize_list_of_models_for_links(fakeid("test-1")), [fakeid("test-1")], )
def test_new_task(self): with requests_mock.mock() as mock: result = {"id": fakeid("task-01")} mock.get( gazu.client.get_full_url( "data/tasks?name=main&entity_id={asset}" "&task_type_id={task_type}".format( asset=fakeid("asset-01"), task_type=fakeid("task-type-01"), ) ), text=json.dumps([]), ) mock.get( gazu.client.get_full_url("data/task-status?name=Todo"), text=json.dumps([{"id": fakeid("task-status-01")}]), ) mock.post( gazu.client.get_full_url("data/tasks"), text=json.dumps(result) ) asset = { "id": fakeid("asset-01"), "project_id": fakeid("project-01"), } task_type = {"id": fakeid("task-type-01")} task = gazu.task.new_task(asset, task_type) self.assertEqual(task, result) result = { "id": fakeid("task-01"), "data": { "assigner_id": fakeid("assigner-1"), "assignees": [ fakeid("assignees-1"), fakeid("assignees-2"), ], }, } mock.post( gazu.client.get_full_url("data/tasks"), text=json.dumps(result) ) task = gazu.task.new_task( asset, task_type, assigner=fakeid("assigner-1"), assignees=[fakeid("assignees-1"), fakeid("assignees-2")], ) self.assertEqual(task, result)
def test_new_shot(self): with requests_mock.mock() as mock: result = { "id": fakeid("shot-1"), "project_id": fakeid("project-1"), "description": "test description", } mock_route( mock, "GET", "data/shots/all?sequence_id=%s&name=Shot 01" % (fakeid("sequence-1")), text=[], ) mock_route( mock, "POST", "data/projects/%s/shots" % (fakeid("project-1")), text=result, ) shot = gazu.shot.new_shot( fakeid("project-1"), fakeid("sequence-1"), "Shot 01", nb_frames=10, frame_in=10, frame_out=20, description="test description", ) self.assertEqual(shot, result) with requests_mock.mock() as mock: result = { "id": fakeid("shot-1"), "project_id": fakeid("project-1"), } mock_route( mock, "GET", "data/shots/all?sequence_id=%s&name=Shot 01" % fakeid("sequence-1"), text=[result], ) shot = gazu.shot.new_shot( fakeid("project-1"), fakeid("sequence-1"), "Shot 01", nb_frames=10, frame_in=10, frame_out=20, ) self.assertEqual(shot, result)