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())
def test_get_ticket(app, client): userId = 11188936 usr = create_user(app, userId) auth = login(client, userId) c = create_course(app, uuid.uuid4(), tas=[usr], students=[usr], supervisors=[usr]) rv = client.get('/api/courses', headers={'Authorization': auth}) cid = c.id rv = client.post('/api/ticket/submit', json={ 'subject': 'test ticket', 'message': 'Test bericht', 'courseid': cid, 'labelid': '' }, headers={'Authorization': auth}) rv = client.get('/api/courses', headers={'Authorization': auth}) cid = c.id tickets = client.get('/api/courses/{}/tickets'.format(cid), headers={'Authorization': auth}) assert len(tickets.get_json()['json_data']) == 1 ticketid = tickets.get_json()['json_data'][0]['id'] assert ticketid is not None
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
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'
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'
def test_insert_ticket(app, client): """ Insert a new ticket. """ userId = 12345 usr = create_user(app, userId) auth = login(client, userId) c = create_course(app, uuid.uuid4(), tas=[usr]) rv = client.get('/api/courses', headers={'Authorization': auth}) cid = rv.get_json()['json_data'][0]['id'] link_student_to_course(usr, c) 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'
def test_create_new_course(app, client): """ Test the api call to create a new course """ usr = create_user(app, 1234) c = create_course(app, uuid.uuid4(), supervisors=[usr]) auth = login(client, 1234) mail = "*****@*****.**" title = "test course title" description = "test course description" rv = client.post('/api/courses', json={ "mail": mail, "title": title, "description": description }, headers={ 'Authorization': auth }) assert rv.status == "200 OK" rv2 = client.get('/api/courses', headers={'Authorization': auth}) json_data = rv2.get_json() print(json_data) assert len(json_data['json_data']) > 0 found = False for course in json_data['json_data']: if(course['course_email'] == mail and course['title'] == title and course['description'] == description): found = True assert found assert rv2.status == '200 OK'
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())
def test_incorrect_course_post(app, client): """ Not sending any json should return 400. """ usr = create_user(app, 12345) c = create_course(app, uuid.uuid4(), supervisors=[usr]) # link_supervisor_to_course(usr, c) auth = login(client, usr.id) rv = client.post('/api/courses', headers={'Authorization': auth}) assert rv.status == '400 BAD REQUEST'
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'
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"
def test_get_student_courses(app, client): user = create_user(app, 1234) auth = login(client, 1234) courseId = uuid.uuid4() course = create_course(app, courseId, [], [user]) rv = client.get('/api/user/student_courses', headers={'Authorization': auth}) json_data = rv.get_json() print(json_data) assert rv.status == "200 OK" assert len(json_data['json_data']) > 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)
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
def test_get_tickets(app, client): """ Database should be empty so no tickets should be returned. """ usr = create_user(app, 12345) auth = login(client, usr.id) c = create_course(app, courseId=uuid.uuid4(), tas=[usr]) tickets = client.get('/api/courses/{}/tickets'.format(c.id), headers={'Authorization': auth}) assert tickets.status == '200 OK' print(tickets.get_json()) assert len(tickets.get_json()['json_data']) == 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'])
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
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"
def test_get_single_course(app, client): """ Test the api call to get a single course """ usr = create_user(app, 1234) courseId = uuid.uuid4() c = create_course(app, courseId) auth = login(client, usr.id) rv = client.get('/api/courses/single/{}'.format(courseId), headers={'Authorization': auth}) json_data = rv.get_json() print(json_data) assert len(json_data['json_data']) > 0 assert rv.status == '200 OK'
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
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"