Пример #1
0
def test_add_message_to_ticket(app, client):
    """
    Add message to existing ticket
    """
    userId = 1234
    testMessage = "this is a test message"
    create_user(app, userId)

    courseId = uuid.uuid4()
    create_course(app, courseId)

    ticketId = uuid.uuid4()
    create_ticket(app, ticketId, userId, courseId)

    auth = login(client, userId)

    rv = client.post('/api/ticket/{}/messages'.format(ticketId),
                     json={
                         'message': testMessage,
                         'user_id': userId
                     },
                     headers={'Authorization': auth})
    json_data = rv.get_json()
    assert rv.status == "201 CREATED"
    assert len(json_data) > 0
    print(json_data)

    rv2 = client.get('/api/ticket/{}/messages'.format(ticketId),
                     headers={'Authorization': auth})
    assert rv2.status == '200 OK'
    json_data = rv2.get_json()
    assert json_data['json_data'][0]['text'] == testMessage
    assert json_data['json_data'][0]['user_id'] == userId
    assert len(json_data['json_data']) == 1
    print(rv2.get_json())
Пример #2
0
def test_remove_note(app, client):
    """
    Test the api call to remove a note
    """
    usr = create_user(app, 1234)
    courseId = uuid.uuid4()
    c = create_course(app, courseId)

    link_ta_to_course(usr, c)

    ticketId = uuid.uuid4()
    create_ticket(app, ticketId, 1234, courseId)

    noteId1 = uuid.uuid4()
    noteId2 = uuid.uuid4()
    create_note(app, noteId1, ticketId, 1234, "dit is een test bericht")
    create_note(app, noteId2, ticketId, 1234, "dit is een test bericht2")

    auth = login(client, 1234)
    rv = client.post('/api/notes/{}/close'.format(noteId1),
                     headers={'Authorization': auth}
                     )

    json_data = rv.get_json()
    assert rv.status == "202 ACCEPTED"

    rv2 = client.get('/api/notes/{}'.format(ticketId),
                     headers={'Authorization': auth})
    json_data = rv2.get_json()
    print(json_data)
    assert len(json_data['json_data']) == 1
Пример #3
0
def test_get_ticket_notes(app, client):
    """
    Test the api call to get all notes belonging to a ticket
    """
    usr = create_user(app, 1234)
    ticketId = uuid.uuid4()
    ticketId2 = uuid.uuid4()
    courseId = uuid.uuid4()

    c = create_course(app, courseId)
    create_ticket(app, ticketId, 1234, courseId)
    create_ticket(app, ticketId2, 1234, courseId)

    link_ta_to_course(usr, c)

    auth = login(client, 1234)

    noteId1 = uuid.uuid4()
    noteId2 = uuid.uuid4()
    noteId3 = uuid.uuid4()
    create_note(app, noteId1, ticketId, 1234, "dit is een test bericht")
    create_note(app, noteId2, ticketId, 1234, "dit is een test bericht2")
    create_note(app, noteId3, ticketId2, 1234, "deze zou je niet moeten zien")

    rv = client.get('/api/notes/{}'.format(ticketId),
                    headers={'Authorization': auth})

    json_data = rv.get_json()
    print(json_data)
    assert len(json_data['json_data']) == 2
    assert rv.status == '200 OK'
Пример #4
0
def test_add_new_note(app, client):
    """
    Test the api call to add a new note to a ticket
    """
    usr = create_user(app, 1234)
    courseId = uuid.uuid4()
    c = create_course(app, courseId)
    ticketId = uuid.uuid4()
    create_ticket(app, ticketId, 1234, courseId)

    link_ta_to_course(usr, c)

    auth = login(client, 1234)

    rv = client.post('/api/notes', json={
        "ticket_id": ticketId,
        "user_id": 1234,
        "text": "dit is een test notitie"
    }, headers={
        'Authorization': auth
    })
    assert rv.status == '201 CREATED'

    rv2 = client.get('/api/notes/{}'.format(ticketId),
                     headers={'Authorization': auth})
    json_data = rv2.get_json()
    print(json_data)
    assert len(json_data['json_data']) == 1
    assert rv2.status == '200 OK'
Пример #5
0
def test_get_ticket_messages(app, client):
    """
    Get messages which belong to a ticket
    """
    userId1 = 1234
    userId2 = 4321
    testMessage1 = "this is a test message1"
    testMessage2 = "this is a test message2"
    create_user(app, userId1)
    create_user(app, userId2)

    courseId = uuid.uuid4()
    create_course(app, courseId)

    ticketId = uuid.uuid4()
    create_ticket(app, ticketId, userId1, courseId)

    auth1 = login(client, userId1)
    auth2 = login(client, userId2)

    client.post('/api/ticket/{}/messages'.format(ticketId),
                json={
                    'message': testMessage1,
                    'user_id': userId1
                },
                headers={'Authorization': auth1})
    client.post('/api/ticket/{}/messages'.format(ticketId),
                json={
                    'message': testMessage2,
                    'user_id': userId2
                },
                headers={'Authorization': auth2})

    rv2 = client.get('/api/ticket/{}/messages'.format(ticketId),
                     headers={'Authorization': auth1})
    assert rv2.status == '200 OK'
    json_data = rv2.get_json()
    assert json_data['json_data'][0]['text'] == testMessage1
    assert json_data['json_data'][0]['user_id'] == userId1
    assert json_data['json_data'][1]['text'] == testMessage2
    assert json_data['json_data'][1]['user_id'] == userId2
    assert len(json_data['json_data']) == 2
    print(rv2.get_json())
Пример #6
0
def test_close_ticket(app, client):
    """
    Close a ticket
    """
    userId = 1234
    usr = create_user(app, userId)

    courseId = uuid.uuid4()
    c = create_course(app, courseId)

    link_ta_to_course(usr, c)

    ticketId1 = uuid.uuid4()
    ticketId2 = uuid.uuid4()
    create_ticket(app, ticketId1, userId, courseId)
    create_ticket(app, ticketId2, userId, courseId)

    auth = login(client, userId)

    rv = client.post('/api/ticket/{}/close'.format(ticketId1),
                     headers={'Authorization': auth})

    json_data = rv.get_json()
    assert rv.status == "200 OK"
    print(json_data)

    rv2 = client.get('/api/courses/{}/tickets'.format(courseId),
                     headers={'Authorization': auth})
    json_data2 = rv2.get_json()

    accepted = False
    for x in json_data2['json_data']:
        if (x['id'] == str(ticketId1) and x['status']['id'] == 2):
            accepted = True
        if (x['id'] == str(ticketId2) and x['status']['id'] == 2):
            accepted = False
            break

    assert accepted
    assert len(json_data2['json_data']) == 2
    assert rv2.status == "200 OK"
Пример #7
0
def test_user_auth(app, client):
    create_user(app, 1234)
    id1 = uuid.uuid4()
    id2 = uuid.uuid4()
    courseId = uuid.uuid4()

    create_course(app, courseId)
    create_ticket(app, id1, 1234, courseId, 1)
    create_ticket(app, id2, 1234, courseId, 2)

    rv = client.get('/api/user/{}/tickets/active'.format(1234))
    rv2 = client.get('/api/user/tickets'.format(1234))
    rv3 = client.get('/api/user/tickets'.format(1234),
                     headers={'Authorization': ""})

    print(rv.status)
    print(rv2.status)
    print(rv3.status)
    assert rv.status == "401 UNAUTHORIZED"
    assert rv2.status == "401 UNAUTHORIZED"
    assert rv3.status == "401 UNAUTHORIZED"
Пример #8
0
def test_get_active_student_tickets(app, client):
    create_user(app, 1234)
    id1 = uuid.uuid4()
    id2 = uuid.uuid4()
    courseId = uuid.uuid4()

    create_course(app, courseId)
    create_ticket(app, id1, 1234, courseId, 1)
    create_ticket(app, id2, 1234, courseId, 2)

    auth = login(client, 1234)
    rv = client.get('/api/user/{}/tickets/active'.format(1234),
                    headers={'Authorization': auth})
    rv2 = client.get('/api/user/tickets', headers={'Authorization': auth})

    active_tickets = rv.get_json()['json_data']
    all_tickets = rv2.get_json()['json_data']
    assert rv.status == '200 OK'
    assert len(active_tickets) > 0
    assert len(all_tickets) - len(active_tickets) == 1
    assert len(all_tickets) != len(active_tickets)
Пример #9
0
def test_get_user_tickets(app, client):
    """
    Test the api call to get the tickets of one users
    """

    create_user(app, 1234)

    id1 = uuid.uuid4()
    id2 = uuid.uuid4()
    courseId = uuid.uuid4()

    create_course(app, courseId)
    create_ticket(app, id1, 1234, courseId)
    create_ticket(app, id2, 1234, courseId)

    auth = login(client, 1234)

    rv = client.get('/api/user/tickets', headers={'Authorization': auth})
    json_data = rv.get_json()
    assert rv.status == '200 OK'
    assert len(json_data['json_data']) > 0
    print(json_data['json_data'])
Пример #10
0
def test_get_ta_tickets(app, client):
    """
    Test the api call to get one user.
    """
    taId = 1234
    student = 4321
    ta = create_user(app, taId)
    usr = create_user(app, student)

    courseId1 = uuid.uuid4()
    courseId2 = uuid.uuid4()
    course1 = create_course(app, courseId1)
    course2 = create_course(app, courseId2)

    link_ta_to_course(ta, course1)
    link_student_to_course(ta, course2)

    auth = login(client, ta.id)

    ticketId1 = uuid.uuid4()
    ticketId2 = uuid.uuid4()
    # create ticket in course where TA
    ticket1 = create_ticket(app, ticketId1, taId, courseId1)
    link_ta_to_ticket(ta, ticket1)
    # create ticket in course where not TA
    create_ticket(app, ticketId2, taId, courseId2)

    rv = client.get('/api/ta/{}/tickets'.format(taId),
                    headers={'Authorization': auth})
    json_data = rv.get_json()['json_data']
    assert rv.status == '200 OK'
    print(json_data)
    assert len(json_data) == 1
    print(json_data[0]['tas'])
    assert len(json_data[0]['tas']) == 1
    assert json_data[0]['tas'][0]['id'] == taId
Пример #11
0
def test_get_course_tickets(app, client):
    """
    Test the api call to get all tickets belonging to this course
    """

    usr = create_user(app, 1234)

    ticketId = uuid.uuid4()
    ticketId2 = uuid.uuid4()
    ticketId3 = uuid.uuid4()

    courseId = uuid.uuid4()
    courseId2 = uuid.uuid4()

    auth = login(client, usr.id)

    c = create_course(app, courseId, tas=[usr])
    c2 = create_course(app, courseId2, tas=[usr])

    create_ticket(app, ticketId, 1234, courseId)
    create_ticket(app, ticketId2, 1234, courseId)
    create_ticket(app, ticketId3, 1234, courseId2)

    rv = client.get('/api/courses/{}/tickets'.format(courseId),
                    headers={'Authorization': auth})
    json_data = rv.get_json()
    print(json_data)
    assert len(json_data['json_data']) == 2
    assert rv.status == "200 OK"

    rv2 = client.get('/api/courses/{}/tickets'.format(courseId2),
                     headers={'Authorization': auth})
    json_data2 = rv2.get_json()
    print(json_data2)
    assert len(json_data2['json_data']) == 1
    assert rv2.status == "200 OK"