__init__.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import copy
  2. import transaction
  3. class Fixture(object):
  4. """ Fixture classes (list) required for this fixtures"""
  5. require = NotImplemented
  6. def __init__(self, session, config):
  7. self._session = session
  8. self._config = config
  9. def insert(self):
  10. raise NotImplementedError()
  11. class FixturesLoader(object):
  12. """
  13. Fixtures loader. Load each fixture once.
  14. """
  15. def __init__(self, session, config, loaded=None):
  16. loaded = [] if loaded is None else loaded
  17. self._loaded = loaded
  18. self._session = session
  19. # FIXME - G.M - 2018-06-169 - Fixture failed with email_notification
  20. # activated, disable it there now. Find better way to fix this
  21. # later
  22. self._config = copy.copy(config)
  23. self._config.EMAIL_NOTIFICATION_ACTIVATED = False
  24. def loads(self, fixtures_classes):
  25. for fixture_class in fixtures_classes:
  26. for required_fixture_class in fixture_class.require:
  27. self._load(required_fixture_class)
  28. self._load(fixture_class)
  29. def _load(self, fixture_class: Fixture):
  30. if fixture_class not in self._loaded:
  31. fixture = fixture_class(
  32. session=self._session,
  33. config=self._config,
  34. )
  35. fixture.insert()
  36. self._loaded.append(fixture_class)
  37. self._session.flush()
  38. transaction.commit()