Exemple #1
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
Exemple #2
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'
Exemple #3
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'
Exemple #4
0
def test_get_courses(app, client):
    """
    Test database contains courses so at leas one should be returned.
    """
    usr = create_user(app, 12345)
    c = create_course(app, uuid.uuid4())
    link_ta_to_course(usr, c)
    auth = login(client, usr.id)
    rv = client.get('/api/courses', headers={'Authorization': auth})
    json_data = rv.get_json()
    assert rv.status == '200 OK'
    assert len(json_data['json_data']) > 0
Exemple #5
0
def test_get_course_tas(app, client):
    user = create_user(app, 1234)
    user2 = create_user(app, 4321)

    courseId = uuid.uuid4()
    course = create_course(app, courseId)
    link_ta_to_course(user, course)
    link_ta_to_course(user2, course)

    auth = login(client, 1234)

    rv = client.get('/api/courses/{}/tas'.format(courseId),
                    headers={'Authorization': auth})
    json_data = rv.get_json()
    print(json_data)
    assert rv.status == '200 OK'
    assert len(json_data['json_data']) == 2
Exemple #6
0
def test_get_all_courses(app, client):
    usr = create_user(app, 1234)

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

    c = create_course(app, courseId)
    create_course(app, courseId2)

    link_ta_to_course(usr, c)

    auth = login(client, 1234)

    rv = client.get('/api/courses',
                    headers={'Authorization': auth})
    json_data = rv.get_json()
    print(json_data)
    assert len(json_data['json_data']) >= 2
    assert rv.status == '200 OK'
Exemple #7
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"
Exemple #8
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
Exemple #9
0
def test_insert_ticket(app, client):
    """
    Insert a new ticket.
    """
    usr = create_user(app, 11188936)
    c = create_course(app, uuid.uuid4())
    link_student_to_course(usr, c)
    link_ta_to_course(usr, c)
    auth = login(client, 11188936)
    rv = client.get('/api/courses', headers={'Authorization': auth})
    cid = rv.get_json()['json_data'][0]['id']
    print("course: {}".format(cid))

    rv = client.post('/api/ticket/submit',
                     json={
                         'subject': 'test ticket',
                         'message': 'Test bericht',
                         'courseid': cid,
                         'labelid': '',
                         'files': ''
                     },
                     headers={'Authorization': auth})
    print(rv.data)
    assert rv.status == '201 CREATED'