11import typing as t
22
3- from ..hrflow import Hrflow
43from ..schemas import Education , Experience , HrFlowProfile
54
65
@@ -27,18 +26,24 @@ def is_valid_experiences_for_scoring(
2726def 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
3645def 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 )
0 commit comments