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_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 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 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_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 test_create_answer(client): response = create_courses(client) assert response.status[:3] == '200', response.data response = create_questions(client) assert response.status[:3] == '200', response.data data = {"is_teacher": False, "content": "test_answer_content"} headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.post('/v1/questions/1/answers', data=json.dumps(data), headers=headers) assert response.status[:3] == '200' assert Answer.query.filter_by( id=1).first().content == 'test_answer_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_create_topic(client): response = create_courses(client) assert response.status[:3] == '200', response.data response = create_questions(client) assert response.status[:3] == '200', response.data data = {"title": "test_topic_title", "content": "test_topic_content"} headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(get_test_token(client)) } response = client.post('/v1/questions/1/discussions', data=json.dumps(data), headers=headers) assert response.status[:3] == '200' assert DiscussionTopic.query.filter_by( id=1).first().title == 'test_topic_title' assert DiscussionTopic.query.filter_by( id=1).first().content == 'test_topic_content'