def test_users_roles(): projects = sa.search_projects(PROJECT_NAME, return_metadata=True) for project in projects: sa.delete_project(project) users = sa.search_team_contributors() project = sa.create_project(PROJECT_NAME, "test_56", "Vector") sa.share_project(PROJECT_NAME, users[1], "QA") project_users = sa.get_project_metadata(PROJECT_NAME)["users"] print(project_users) found = False for u in project_users: if u["user_id"] == users[1]: found = True break assert found, users[1] sa.unshare_project(PROJECT_NAME, users[1]) project_users = sa.get_project_metadata(PROJECT_NAME)["users"] found = False for u in project_users: if u["user_id"] == users[1]: found = True break assert not found, users[1]
def test_assign_images_folder(tmpdir): tmpdir = Path(tmpdir) projects = sa.search_projects(PROJECT_NAME_VECTOR2, return_metadata=True) for project in projects: sa.delete_project(project) project = sa.create_project(PROJECT_NAME_VECTOR2, "test", "Vector") email = sa.get_team_metadata()["users"][0]["email"] sa.share_project(project, email, "QA") sa.create_folder(project, FOLDER2) project_folder = project["name"] + "/" + FOLDER2 sa.upload_images_from_folder_to_project(project_folder, "./tests/sample_project_vector") sa.assign_images(project_folder, ["example_image_1.jpg", "example_image_2.jpg"], email) time.sleep(1) im1_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg") im2_metadata = sa.get_image_metadata(project_folder, "example_image_2.jpg") assert im1_metadata["qa_id"] == email assert im2_metadata["qa_id"] == email sa.unshare_project(project, email) time.sleep(1) im1_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg") im2_metadata = sa.get_image_metadata(project_folder, "example_image_2.jpg") assert im1_metadata["qa_id"] is None assert im2_metadata["qa_id"] is None assert im1_metadata["annotator_id"] is None assert im2_metadata["annotator_id"] is None sa.share_project(project, email, "Annotator") sa.assign_images(project_folder, ["example_image_1.jpg", "example_image_2.jpg"], email) time.sleep(1) im1_metadata = sa.get_image_metadata(project_folder, "example_image_1.jpg") im2_metadata = sa.get_image_metadata(project_folder, "example_image_2.jpg") assert im1_metadata["annotator_id"] == email assert im2_metadata["annotator_id"] == email assert im1_metadata["qa_id"] is None assert im2_metadata["qa_id"] is None
def test_create_from_full_info(): projects = sa.search_projects(PROJECT_NAME1, return_metadata=True) for project in projects: sa.delete_project(project) project = sa.create_project(PROJECT_NAME1, "test", "Vector") sa.upload_images_from_folder_to_project( project, "./tests/sample_project_vector" ) sa.create_annotation_classes_from_classes_json( project, "./tests/sample_project_vector/classes/classes.json" ) old_settings = sa.get_project_settings(PROJECT_NAME1) for setting in old_settings: if "attribute" in setting and setting["attribute"] == "Brightness": brightness_value = setting["value"] sa.set_project_settings( PROJECT_NAME1, [{ "attribute": "Brightness", "value": brightness_value + 10 }] ) team_users = sa.search_team_contributors() sa.share_project(PROJECT_NAME1, team_users[1], "QA") project_metadata = sa.get_project_metadata( project, include_annotation_classes=True, include_settings=True, include_workflow=True, include_contributors=True ) project_metadata["name"] = PROJECT_NAME2 print(project_metadata) projects = sa.search_projects(PROJECT_NAME2, return_metadata=True) for project in projects: sa.delete_project(project) sa.create_project_from_metadata(project_metadata) new_project_metadata = sa.get_project_metadata( PROJECT_NAME2, include_annotation_classes=True, include_settings=True, include_workflow=True, include_contributors=True ) for u in new_project_metadata["contributors"]: if u["user_id"] == team_users[1]: break else: assert False assert len(new_project_metadata["annotation_classes"]) == len( project_metadata["annotation_classes"] ) assert len(new_project_metadata["settings"]) == len( project_metadata["settings"] ) for new_setting in new_project_metadata["settings"]: if "attribute" in new_setting and new_setting["attribute" ] == "Brightness": new_brightness_value = new_setting["value"] assert new_brightness_value == brightness_value + 10 assert len(new_project_metadata['workflow']) == len( project_metadata["workflow"] )
def test_create_like_project(tmpdir): tmpdir = Path(tmpdir) projects = sa.search_projects(PROJECT_NAME, return_metadata=True) for project in projects: sa.delete_project(project) sa.create_project(PROJECT_NAME, "tt", "Vector") sa.create_annotation_class(PROJECT_NAME, "rrr", "#FFAAFF") old_settings = sa.get_project_settings(PROJECT_NAME) for setting in old_settings: if "attribute" in setting and setting["attribute"] == "Brightness": brightness_value = setting["value"] sa.set_project_settings(PROJECT_NAME, [{ "attribute": "Brightness", "value": brightness_value + 10 }]) sa.set_project_workflow(PROJECT_NAME, [{ "step": 1, "className": "rrr", "tool": 3 }]) users = sa.search_team_contributors() sa.share_project(PROJECT_NAME, users[1], "QA") projects = sa.search_projects(PROJECT_NAME2, return_metadata=True) for project in projects: sa.delete_project(project) new_project = sa.clone_project(PROJECT_NAME2, PROJECT_NAME, copy_contributors=True) assert new_project["description"] == "tt" assert new_project["type"] == 1 time.sleep(1) ann_classes = sa.search_annotation_classes(PROJECT_NAME2, return_metadata=True) assert len(ann_classes) == 1 assert ann_classes[0]["name"] == "rrr" assert ann_classes[0]["color"] == "#FFAAFF" new_settings = sa.get_project_settings(PROJECT_NAME2) for setting in new_settings: if "attribute" in setting and setting["attribute"] == "Brightness": new_brightness_value = setting["value"] assert new_brightness_value == brightness_value + 10 new_workflow = sa.get_project_workflow(PROJECT_NAME2) assert len(new_workflow) == 1 assert new_workflow[0]["className"] == "rrr" assert new_workflow[0]["tool"] == 3 new_project = sa.get_project_metadata(new_project["name"], include_contributors=True) assert len(new_project["contributors"]) == 1 assert new_project["contributors"][0]["user_id"] == users[1] assert new_project["contributors"][0][ "user_role"] == sa.user_role_str_to_int("QA")