def test_expire_jobs(mocker, one_hour_ago, spark_job_factory):
    spark_job = spark_job_factory(end_date=one_hour_ago)
    # manually adding the job to the schedule since we do a check
    # in the post_save signal handler for the end_date
    spark_job.schedule.add()
    mocker.spy(schedules.SparkJobSchedule, "delete")
    result = tasks.expire_jobs()
    # 2 since 1 is called as part of the expire call and one
    # by the save call
    assert spark_job.schedule.delete.call_count == 2
    assert result == [[spark_job.identifier, spark_job.pk]]
def test_expire_jobs(mocker, one_hour_ago, spark_job_factory):
    spark_job = spark_job_factory(end_date=one_hour_ago)
    # manually adding the job to the schedule since we do a check
    # in the post_save signal handler for the end_date
    spark_job.schedule.add()
    mocker.spy(schedules.SparkJobSchedule, 'delete')
    result = tasks.expire_jobs()
    # 2 since 1 is called as part of the expire call and one
    # by the save call
    assert spark_job.schedule.delete.call_count == 2
    assert result == [[spark_job.identifier, spark_job.pk]]
def test_expire_and_no_schedule_delete(mocker, one_hour_ago, spark_job_factory):
    # adding one Spark job to the schedule
    spark_job1 = spark_job_factory(end_date=one_hour_ago)
    spark_job1.schedule.add()

    # the other we don't add to make sure the logging isn't triggered
    spark_job2 = spark_job_factory(end_date=one_hour_ago)

    mocker.spy(schedules.SparkJobSchedule, "delete")
    result = tasks.expire_jobs()
    # 4 since 1 is called as part of the expire call and one
    # by the save call, x 2 jobs to expire
    assert schedules.SparkJobSchedule.delete.call_count == 4
    assert sorted(result) == sorted(
        [[spark_job1.identifier, spark_job1.pk], [spark_job2.identifier, spark_job2.pk]]
    )
def test_expire_and_no_schedule_delete(mocker, one_hour_ago, spark_job_factory):
    # adding one Spark job to the schedule
    spark_job1 = spark_job_factory(end_date=one_hour_ago)
    spark_job1.schedule.add()

    # the other we don't add to make sure the logging isn't triggered
    spark_job2 = spark_job_factory(end_date=one_hour_ago)

    mocker.spy(schedules.SparkJobSchedule, 'delete')
    result = tasks.expire_jobs()
    # 4 since 1 is called as part of the expire call and one
    # by the save call, x 2 jobs to expire
    assert schedules.SparkJobSchedule.delete.call_count == 4
    assert sorted(result) == sorted([
        [spark_job1.identifier, spark_job1.pk],
        [spark_job2.identifier, spark_job2.pk],
    ])
def test_dont_expire_jobs(mocker, one_hour_ahead, spark_job_factory):
    spark_job = spark_job_factory(end_date=one_hour_ahead)
    mocker.spy(schedules.SparkJobSchedule, "delete")
    result = tasks.expire_jobs()
    assert spark_job.schedule.delete.call_count == 0
    assert result == []
def test_dont_expire_jobs(mocker, one_hour_ahead, spark_job_factory):
    spark_job = spark_job_factory(end_date=one_hour_ahead)
    mocker.spy(schedules.SparkJobSchedule, 'delete')
    result = tasks.expire_jobs()
    assert spark_job.schedule.delete.call_count == 0
    assert result == []