Ejemplo n.º 1
0
def test_revert_valid(clear):
    '''
    Testing a valid scenario of using revert()
    '''
    zid1 = zid(1)
    make_request(zid1, "I need halp")
    help(zid1)
    assert revert(zid1) is None
Ejemplo n.º 2
0
def test_help_no_waiting_request(clear):
    '''
    Testing for if a student does not have a request
        with a 'waiting' status
    '''
    zid1 = zid(1)
    make_request(zid1, "I need halp")
    help(zid1)
    with pytest.raises(KeyError):
        help(zid1)
Ejemplo n.º 3
0
def test_cancel_no_request_one(clear):
    '''
    Testing for no request in queue from student with 'waiting' status
    '''
    zid1 = zid(1)
    zid2 = zid(2)
    make_request(zid1, "I need halp")
    help(zid1)
    with pytest.raises(KeyError):
        cancel(zid1)
    with pytest.raises(KeyError):
        cancel(zid2)
Ejemplo n.º 4
0
def help():
    '''
    A route for helpr.help()

    Params: {"zid"}

    Raises: BadRequest if helpr.help() raises a KeyError.

    Returns: {}
    '''
    zid = request.get_json()['zid']
    try:
        helpr.help(zid)
    except KeyError as err:
        raise BadRequest(err)
    return dumps({})
Ejemplo n.º 5
0
def test_help_valid(clear):
    '''
    Testing valid scenario of using help()
    '''
    zid1 = zid(1)
    make_request(zid1, "I need halp")
    assert help(zid1) is None
Ejemplo n.º 6
0
def help():
    '''
    A route for helpr.help()

    Params: {"zid"}

    Raises: BadRequest if helpr.help() raises a KeyError.

    Returns: {}
    '''
    # Get input data
    input_data = request.get_json()
    try:
        helpr.help(input_data["zid"])
        return dumps({})
    except KeyError:
        raise BadRequest
Ejemplo n.º 7
0
def test_reprioritise_valid(clear):
    '''
    Testing if reprioritisation works
    '''
    zid1 = zid(1)
    zid2 = zid(2)
    zid3 = zid(3)
    zid4 = zid(4)
    make_request(zid1, "first request")
    make_request(zid2, "second request")
    make_request(zid3, "third request")
    help(zid1)
    resolve(zid1)
    help(zid2)
    resolve(zid2)
    make_request(zid1, "fourth request")
    make_request(zid2, "fifth request")
    help(zid2)
    resolve(zid2)
    make_request(zid2, "seventh request")
    make_request(zid4, "sixth request")
    assert queue() == [{
        "zid": zid3,
        "description": "third request",
        "status": "waiting"
    }, {
        "zid": zid1,
        "description": "fourth request",
        "status": "waiting"
    }, {
        "zid": zid2,
        "description": "seventh request",
        "status": "waiting"
    }, {
        "zid": zid4,
        "description": "sixth request",
        "status": "waiting"
    }]

    reprioritise()

    assert queue() == [{
        "zid": zid3,
        "description": "third request",
        "status": "waiting"
    }, {
        "zid": zid4,
        "description": "sixth request",
        "status": "waiting"
    }, {
        "zid": zid1,
        "description": "fourth request",
        "status": "waiting"
    }, {
        "zid": zid2,
        "description": "seventh request",
        "status": "waiting"
    }]
Ejemplo n.º 8
0
def test_sanity():
    '''
    A simple sanity test of the system.
    '''
    # DO NOT CHANGE THIS TEST! If you feel you have to change this test then
    # your functions have not been implemented correctly.
    student1 = "z1234567"
    description1 = "I don't understand how 'global' works in python"
    student2 = "z7654321"
    description2 = "What's the difference between iterator and iterable?"

    # Queue is initially empty
    assert queue() == []

    # Student 1 makes a request
    make_request(student1, description1)
    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "waiting"
    }]
    assert remaining(student1) == 0

    # Student 2 makes a request
    make_request(student2, description2)
    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "waiting"
    }, {
        "zid": student2,
        "description": description2,
        "status": "waiting"
    }]
    assert remaining(student1) == 0
    assert remaining(student2) == 1

    # Student 1 gets help
    help(student1)
    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "receiving"
    }, {
        "zid": student2,
        "description": description2,
        "status": "waiting"
    }]
    # Student 2 is now the only student "waiting" in the queue, so they have no
    # one remaining in front of them
    assert remaining(student2) == 0

    # Student 1 has their problem resolved
    resolve(student1)
    # Only student 2 is left in the queue
    assert queue() == [{
        "zid": student2,
        "description": description2,
        "status": "waiting"
    }]

    # Student is helped and their problem is resolved
    help(student2)
    resolve(student2)
    assert queue() == []

    # End the session
    end()
Ejemplo n.º 9
0
def test_remaining_error():
    """
    test for all the rests errors
    """
    student1 = "z1234567"
    description1 = "I don't understand how 'global' works in python"
    student2 = "z7654321"
    description2 = "What's the difference between iterator and iterable?"

    make_request(student1, description1)
    make_request(student2, description2)

    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "waiting"
    }, {
        "zid": student2,
        "description": description2,
        "status": "waiting"
    }]

    # student 2 cancle request
    cancel(student2)
    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "waiting"
    }]

    # student 2 make request again
    make_request(student2, description2)
    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "waiting"
    }, {
        "zid": student2,
        "description": description2,
        "status": "waiting"
    }]

    assert remaining(student1) == 0

    # help student1, status change from waiting to recieving
    help(student1)
    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "receiving"
    }, {
        "zid": student2,
        "description": description2,
        "status": "waiting"
    }]

    # student1 is receiving not waiting
    with pytest.raises(KeyError):
        remaining(student1)

    # student1 is receiving, can't help
    with pytest.raises(KeyError):
        help(student1)
    # student1 is receiving, can't cancel
    with pytest.raises(KeyError):
        cancel(student1)
    # tutor too busy, revert student 1
    revert(student1)
    assert queue() == [{
        "zid": student1,
        "description": description1,
        "status": "waiting"
    }, {
        "zid": student2,
        "description": description2,
        "status": "waiting"
    }]

    # tutor can't revert student 1 again
    with pytest.raises(KeyError):
        revert(student1)

    # student2 is waiting, can't resolve
    with pytest.raises(KeyError):
        resolve(student2)