def test_job_transition_crud(self) -> None:
        """
        Creates and fetch data from db
        :return:
        """
        # Insert one

        app_user = AppUser('*****@*****.**', 'pass', AppUserRole.ADMIN)
        job = Job(app_user)
        job_transition = JobTransition(JobStatusEnum.QUEUED, job)
        job_transition1 = JobTransitionRepository.create(job_transition)
        self.assertEqual(job_transition, job_transition1)

        job_transitions = JobTransitionRepository.get_all()
        self.assertEqual(1, len(job_transitions))
        self.assertEqual(job_transitions[0], job_transition1)

        # Insert and get many
        JobTransitionRepository.create_many([
            JobTransition(JobStatusEnum.IN_PROGRESS, job),
            JobTransition(JobStatusEnum.FINISHED, job)
        ])
        job_transitions = JobTransitionRepository.get_all()
        self.assertEqual(3, len(job_transitions))

        # Get by id
        job_transition_from_db = JobTransitionRepository.get_by_id(
            job_transition1.id)
        self.assertEqual(job_transition1, job_transition_from_db)
    def test_get_queued_job_to_process(self) -> None:
        # Should get no job
        no_job = JobRepository.get_queued_job_to_process()
        self.assertIsNone(no_job)

        # Should get job1
        app_user = AppUser('*****@*****.**', 'pass', AppUserRole.ADMIN)
        job1 = JobRepository.create(Job(app_user))
        JobTransitionRepository.create_many([JobTransition(JobStatusEnum.QUEUED, job1)]
                                            )
        queued_job = JobRepository.get_queued_job_to_process()
        self.assertEqual(job1, queued_job)

        # Should get job1 again even job2 is created
        job2 = JobRepository.create(Job(app_user))
        JobTransitionRepository.create_many([JobTransition(JobStatusEnum.QUEUED, job2)])
        queued_job = JobRepository.get_queued_job_to_process()
        self.assertEqual(job1, queued_job)

        # Should not get job1 cause it is finished, but job2
        JobTransitionRepository.create_many([
            JobTransition(JobStatusEnum.IN_PROGRESS, job1),
            JobTransition(JobStatusEnum.FINISHED, job1)
        ])

        finished_job = JobRepository.get_queued_job_to_process()
        self.assertEqual(job2, finished_job)