def test_context_from_dict(): context_dict = {} context_dict["project"] = {"type": "project", "id": 123} context_dict["entity"] = {"type": "shot", "id": 123} context_dict["step"] = "step" context_dict["task"] = {"type": "task", "id": 123} context_dict["workfile"] = {"type": "workfile", "id": 123} context_dict["user"] = {"type": "user", "id": 123} context = Context.from_dict(context_dict) assert context.project == {"type": "project", "id": 123} assert context.entity == {"type": "shot", "id": 123} assert context.step == "step" assert context.task == {"type": "task", "id": 123} assert context.workfile == {"type": "workfile", "id": 123} assert context.user == {"type": "user", "id": 123}
def context_from_path(path): # type: (str) -> kttk.context.Context """ Extracts context by path from database :param path: path for context :return: stored context if exists, else None """ # make path beautifull path = __good_path(path) kt = ktrack_api.get_ktrack() context_dicts = kt.find("path_entry", [["path", "is", path]]) context_found = len(context_dicts) > 0 if context_found: context = Context.from_dict(context_dicts[0]["context"]) return context else: return None