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.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. def get_modifiable_sub_objects(self) -> Iterable:
  16. return []
  17. class TestModifiableObject(unittest.TestCase):
  18. def test_new_clean(self):
  19. mo = SUTModifiableObject()
  20. self.assertFalse(mo.is_saved_on(destination))
  21. def test_touching_cleaning(self):
  22. mo = SUTModifiableObject()
  23. self.assertFalse(mo.is_saved_on(destination))
  24. mo.set_saved_on(destination)
  25. self.assertTrue(mo.is_saved_on(destination))
  26. def test_sub_object_modification(self):
  27. class Bag(ModifiableObject):
  28. def __init__(self, _sub_objects: List[ModifiableObject]):
  29. super().__init__()
  30. self.sub_objects = _sub_objects
  31. def get_modifiable_sub_objects(self) -> Iterable[ModifiableObject]:
  32. return self.sub_objects
  33. sub_objects = [SUTModifiableObject(destination) for _ in range(3)]
  34. bag = Bag(sub_objects)
  35. bag.set_saved_on(destination)
  36. self.assertTrue(bag.is_saved_on(destination), f"Expected complete bag is saved on {destination}")
  37. sub_objects[0].touch()
  38. self.assertFalse(bag.is_saved_on(destination), f"Expected modified bag is not saved on {destination}")
  39. if __name__ == '__main__':
  40. unittest.main()