Ejemplo n.º 1
0
def test_end(clear):
    '''
    Testing usage of end()
    '''
    make_request(zid(), "I need halp")
    end()
    assert queue() == []
Ejemplo n.º 2
0
def end():
    '''
    A route for helpr.end()

    Returns: {}
    '''
    helpr.end()
    return dumps({})
Ejemplo n.º 3
0
def test_make_requet_error():
    '''
    test for error in make request function
    '''
    student1 = "z5263516"
    description1 = ""
    student2 = "z5263517"
    description2 = "What's the difference between c and python"

    # test empty string
    with pytest.raises(ValueError):
        make_request(student1, description1)

    # Student 2 makes a request
    make_request(student2, description2)

    # request again to test request exist
    with pytest.raises(KeyError):
        make_request(student2, description2)

    # End the session
    end()
Ejemplo n.º 4
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.º 5
0
def clear():
    end()