NotifyMock.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. class NotifyMock:
  12. """
  13. A shared class for testing notification on jobStatus of sequence level and scenario level
  14. "entity" can be understood as either "scenario" or "sequence".
  15. """
  16. def __init__(self, entity):
  17. self.scenario = entity
  18. self.nb_called = 0
  19. self.__name__ = "NotifyMock"
  20. def __call__(self, entity, job):
  21. assert entity == self.scenario
  22. if self.nb_called == 0:
  23. assert job.is_pending()
  24. if self.nb_called == 1:
  25. assert job.is_running()
  26. if self.nb_called == 2:
  27. assert job.is_finished()
  28. self.nb_called += 1
  29. def assert_called_3_times(self):
  30. assert self.nb_called == 3
  31. def assert_not_called(self):
  32. assert self.nb_called == 0
  33. def reset(self):
  34. self.nb_called = 0