Take the component as string or a dict and will construct a TraceComponentDB. :param component: Should identify the component. If a string should be id of the component. If a dict should contain id and the caused_by. :type component: ``bson.ObjectId`` or ``dict``
(component)
| 398 | |
| 399 | |
| 400 | def _to_trace_component_db(component): |
| 401 | """ |
| 402 | Take the component as string or a dict and will construct a TraceComponentDB. |
| 403 | |
| 404 | :param component: Should identify the component. If a string should be id of the |
| 405 | component. If a dict should contain id and the caused_by. |
| 406 | :type component: ``bson.ObjectId`` or ``dict`` |
| 407 | |
| 408 | :rtype: ``TraceComponentDB`` |
| 409 | """ |
| 410 | if not isinstance(component, (six.string_types, dict)): |
| 411 | print(type(component)) |
| 412 | raise ValueError("Expected component to be str or dict") |
| 413 | |
| 414 | object_id = ( |
| 415 | component if isinstance(component, six.string_types) else component["id"] |
| 416 | ) |
| 417 | ref = component.get("ref", "") if isinstance(component, dict) else "" |
| 418 | caused_by = component.get("caused_by", {}) if isinstance(component, dict) else {} |
| 419 | |
| 420 | return TraceComponentDB(object_id=object_id, ref=ref, caused_by=caused_by) |
no test coverage detected