Skip to content

Instantly share code, notes, and snippets.

@lapshinmr
Created October 7, 2020 10:23
Show Gist options
  • Select an option

  • Save lapshinmr/564d0581bf86f562943b09e9112c2c3b to your computer and use it in GitHub Desktop.

Select an option

Save lapshinmr/564d0581bf86f562943b09e9112c2c3b to your computer and use it in GitHub Desktop.
def validate_argument_dict(dict_arg, dict_expected):
for key, value in dict_arg.items():
if key not in dict_expected:
raise ValueError(f'Wrong key {key}')
type_expected = type(dict_expected[key])
if not isinstance(value, type_expected):
raise ValueError(f'Wrong value type for the {key}. {type_expected} is expected.')
return dict_arg
PD_EXPECTED = {
'passport_last_name': '',
'passport_first_name': '',
'passport_middle_name': '',
'passport_number': '',
'passport_issue_date': '', # YYYY-MM-DD
'passport_birth_date': '', # YYYY-MM-DD
'passport_tin_number': '',
'country_code': '',
'phone': '',
'email': '',
}
pd = partial(validate_argument_dict, dict_expected=self.PD_EXPECTED)
parser = reqparse.RequestParser()
parser.add_argument('passport_last_name', required=True, type=pd, default=dict())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment