Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. case_obj = get_or_create_model('UnlockCase', {'client': client_obj,
  2. 'client2': client_obj,
  3. 'address': address_obj,
  4. 'state': 'TestState'})
  5.  
  6.  
  7. def get_or_create_model():
  8. def _get_or_create_model(modelname: str, data: dict):
  9. model_cls = getattr(models, modelname, None)
  10. if model_cls:
  11. model = model_cls.get(**data)
  12. if not model:
  13. model = model_cls(**data)
  14. commit()
  15. return model
  16. else:
  17. raise AttributeError('This model does not exists')
  18.  
  19.  
  20.  
  21. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  22. def test_get_user_ok(self, login, get_or_create_model, generate_address_model):
  23. email = 't@t.t'
  24. client_obj = get_or_create_model('Client', {'email': email,
  25. 'first_name': 'fn',
  26. 'last_name': 'ln'})
  27. address_obj = generate_address_model('full_addr', '12345', 'city', 'state')
  28. > case_obj = get_or_create_model('UnlockCase', {'client': client_obj,
  29. 'client2': client_obj,
  30. 'address': address_obj,
  31. 'state': 'TestState'})
  32.  
  33. test_api/test_user.py:11:
  34. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  35. conftest.py:40: in _get_or_create_model
  36. model = model_cls.get(**data)
  37. ../../.venv/lib/python3.8/site-packages/pony/orm/core.py:4001: in get
  38. try: return entity._find_one_(kwargs) # can throw MultipleObjectsFoundError
  39. ../../.venv/lib/python3.8/site-packages/pony/orm/core.py:4104: in _find_one_
  40. if obj is None: obj = entity._find_in_db_(avdict, unique, for_update, nowait, skip_locked)
  41. ../../.venv/lib/python3.8/site-packages/pony/orm/core.py:4160: in _find_in_db_
  42. sql, adapter, attr_offsets = entity._construct_sql_(query_attrs, False, limit, for_update, nowait, skip_locked)
  43. ../../.venv/lib/python3.8/site-packages/pony/orm/core.py:4260: in _construct_sql_
  44. elif not attr.columns: throw(NotImplementedError)
  45. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  46.  
  47. exc_type = <class 'NotImplementedError'>, args = (), kwargs = {}
  48.  
  49. def throw(exc_type, *args, **kwargs):
  50. if isinstance(exc_type, Exception):
  51. assert not args and not kwargs
  52. exc = exc_type
  53. else: exc = exc_type(*args, **kwargs)
  54. exc.__cause__ = None
  55. try:
  56. if not (pony.MODE == 'INTERACTIVE' and options.CUT_TRACEBACK):
  57. > raise exc
  58. E NotImplementedError
  59.  
  60. ../../.venv/lib/python3.8/site-packages/pony/utils/utils.py:106: NotImplementedError
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement