예제 #1
0
def test_setters():
    job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user)

    timestamp = datetime.datetime.now()
    job.set_start_time(timestamp)
    job.set_end_time(timestamp)
    job.set_enqueue_time(timestamp)
    assert job.get_start_time() == timestamp
    assert job.get_end_time() == timestamp
    assert job.get_enqueue_time() == timestamp

    job.set_status(JobStatus.DONE)
    assert job.get_status() == JobStatus.DONE
    assert job.has_start_notification() == job.has_start_notification()
    assert job.has_end_notification() == job.has_end_notification()
    assert job.has_error_notification() == job.has_error_notification()
예제 #2
0
def test_build_log():
    try:
        user = User.get_user_by_username("rbuser")
    except UserNotFoundException:
        user = User("rbuser", "token")

    job1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user)
    job1_id = job1.get_job_id()
    job1.set_status(JobStatus.DONE)
    timestamp = datetime.datetime.now()
    job1.set_enqueue_time(timestamp)
    job1.set_end_time(timestamp)

    job2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user)
    job2_id = job2.get_job_id()
    job2.set_status(JobStatus.DONE)
    timestamp = datetime.datetime.now()
    job2.set_enqueue_time(timestamp)
    job2.set_end_time(timestamp)

    job1 = Job.get_job_by_id(job1_id)
    job2 = Job.get_job_by_id(job2_id)
    answer = json.loads(rb.build_log([job1, job2]))

    job1 = Job.get_job_by_id(job1_id)
    assert answer[0]["job_id"] == job1.get_job_id()
    assert answer[0]["source"] == job1.get_source_alias(
    ) + ":" + job1.get_source_relative_path()
    assert answer[0]["target"] == job1.get_target_alias()
    assert answer[0]["enqueue_time"] == job1.get_enqueue_time().isoformat()
    assert answer[0]["end_time"] == job1.get_end_time().isoformat()
    assert answer[0]["creator"] == job1.get_user().get_username()
    assert answer[0]["status"] == job1.get_status().name
    assert answer[0]["error"] == job1.get_error()

    job2 = Job.get_job_by_id(job2_id)
    assert answer[1]["job_id"] == job2.get_job_id()
    assert answer[1]["source"] == job2.get_source_alias(
    ) + ":" + job2.get_source_relative_path()
    assert answer[1]["target"] == job2.get_target_alias()
    assert answer[1]["enqueue_time"] == job2.get_enqueue_time().isoformat()
    assert answer[1]["end_time"] == job2.get_end_time().isoformat()
    assert answer[1]["creator"] == job2.get_user().get_username()
    assert answer[1]["status"] == job2.get_status().name
    assert answer[1]["error"] == job2.get_error()
예제 #3
0
def test_build_job():
    try:
        user = User.get_user_by_username("rbuser")
    except UserNotFoundException:
        user = User("rbuser", "token")
    job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user)
    job.set_status(JobStatus.QUEUED)
    timestamp = datetime.datetime.now()
    job.set_enqueue_time(timestamp)

    answer = json.loads(rb.build_job(job))
    assert answer["job_id"] == job.get_job_id()
    assert answer["source"] == job.get_source_alias(
    ) + ":" + job.get_source_relative_path()
    assert answer["target"] == job.get_target_alias()
    assert answer["enqueue_time"] == job.get_enqueue_time().isoformat()
    assert answer["creator"] == job.get_user().get_username()
    assert answer["status"] == job.get_status().name
    return
예제 #4
0
def test_get_log_different_days():
    """
    /SA240/
    """
    try:
        user1 = User.get_user_by_username("loguser2")
        jobs = Job.get_jobs([user1.get_username()], [
            JobStatus.PAUSED, JobStatus.QUEUED, JobStatus.ACTIVE,
            JobStatus.DONE
        ])
        for current_job in jobs:
            current_job.set_status(JobStatus.ACTIVE)
    except UserNotFoundException:
        user1 = User("loguser2", "token")

    timestamp = datetime.date.today() - datetime.timedelta(days=2)

    active_job_ids_user1 = []
    job1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1)
    job1.set_status(JobStatus.DONE)
    job1.set_start_time(timestamp)
    job1.set_end_time(timestamp)
    job1.set_enqueue_time(timestamp)
    active_job_ids_user1.append(job1.get_job_id())

    job2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1)
    job2.set_status(JobStatus.DONE)
    job2.set_start_time(timestamp)
    job2.set_end_time(timestamp)
    job2.set_enqueue_time(timestamp)

    active_job_ids_user1.append(job2.get_job_id())
    job3 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1)
    job3.set_status(JobStatus.DONE)
    job3.set_start_time(timestamp)
    job3.set_end_time(timestamp)
    job3.set_enqueue_time(timestamp)
    active_job_ids_user1.append(job3.get_job_id())

    # Log for last 3 days
    request = {"days": "3", "user": "******", "for_user": "******"}

    json_string = json.dumps(request)
    response = json.loads(app.get_log(json_string))

    assert len(response) == 3
    for job in response:
        assert job['job_id'] in active_job_ids_user1

    # Log for last day
    request = {"days": "1", "user": "******", "for_user": "******"}

    json_string = json.dumps(request)
    response = json.loads(app.get_log(json_string))

    assert len(response) == 0
예제 #5
0
def test_get_queue():
    """
    /SA310/
    """
    jobs = Job.get_jobs(None, [JobStatus.QUEUED])
    for current_job in jobs:
        current_job.set_status(JobStatus.DONE)
    assert len(Job.get_jobs(None, [JobStatus.QUEUED])) == 0

    timestamp = datetime.datetime.now()

    try:
        admin = User.get_user_by_username("queueadmin1")
    except UserNotFoundException:
        admin = Administrator("queueadmin1", "token")

    job1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], admin)
    job1_id = job1.get_job_id()
    job1.set_status(JobStatus.QUEUED)
    job1.set_enqueue_time(timestamp)
    job1.set_priority(1)

    try:
        user = User.get_user_by_username("queueuser1")
    except UserNotFoundException:
        user = Administrator("queueuser1", "token")

    job2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user)
    job2_id = job2.get_job_id()
    job2.set_status(JobStatus.QUEUED)
    job2.set_enqueue_time(timestamp)
    job2.set_priority(2)

    job3 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user)
    job3_id = job3.get_job_id()
    job3.set_status(JobStatus.QUEUED)
    job3.set_enqueue_time(timestamp)
    job3.set_priority(3)

    response = json.loads(app.get_queue())
    assert len(response) == 3
    for job_json in response:
        job = Job.get_job_by_id(job_json['job_id'])
        assert job_json['job_id'] == job1_id or job_json[
            'job_id'] == job2_id or job_json['job_id'] == job3_id
        assert job_json['job_id'] == job.get_job_id()
        assert job_json['source'] == job.get_source_alias(
        ) + ":" + job.get_source_relative_path()
        assert job_json['enqueue_time'] == job.get_enqueue_time().isoformat()
        assert job_json['creator'] == job.get_user().get_username()
        assert job_json['priority'] == job.get_priority()
        assert job_json['status'] == job.get_status().name
예제 #6
0
def test_get_log():
    """
    1. Admin requests logs of user. /SA210/
    2. User requests his own logs /SA220/
    3. Another user(not admin) requests logs of user /SA230/
    :return:
    """
    try:
        user1 = User.get_user_by_username("loguser1")
        jobs = Job.get_jobs([user1.get_username()], [
            JobStatus.PAUSED, JobStatus.QUEUED, JobStatus.ACTIVE,
            JobStatus.DONE
        ])
        for current_job in jobs:
            current_job.set_status(JobStatus.ACTIVE)
    except UserNotFoundException:
        user1 = User("loguser1", "token")

    timestamp = datetime.datetime.now()

    active_job_ids_user1 = []
    job1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1)
    job1.set_status(JobStatus.DONE)
    job1.set_start_time(timestamp)
    job1.set_end_time(timestamp)
    job1.set_enqueue_time(timestamp)
    active_job_ids_user1.append(job1.get_job_id())

    job2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1)
    job2.set_status(JobStatus.DONE)
    job2.set_start_time(timestamp)
    job2.set_end_time(timestamp)
    job2.set_enqueue_time(timestamp)

    active_job_ids_user1.append(job2.get_job_id())
    job3 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1)
    job3.set_status(JobStatus.DONE)
    job3.set_start_time(timestamp)
    job3.set_end_time(timestamp)
    job3.set_enqueue_time(timestamp)
    active_job_ids_user1.append(job3.get_job_id())

    # -----------1------------
    try:
        admin = User.get_user_by_username("logadmin1")
    except UserNotFoundException:
        admin = Administrator("logadmin1", "token")

    request = {"days": "5", "user": "******", "for_user": "******"}

    json_string = json.dumps(request)
    response = json.loads(app.get_log(json_string))

    assert len(response) == 3
    for job in response:
        assert job['job_id'] in active_job_ids_user1

    # -----------2------------
    request = {"days": "5", "user": "******", "for_user": "******"}

    json_string = json.dumps(request)
    response = json.loads(app.get_log(json_string))

    assert len(response) == 3
    for job in response:
        assert job['job_id'] in active_job_ids_user1

    # -----------3------------
    try:
        false_admin = User.get_user_by_username("logadminfalse1")
    except UserNotFoundException:
        false_admin = User("logadminfalse1", "token")

    request = {"days": "5", "user": "******", "for_user": "******"}

    json_string = json.dumps(request)
    with pytest.raises(PermissionException):
        app.get_log(json_string)