Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

test_modifiableobject.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from typing import (
  2. Iterable,
  3. List,
  4. Optional
  5. )
  6. import unittest
  7. from dataladmetadatamodel.modifiableobject import ModifiableObject
  8. destination = "/tmp/t"
  9. class SUTModifiableObject(ModifiableObject):
  10. def __init__(self, saved_on: Optional[str] = None):
  11. super().__init__()
  12. if saved_on is not None:
  13. self.set_saved_on(saved_on)
  14. self.something = "Something " * 100
  15. @property
  16. def modifiable_sub_objects(self) -> Iterable:
  17. return []
  18. class TestModifiableObject(unittest.TestCase):
  19. def test_new_clean(self):
  20. mo = SUTModifiableObject()
  21. self.assertFalse(mo.is_saved_on(destination))
  22. def test_touching_cleaning(self):
  23. mo = SUTModifiableObject()
  24. self.assertFalse(mo.is_saved_on(destination))
  25. mo.set_saved_on(destination)
  26. self.assertTrue(mo.is_saved_on(destination))
  27. def test_sub_object_modification(self):
  28. class Bag(ModifiableObject):
  29. def __init__(self, _sub_objects: List[ModifiableObject]):
  30. super().__init__()
  31. self.sub_objects = _sub_objects
  32. @property
  33. def modifiable_sub_objects(self) -> Iterable[ModifiableObject]:
  34. return self.sub_objects
  35. sub_objects = [SUTModifiableObject(destination) for _ in range(3)]
  36. bag = Bag(sub_objects)
  37. bag.set_saved_on(destination)
  38. self.assertTrue(bag.is_saved_on(destination), f"Expected complete bag is saved on {destination}")
  39. sub_objects[0].touch()
  40. self.assertFalse(bag.is_saved_on(destination), f"Expected modified bag is not saved on {destination}")
  41. if __name__ == '__main__':
  42. unittest.main()