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_mappableobject.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import unittest
  2. from typing import (
  3. Iterable,
  4. Optional
  5. )
  6. from unittest.mock import MagicMock
  7. from dataladmetadatamodel.mappableobject import MappableObject
  8. from dataladmetadatamodel.mapper import set_mapper
  9. from dataladmetadatamodel.mapper.reference import Reference
  10. class SUTMappableObject(MappableObject):
  11. def __init__(self, reference=None):
  12. super().__init__(reference)
  13. self.something = "Something " * 100
  14. def deepcopy_impl(self,
  15. new_mapper_family: Optional[str] = None,
  16. new_destination: Optional[str] = None,
  17. **kwargs) -> "MappableObject":
  18. return self
  19. def purge_impl(self):
  20. self.something = None
  21. def get_modifiable_sub_objects_impl(self) -> Iterable:
  22. return []
  23. class TestMappableObject(unittest.TestCase):
  24. def setUp(self) -> None:
  25. self.test_mapper = MagicMock(
  26. map_out=MagicMock(return_value=Reference(
  27. "git",
  28. "/test",
  29. "SUTMappableObject",
  30. "location:00001111"
  31. ))
  32. )
  33. set_mapper("SUTMappableObject", "git", self.test_mapper)
  34. def test_new_mapped(self):
  35. # expect that a newly created object without reference is written out once
  36. mo = SUTMappableObject()
  37. mo.write_out("/tmp/t", "git")
  38. self.test_mapper.map_out.assert_called_once_with(mo, "/tmp/t", False)
  39. mo.write_out("/tmp/t", "git")
  40. self.test_mapper.map_out.assert_called_once_with(mo, "/tmp/t", False)
  41. def test_purge(self):
  42. mo = SUTMappableObject(None)
  43. self.assertRaises(ValueError, mo.purge)
  44. mo.write_out("/tmp/t", "git")
  45. mo.purge()
  46. self.test_mapper.map_out.assert_called_once_with(mo, "/tmp/t", False)
  47. def test_purge_unsaved(self):
  48. mo = SUTMappableObject(None)
  49. self.assertRaises(ValueError, mo.purge)
  50. if __name__ == '__main__':
  51. unittest.main()