(cls, data, extra, udata)
| 398 | |
| 399 | @classmethod |
| 400 | def validate_record_data(cls, data, extra, udata): |
| 401 | # data - always present (UID, Title, ...) |
| 402 | if data: |
| 403 | data_types = { |
| 404 | 'folder': {'field': 'folder', 'name': 'folder', 'type': ''}, |
| 405 | 'title': {'field': 'title', 'name': 'title', 'type': ''}, |
| 406 | 'secret1': {'field': 'secret1', 'name': 'login', 'type': ''}, |
| 407 | 'secret2': {'field': 'secret2', 'name': 'password', 'type': ''}, |
| 408 | 'link': {'field': 'link', 'name': 'url', 'type': ''}, |
| 409 | 'notes': {'field': 'notes', 'name': 'notes', 'type': ''}, |
| 410 | 'custom': {'field': 'custom', 'name': 'custom', 'type': []} |
| 411 | } |
| 412 | |
| 413 | for item in data_types: |
| 414 | if item in data and type(data.get(item)) != type(data_types[item].get('type')): |
| 415 | raise ValueError('Error validating record data - "' + data_types[item].get('name') + '" is invalid!') |
| 416 | |
| 417 | if 'custom' in data and isinstance(data['custom'], list): |
| 418 | invalid = [x for x in data['custom'] if not(x)] |
| 419 | if invalid: |
| 420 | raise ValueError('Error validating record data - Invalid custom fields! ' + str(invalid)) |
| 421 | else: |
| 422 | raise Exception('Record is empty!') |
| 423 | |
| 424 | # extra and udata sections are optional |
| 425 | if extra: |
| 426 | fields = extra.get('fields') or [] |
| 427 | invalid = [x for x in fields if not(x)] |
| 428 | if invalid: |
| 429 | raise ValueError('Error validating record extra data - Invalid extra fields! ' + str(invalid)) |
no test coverage detected