Skip to content

Commit

Permalink
fix: e2e Zoho Bug hunt
Browse files Browse the repository at this point in the history
  • Loading branch information
itsnedhir committed Nov 26, 2024
1 parent 4a5e401 commit 67e1ecc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 41 deletions.
39 changes: 20 additions & 19 deletions src/hrflow_connectors/v2/connectors/zohorecruit/aisles.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ class AuthParameters(Struct):
),
]
authorization_code: Annotated[
str,
t.Optional[str],
Meta(
description=(
"The authorization code generated during the Self Client creation, used"
" to get the refresh token and the first access token."
),
),
]
] = None
refresh_token: Annotated[
None,
t.Optional[str],
Meta(
description=(
"The refresh token is used to generate a new access token when the"
" current access token expires."
),
),
]
] = None
zoho_accounts_url: Annotated[
ZohoAccountsURL,
Meta(
Expand Down Expand Up @@ -134,9 +134,9 @@ class State(str, Enum):


class Type(str, Enum):
ALL = "All"
RECYCLE = "Recycle"
PERMANENT = "Permanent"
ALL = "all"
RECYCLE = "recycle"
PERMANENT = "permanent"


class ReadParameters(Struct):
Expand All @@ -148,7 +148,7 @@ class ReadParameters(Struct):
" API names, comma-separated.\nFor example Last_Name, Email"
),
),
]
] = None
sort_order: Annotated[
t.Optional[SortOrder],
Meta(
Expand All @@ -157,7 +157,7 @@ class ReadParameters(Struct):
" descending order\nasc - ascending order\ndesc - descending order"
),
),
]
] = None
sort_by: Annotated[
t.Optional[str],
Meta(
Expand All @@ -166,22 +166,21 @@ class ReadParameters(Struct):
" API name\nExample: Email"
),
),
]

] = None
cvid: Annotated[
t.Optional[int],
Meta(
description=(
"To get the list of records based on custom views\n{custom_view_id}"
),
),
]
] = None
territory_id: Annotated[
t.Optional[int],
Meta(
description="To get the list of records based on territory\n{territory_id}",
),
]
] = None
include_child: Annotated[
t.Optional[bool],
Meta(
Expand All @@ -191,7 +190,7 @@ class ReadParameters(Struct):
" records.\nThe default value is false."
),
),
]
] = None
state: Annotated[
t.Optional[State],
Meta(
Expand All @@ -204,7 +203,7 @@ class ReadParameters(Struct):
" the specified module."
),
),
]
] = None
converted: Annotated[
t.Optional[ZohoBool],
Meta(
Expand All @@ -229,15 +228,15 @@ class ReadParameters(Struct):

class ReadDeleteParameters(Struct):
type: Annotated[
Type,
t.Optional[Type],
Meta(
description=(
"All\nTo get the list of all deleted records\nRecycle\nTo get the list"
" of deleted records from recycle bin\nPermanent\nTo get the list of"
" permanently deleted records"
),
),
]
] = Type.ALL


class WriteParameters(Struct):
Expand All @@ -254,7 +253,7 @@ class WriteDeleteParameters(Struct):
" trigger workflows. The default value is true."
),
),
]
] = True


def get_refresh_token_and_first_access_token(
Expand Down Expand Up @@ -371,7 +370,6 @@ def __pull_records(
headers = {"Authorization": f"Zoho-oauthtoken {access_token}"}
while True:
response = requests.get(url, headers=headers, params=params)

if response.status_code == 200:
response = response.json()
data = response["data"]
Expand Down Expand Up @@ -473,6 +471,9 @@ def __pull_deleted_records(
if not response["info"]["more_records"]:
break
params["page"] = response["info"]["page"] + 1
elif response.status_code == 204:
adapter.info("No records found")
break
elif response.status_code == 401:
access_token = refresh_access_token(
adapter,
Expand Down
69 changes: 47 additions & 22 deletions src/hrflow_connectors/v2/connectors/zohorecruit/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_job_opening_tags(job_opening: dict) -> list:
]
tags = []
for tag in tags_list:
if job_opening[tag]:
if job_opening.get(tag):
tags.append(dict(name=tag, value=job_opening[tag]))
return tags

Expand All @@ -68,16 +68,19 @@ def format_zoho_job_opening_to_hrflow(job_opening: dict) -> dict:
location=get_location(job_opening),
summary=job_opening["Job_Description"],
skills=get_skills(job_opening["Required_Skills"]),
# TODO: get Additional_Info & Job_Description and add them only if they exist
sections=[
dict(
name="Job_Description",
title="Job Description",
description=job_opening["Job_Description"],
),
dict(
name="Additional_Info",
title="Additional Info",
description=job_opening["Additional_Info"],
(
dict(
name="Additional_Info",
title="Additional Info",
description=job_opening.get("Additional_Info", None),
)
),
],
tags=get_job_opening_tags(job_opening),
Expand All @@ -91,8 +94,9 @@ def get_experiences(experiences: list) -> list:
experience_dict = dict(
title=experience["Occupation_Title"],
company=experience["Company"],
date_start=experience["Work_Duration"]["from"],
date_end=experience["Work_Duration"].get("to", None),
location={"text": "", "lng": None, "lat": None},
date_start=experience.get("Work_Duration", {}).get("from", None),
date_end=experience.get("Work_Duration", {}).get("to", None),
description=experience["Summary"],
)
experiences_list.append(experience_dict)
Expand All @@ -105,8 +109,9 @@ def get_educations(educations: list) -> list:
education_dict = dict(
title=education["Degree"],
school=education["Institute_School"],
date_start=education["Education_Duration"]["from"],
date_end=education["Education_Duration"].get("to", None),
location={"text": "", "lng": None, "lat": None},
date_start=education.get("Education_Duration", {}).get("from", None),
date_end=education.get("Education_Duration", {}).get("to", None),
description=education["Major_Department"],
)
educations_list.append(education_dict)
Expand All @@ -115,6 +120,8 @@ def get_educations(educations: list) -> list:

def get_skills(skill_set: str) -> list:
skills = []
if not skill_set:
return skills
extracted_skills = skill_set.split(", ")
for skill in extracted_skills:
skill_dict = dict(
Expand Down Expand Up @@ -143,7 +150,7 @@ def get_candidate_tags(candidate: dict) -> list:
]
tags = []
for tag in tags_list:
if candidate[tag]:
if candidate.get(tag):
tags.append(dict(name=tag, value=candidate[tag]))
return tags

Expand Down Expand Up @@ -186,14 +193,18 @@ def get_zoho_skill_set(skills: list) -> str:
def get_zoho_experiences(experiences: list) -> list:
experiences_list = []
for experience in experiences:
work_duration = None
if experience["date_start"]:
work_duration = {
"from": experience["date_start"],
}
if experience["date_end"]:
work_duration["to"] = experience["date_end"]
experience_dict = dict(
Occupation_Title=experience["title"],
I_currently_work_here=experience["date_end"] is None,
Company=experience["company"],
Work_Duration={
"from": experience["date_start"],
"to": experience.get("date_end", None),
},
Work_Duration=work_duration,
Summary=experience["description"],
)
experiences_list.append(experience_dict)
Expand All @@ -203,15 +214,19 @@ def get_zoho_experiences(experiences: list) -> list:
def get_zoho_educations(educations: list) -> list:
educations_list = []
for education in educations:
duration = None
if education["date_start"]:
duration = {
"from": education["date_start"],
}
if education["date_end"]:
duration["to"] = education["date_end"]
education_dict = dict(
Institute_School=education["school"],
Currently_pursuing=education["date_end"] is None,
Degree=education["title"],
Major_Department=education["description"],
Duration={
"from": education["date_start"],
"to": education.get("date_end", None),
},
Duration=duration,
)
educations_list.append(education_dict)
return educations_list
Expand All @@ -232,11 +247,15 @@ def format_hrflow_profile_to_zoho(profile: dict) -> dict:
Email=profile["info"]["email"],
Phone=profile["info"]["phone"],
skillSet=get_zoho_skill_set(profile["skills"]),
Experience_in_Years=profile["experiences_duration"],
Experience_in_Years=(
int(profile["experiences_duration"])
if profile["experiences_duration"]
else None
),
Experience_Details=get_zoho_experiences(profile["experiences"]),
Educational_Details=get_zoho_educations(profile["educations"]),
Created_Time=profile["created_at"],
Updated_On=profile["updated_at"],
Created_Time=profile["created_at"][:19] if profile["created_at"] else None,
Updated_On=profile["updated_at"][:19] if profile["updated_at"] else None,
LinkedIn__s=get_url(profile["info"]["urls"], "linkedin"),
Facebook__s=get_url(profile["info"]["urls"], "facebook"),
Twitter=get_url(profile["info"]["urls"], "twitter"),
Expand All @@ -250,6 +269,12 @@ def format_hrflow_profile_to_zoho(profile: dict) -> dict:
return zoho_candidate


def format_hrflow_profile_for_update_to_zoho(profile: dict) -> dict:
zoho_candidate = format_hrflow_profile_to_zoho(profile)
zoho_candidate["id"] = int(profile["reference"])
return zoho_candidate


def format_archive_in_hrflow(record: dict) -> dict:
return dict(reference=record["id"])

Expand Down Expand Up @@ -295,7 +320,7 @@ def format_archive_in_zoho(record: dict) -> dict:
Mode.update,
Entity.profile,
Direction.outbound,
format=format_hrflow_profile_to_zoho,
format=format_hrflow_profile_for_update_to_zoho,
),
Flow(
Mode.archive,
Expand Down

0 comments on commit 67e1ecc

Please sign in to comment.