def test_delete_course(client): headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.delete('/v1/courses/1', headers=headers) assert response.status == '204 NO CONTENT', response.data assert not Course.query.filter_by(cid=1).first()
def test_get_answer(client): headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.get('/v1/answers/1', headers=headers) assert response.status[:3] == '200' assert json.loads(response.data)['content'] == 'test_answer_content'
def test_delete_answer(client): headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.delete('/v1/answers/1', headers=headers) assert response.status[:3] == '204' assert not Answer.query.filter_by(id=1).first()
def test_get_answers(client): headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.get('/v1/discussions/1/answer', headers=headers) assert response.status[:3] == '200', response.data res_json = json.loads(response.data) assert len(res_json) == 1 assert res_json[0]['content'] == 'test_topic_answer_content'
def test_answer_discussion(client): data = {"reply_id": 123, "content": "test_topic_answer_content"} headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.post('/v1/discussions/1/answer', data=json.dumps(data), headers=headers) assert response.status[:3] == '200' assert DiscussionAnswer.query.filter_by( id=1).first().content == 'test_topic_answer_content'
def test_update_answer(client): data = {"is_teacher": False, "content": "test_update_answer_content"} headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.put('/v1/answers/1', data=json.dumps(data), headers=headers) assert response.status[:3] == '200' assert Answer.query.filter_by( id=1).first().content == 'test_update_answer_content'
def test_get_schedule(client): headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } rsp = client.get('/v1/schedules/1') assert rsp.status == '200 OK', rsp.data rsp_json = json.loads(rsp.data) assert rsp_json['week'] == 11 assert rsp_json['topic'] == "test_schedule_topic" assert rsp_json['datetime'] == "2000-01-01" assert rsp_json['reference'] == "test_schedule_reference"
def test_get_course(client): headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.get('/v1/courses/1', headers=headers) res_json = json.loads(response.data) assert response.status == '200 OK', res_json assert res_json['intro'] == 'test_intro' assert res_json['name_en'] == 'test_name_en' assert res_json['name_zh'] == 'test_name_zh' assert res_json['pre_course'] == 'test_pre_course' assert res_json['semester'] == 'test_semester'
def create_schedule(client): data = { "week": 11, "topic": "test_schedule_topic", "datetime": "2000-01-01", "reference": "test_schedule_reference" } headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.post('/v1/courses/1/schedules', data=json.dumps(data), headers=headers) return response
def test_update_discussion(client): data = { "title": "test_update_topic_title", "content": "test_update_topic_content" } headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.put('/v1/discussions/1', data=json.dumps(data), headers=headers) assert response.status[:3] == '200' assert DiscussionTopic.query.filter_by( id=1).first().content == 'test_update_topic_content'
def test_create_announce(client): response = create_courses(client) assert response.status == '200 OK', response.data data = {"title": 'test_announce_title', "content": "test_announce_content"} headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.post('/v1/courses/1/announces', data=json.dumps(data), headers=headers) assert response.status == "200 OK", response.data assert Announce.query.filter_by( id=1).first().title == 'test_announce_title' assert Announce.query.filter_by( id=1).first().content == 'test_announce_content'
def create_courses(client): data = { "intro": "test_intro", "name_en": "test_name_en", "name_zh": "test_name_zh", "pre_course": "test_pre_course", "semester": "test_semester", "textbooks": "test_textbooks", "series": "test_series" } headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.post('/v1/courses', data=json.dumps(data), headers=headers) return response
def test_update_schedule(client): data = { "week": 12, "topic": "test_update_schedule_topic", "datetime": "2000-01-02", "reference": "test_update_schedule_reference" } headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.put('/v1/schedules/1', data=json.dumps(data), headers=headers) assert response.status == '200 OK' assert Schedule.query.filter_by(id=1).first().week == 12 assert Schedule.query.filter_by( id=1).first().topic == 'test_update_schedule_topic' assert Schedule.query.filter_by(id=1).first().datetime == '2000-01-02' assert Schedule.query.filter_by( id=1).first().reference == 'test_update_schedule_reference'
def test_update_course(client): data = { "intro": "test_update_intro", "name_en": "test_update_name_en", "name_zh": "test_update_name_zh", "pre_course": "test_update_pre_course", "semester": "test_update_semester", "textbooks": "test_update_textbooks", "series": "test_update_series" } headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.put('/v1/courses/1', data=json.dumps(data), headers=headers) assert response.status == '200 OK', response.data assert Course.query.filter_by( cid=1).first().name_en == 'test_update_name_en' assert Course.query.filter_by( cid=1).first().name_zh == 'test_update_name_zh'
def test_upload(client): response = create_courses(client) assert response.status[:3] == '200', response.data data = {} data["description"] = "test_file" data['file'] = (io.BytesIO(b"abcdef"), 'test.jpg') headers = {'Content-Type': 'multipart/form-data', 'Authorization': 'Bearer {0}'.format(get_test_token(client))} response = client.post('/v1/courses/1/resources', data=data, headers=headers, content_type='multipart/form-data') assert response.status[:3] == '200'
def create_questions(client): data = { "title": "test_question_title", "content": "test_question_content" } headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client))} response = client.post('/v1/courses/1/questions', data=json.dumps(data), headers=headers) return response
def test_get_resource(client): headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client))} response = client.get('/v1/recources/1', headers=headers) assert response.status[:3] == '200'