Exemplo n.º 1
0
def test_full_activities_reassign(app, planner_client, maintainer_user,
                                  maintainer_users, activity_seed,
                                  activity_seed_without_id, week_days):
    """ Tests a successful retrival of the weekly availabilities when a maintainer
        already has a full schedule and the activity is already associated with that maintainer"""

    start_time = config.MAINTAINER_WORK_START_HOUR
    end_time = start_time + config.MAINTAINER_WORK_HOURS

    with app.app_context():
        work_hours = config.MAINTAINER_WORK_HOURS
        i = start_time
        while i < end_time - 1:
            activity = MaintenanceActivityModel(**activity_seed_without_id)
            activity.maintainer_username = maintainer_user["username"]
            activity.week_day = "monday"
            activity.start_time = i
            activity.save_to_db()
            i += 1
        activity = MaintenanceActivityModel(**activity_seed)
        activity.maintainer_username = maintainer_user["username"]
        activity.week_day = "monday"
        activity.start_time = i
        activity.save_to_db()

    test_current_page = 1
    test_page_size = len(maintainer_users)
    data = {"current_page": test_current_page, "page_size": test_page_size}

    res = planner_client.get(
        f"/maintainer/{activity_seed['activity_id']}/availabilities",
        data=data)

    validate_successful_response(res, test_current_page, test_page_size,
                                 maintainer_users, activity_seed, week_days)

    maintainer_availability = next(
        row["weekly_percentage_availability"] for row in res.get_json()["rows"]
        if row["user"]["username"] == maintainer_user["username"])

    assert maintainer_availability[
        "monday"] == f"{round(100 - 100*(work_hours-1)/work_hours)}%"
Exemplo n.º 2
0
def test_full_activities_success(app, planner_client, maintainer_user,
                                 maintainer_users, activity_seed,
                                 activity_seed_without_id, week_days):
    """ Tests a successful retrival of the weekly availabilities when a maintainer
    has an already full schedule """
    start_time = config.MAINTAINER_WORK_START_HOUR
    end_time = start_time + config.MAINTAINER_WORK_HOURS

    with app.app_context():
        # Create many assigned activities without filling all the maintainer work schedule
        i = start_time
        while i < end_time:
            activity = MaintenanceActivityModel(**activity_seed_without_id)
            activity.maintainer_username = maintainer_user["username"]
            activity.week_day = "monday"
            activity.start_time = i
            activity.save_to_db()
            i += 1
        # Create one unassigned activity
        activity = MaintenanceActivityModel(**activity_seed)
        activity.save_to_db()

    test_current_page = 1
    test_page_size = len(maintainer_users)
    data = {"current_page": test_current_page, "page_size": test_page_size}

    res = planner_client.get(
        f"/maintainer/{activity_seed['activity_id']}/availabilities",
        data=data)

    validate_successful_response(res, test_current_page, test_page_size,
                                 maintainer_users, activity_seed, week_days)

    maintainer_availability = next(
        row["weekly_percentage_availability"] for row in res.get_json()["rows"]
        if row["user"]["username"] == maintainer_user["username"])

    assert maintainer_availability["monday"] == "0%"