Created
October 7, 2020 10:23
-
-
Save lapshinmr/564d0581bf86f562943b09e9112c2c3b to your computer and use it in GitHub Desktop.
Revisions
-
lapshinmr created this gist
Oct 7, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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())