Skip to content

Commit 0aade53

Browse files
fix: remove fetching in validate profile for searching and scoring
1 parent c707b4f commit 0aade53

2 files changed

Lines changed: 14 additions & 84 deletions

File tree

hrflow/utils/scoring.py

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import typing as t
22

3-
from ..hrflow import Hrflow
43
from ..schemas import Education, Experience, HrFlowProfile
54

65

@@ -27,18 +26,24 @@ def is_valid_experiences_for_scoring(
2726
def is_valid_educations_for_scoring(
2827
education_list: t.Optional[t.List[Education]],
2928
) -> bool:
29+
"""
30+
Check if a list of educations is valid for scoring
31+
32+
Args:
33+
education_list: <list>
34+
List of educations to check
35+
Return:
36+
<bool> True if the list of educations is valid for
37+
scoring, False otherwise
38+
"""
3039
for education in education_list:
3140
if education.title or education.school:
3241
return True
3342
return False
3443

3544

3645
def is_valid_for_scoring(
37-
client: Hrflow,
38-
profile: t.Optional[t.Union[t.Dict, HrFlowProfile]] = None,
39-
source_key: t.Optional[str] = None,
40-
profile_key: t.Optional[str] = None,
41-
profile_reference: t.Optional[str] = None,
46+
profile: t.Union[t.Dict, HrFlowProfile],
4247
) -> bool:
4348
"""
4449
Check if a profile is valid for scoring
@@ -49,52 +54,17 @@ def is_valid_for_scoring(
4954
client: <Hrflow>
5055
Hrflow client
5156
profile: <dict> or <HrFlowProfile>
52-
Profile to check. Can be not provided if source_key,
53-
profile_key or profile_reference are provided
54-
source_key: <str>
55-
Source key. If provided, profile_key or
56-
profile_reference must be also provided.
57-
profile_key: <str>
58-
Profile key. If provided, profile_reference must be None
59-
profile_reference: <str>
60-
Profile reference. If provided, profile_key must be None
57+
Profile to check
6158
Return:
6259
<bool> True if the profile is valid for scoring,
6360
False otherwise
6461
"""
65-
# Check parameters and fetch profile if needed
66-
if profile is None:
67-
if source_key is None:
68-
raise ValueError("profile or source_key must be provided")
69-
elif profile_key is None and profile_reference is None:
70-
raise ValueError("profile_key or profile_reference must be provided")
71-
72-
response = client.profile.storing.get(
73-
source_key=source_key, key=profile_key, reference=profile_reference
74-
)
75-
if response["code"] >= 400:
76-
message = response["message"]
77-
raise ValueError(f"Error while fetching profile: {message}")
78-
profile = response["data"]
79-
else:
80-
if (
81-
source_key is not None
82-
or profile_key is not None
83-
or profile_reference is not None
84-
):
85-
86-
raise ValueError(
87-
"If you provide a profile, you can't provide source_key, profile_key "
88-
"or profile_reference"
89-
)
90-
9162
if isinstance(profile, dict):
9263
profile = HrFlowProfile.parse_obj(profile)
9364

9465
if not isinstance(profile, HrFlowProfile):
9566
raise ValueError("profile must be a dict or a HrFlowProfile object")
9667

97-
# Check if profile is valid for scoring
9868
return (
9969
is_valid_experiences_for_scoring(profile.experiences)
10070
or is_valid_educations_for_scoring(profile.educations)

hrflow/utils/searching.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import typing as t
22

3-
from ..hrflow import Hrflow
43
from ..schemas import HrFlowProfile, ProfileInfo
54

65

@@ -43,11 +42,7 @@ def is_valid_info_for_searching(info: ProfileInfo) -> bool:
4342

4443

4544
def is_valid_for_searching(
46-
client: Hrflow,
47-
profile: t.Optional[t.Union[t.Dict, HrFlowProfile]] = None,
48-
source_key: t.Optional[str] = None,
49-
profile_key: t.Optional[str] = None,
50-
profile_reference: t.Optional[str] = None,
45+
profile: t.Union[t.Dict, HrFlowProfile],
5146
) -> bool:
5247
"""
5348
Check if a profile is valid for searching
@@ -58,50 +53,15 @@ def is_valid_for_searching(
5853
client: <Hrflow>
5954
Hrflow client
6055
profile: <dict> or <HrFlowProfile>
61-
Profile to check. Can be not provided if source_key,
62-
profile_key or profile_reference are provided
63-
source_key: <str>
64-
Source key. If provided, profile_key or
65-
profile_reference must be also provided.
66-
profile_key: <str>
67-
Profile key. If provided, profile_reference must be None
68-
profile_reference: <str>
69-
Profile reference. If provided, profile_key must be None
56+
Profile to check
7057
Return:
7158
<bool> True if the profile is valid for searching,
7259
False otherwise
7360
"""
74-
# Check parameters and fetch profile if needed
75-
if profile is None:
76-
if source_key is None:
77-
raise ValueError("profile or source_key must be provided")
78-
elif profile_key is None and profile_reference is None:
79-
raise ValueError("profile_key or profile_reference must be provided")
80-
81-
response = client.profile.storing.get(
82-
source_key=source_key, key=profile_key, reference=profile_reference
83-
)
84-
if response["code"] >= 400:
85-
message = response["message"]
86-
raise ValueError(f"Error while fetching profile: {message}")
87-
profile = response["data"]
88-
else:
89-
if (
90-
source_key is not None
91-
or profile_key is not None
92-
or profile_reference is not None
93-
):
94-
95-
raise ValueError(
96-
"If you provide a profile, you can't provide source_key, profile_key "
97-
"or profile_reference"
98-
)
99-
10061
if isinstance(profile, dict):
10162
profile = HrFlowProfile.parse_obj(profile)
10263

10364
if not isinstance(profile, HrFlowProfile):
10465
raise ValueError("profile must be a dict or a HrFlowProfile object")
10566

106-
# Check if profile is valid for searching
10767
return is_valid_info_for_searching(profile.info) and bool(profile.text)

0 commit comments

Comments
 (0)