示例#1
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"
    }]
示例#2
0
def queue():
    '''
    A route for helpr.queue()

    Returns: A list in the same format as helpr.queue()
    '''
    return dumps(helpr.queue())
示例#3
0
def test_end(clear):
    '''
    Testing usage of end()
    '''
    make_request(zid(), "I need halp")
    end()
    assert queue() == []
示例#4
0
def test_queue_valid(clear):
    '''
    Testing correct return types for queue()
    '''
    make_request(zid(), "I need halp")
    queue_list = queue()
    assert isinstance(queue_list, list)
    for item in queue_list:
        assert isinstance(item, dict)
示例#5
0
def queue():
    '''
    A route for helpr.queue()

    Returns: A list in the same format as helpr.queue()
    '''

    output_data = helpr.queue()
    return dumps(output_data)
示例#6
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()
示例#7
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)