workflows: Holding Pen previous/next robustness

* Makes the previous/next object getter more robust.

* Adds unit tests for this functionality.

Reviewed-by: Jiri Kuncar <jiri.kuncar@cern.ch>
Signed-off-by: Jan Aage Lavik <jan.age.lavik@cern.ch>