Example #1
0
func ParseMark(markStr string) (markPtr *float32, err error) {
	if markStr != "" {
		var mark float64
		if mark, err = strconv.ParseFloat(strings.TrimSuffix(markStr, "分"), 32); err == nil {
			markPtr = util.NewFloat32(float32(mark))
		}
	}
	return
}
func TestAssignments(t *testing.T) {
	actual, status, err := ada.Assignments("127743")
	if err != nil {
		t.Fatalf("Failed to get assignments: %s", err)
	}

	util.ExpectStatus(t, status, http.StatusOK)

	// Check fetched data.
	expected := []*model.Assignment{
		{
			Id:       "663857",
			CourseId: "127743",
			BeginAt:  "2015-11-02",
			DueAt:    "2015-11-05T23:59:59+0800",
			Title:    "第六次作业",
			Body:     "第六次作业有部分内容需要Matlab仿真,所以如果有同学想提交电子版作业,请把非仿真的部分也拍照一并提交上来,这样就可以不必提交纸版作业了。\n    如果有同学要提交纸板作业,请把仿真内容打印出来,在课堂上交给老师!",
			Submission: &model.Submission{
				AssignmentId: "663857",
				Late:         false,
				Body:         "",
				Attachment: &model.Attachment{
					Filename:    "2013011187_663857_873609575_p4.pdf",
					Size:        2820876,
					DownloadURL: "https://learn.tsinghua.edu.cn/uploadFile/downloadFile.jsp?module_id=322\u0026course_id=127743\u0026filePath=Ui6dWfN3E23iy92Lm3GqLolVIj%2Bu5tfsytg7jRwlhOqxaULAEWF80pMjNsAbeGoNLbxf932lsPZSeaPFGySxlzqYaxPQuvWF9JTL%2B1WuOg4%3D",
				},
				MarkedAt: "2015-11-06",
				Mark:     util.NewFloat32(9.5),
				Comment:  "第二题分析和结论正确,公式有问题。",
			},
		},
		{
			Id:       "667021",
			CourseId: "127743",
			BeginAt:  "2015-11-15",
			DueAt:    "2015-11-30T23:59:59+0800",
			Title:    "大作业",
			Body:     "作业说明件附件,参考论文和数据请从“课程文件”中下载。",
			Attachment: &model.Attachment{
				Filename:    "625602385_2_2015年《数字信号处理》课程大作业.pdf",
				Size:        112055,
				DownloadURL: "https://learn.tsinghua.edu.cn/uploadFile/downloadFile.jsp?module_id=322\u0026course_id=127743\u0026filePath=7D5eM/3uxuWgUscnZFe5xYFRwCtzmT3Nd4b8XfYdVt9QXP6jW0X3Mw6gr2ogb0t8bD67/q7AeDDvr3x32279mpdW6Tj5nS6ysO1fFyPcUzk%3D",
			},
			Submission: &model.Submission{
				AssignmentId: "667021",
				Late:         false,
				Body:         "",
				Attachment: &model.Attachment{
					Filename:    "2013011187_667021_531504538_report.pdf",
					Size:        98640,
					DownloadURL: "https://learn.tsinghua.edu.cn/uploadFile/downloadFile.jsp?module_id=322\u0026course_id=127743\u0026filePath=Ui6dWfN3E23iy92Lm3GqLolVIj%2Bu5tfsVetxSI%2BmeI5zL/GWM0GkxzPppRm00efUNVY7MLZOt3A1jm56tM3YdeAlZMTa30DiABpxaPmB1YI%3D",
				},
			},
		},
		{
			Id:       "669225",
			CourseId: "127743",
			BeginAt:  "2015-11-24",
			DueAt:    "2015-11-26T23:59:59+0800",
			Title:    "第九次作业",
			Body:     "",
		},
		{
			Id:       "670485",
			CourseId: "127743",
			BeginAt:  "2015-11-30",
			DueAt:    "2015-12-04T23:59:59+0800",
			Title:    "第十次作业",
			Body:     "请未交作业的同学尽快提交作业!",
		},
		{
			Id:       "672559",
			CourseId: "127743",
			BeginAt:  "2015-12-09",
			DueAt:    "2015-12-11T23:59:59+0800",
			Title:    "第十一次作业",
			Body:     "",
		},
		{
			Id:       "674369",
			CourseId: "127743",
			BeginAt:  "2015-12-15",
			DueAt:    "2015-12-18T23:59:59+0800",
			Title:    "第十二次作业",
			Body:     "",
		},
		{
			Id:       "675999",
			CourseId: "127743",
			BeginAt:  "2015-12-22",
			DueAt:    "2015-12-25T23:59:59+0800",
			Title:    "第十三次作业",
			Body:     "",
		},
		{
			Id:       "677925",
			CourseId: "127743",
			BeginAt:  "2015-12-30",
			DueAt:    "2016-01-01T23:59:59+0800",
			Title:    "第十四次作业",
			Body:     "",
			Submission: &model.Submission{
				AssignmentId: "677925",
				Late:         false,
				Body:         "助教你好,这是最后的三次作业(对于课件12,13,14,15),一起交上来了!",
				Attachment: &model.Attachment{
					Filename:    "2013011187_677925_351002502_课件12-15对应的作业.zip",
					Size:        13601942,
					DownloadURL: "https://learn.tsinghua.edu.cn/uploadFile/downloadFile.jsp?module_id=322\u0026course_id=127743\u0026filePath=Ui6dWfN3E23iy92Lm3GqLolVIj%2Bu5tfsAqZGEzdQ71%2BH77AyehAScSLl2e2n5PeFBbCCeknxk/vScQfKcoZU4o%2B/fgVxuHWOFnv5a2X8eUU%3D",
				},
				MarkedAt: "2016-01-03",
				Mark:     util.NewFloat32(9.5),
				Comment:  "前面三次各8分",
			},
		},
	}

	util.ExpectDeepEqual(t, actual, expected)
}
func TestAssignments(t *testing.T) {
	actual, status, err := ada.Assignments("2014-2015-1-20750021-97")
	if err != nil {
		t.Fatalf("Failed to get homeworks: %s", err)
	}

	util.ExpectStatus(t, status, http.StatusOK)

	// Check fetched data.
	expected := []*model.Assignment{
		{
			Id:         "58093",
			CourseId:   "2014-2015-1-20750021-97",
			CreatedAt:  "",
			BeginAt:    "2014-09-23T10:02:50+0800",
			DueAt:      "2014-09-23T18:59:59+0800",
			Title:      "第一节课预习作业:已经发了课程公告,为防止大家没看到",
			Body:       "<p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\">重要:预习作业每人都要做,但不用交,我会课堂上随机抽查预习效果。</p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\"><br/></p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\">本课第一讲将主要帮助大家正确认识文献信息源。请大家预习以下内容。</p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\"><br/></p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\">查清华大学图书馆是否有“凌晓峰.学术研究:你的成功之道.北京 : 清华大学出版社, 2012”一书。</p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\">如有,告知馆藏地、索书号和馆藏状态。</p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\">本馆是否该书的英文版本?如何使用该书电子版?</p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\"><br/></p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\">请大家使用图书馆馆藏目录查阅以上信息。课堂上我会随机点名抽查预习的效果哦。</p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\"><br/></p><p style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Tahoma, Helvetica, Arial, 微软雅黑, sans-serif; font-size: 12px; line-height: 22px; white-space: normal; background-color: rgb(255, 255, 255);\">晚上见!</p><p><br/></p>",
			Attachment: nil,
			Submission: nil,
		},
		{
			Id:         "71056",
			CourseId:   "2014-2015-1-20750021-97",
			CreatedAt:  "2014-10-14T21:18:04+0800",
			BeginAt:    "2014-10-14T00:00:00+0800",
			DueAt:      "2014-10-20T23:59:59+0800",
			Title:      "第一次作业:电子图书与检索式编写",
			Body:       "<p>请于10月20日前提交作业,电子版即可,可将两个题目做在一个ppt或word中,推荐使用ppt呈现。有不明白的请给我或助教发邮件。<br/></p>",
			Attachment: nil,
			Submission: &model.Submission{
				Owner:        &model.User{Id: "2013011187"},
				AssignmentId: "71056",
				CreatedAt:    "2014-10-20T23:50:27+0800",
				Late:         false,
				Body:         "",
				Attachment: &model.Attachment{
					Filename:    "作业1.pptx",
					Size:        315198,
					DownloadURL: "http://learn.cic.tsinghua.edu.cn/b/resource/downloadFileStream/2013011187_2014-2015-1-20750021-97_ZY_1413820224",
				},
				MarkedBy:          &model.User{Name: "汤娇"},
				MarkedAt:          "2014-10-23T23:12:39+0800",
				Mark:              util.NewFloat32(11),
				Comment:           "<p>作业一,缺少分享一部分,此次不扣分,请再试一下如何将下载的图书拷贝给别人使用,另外关于超星电子图书阅读器的注册和下载过程的展示过于简略,;作业二,中文检索式连接符的使用正确,但是检索词的选择过于生僻和口语化,导致你的检索结果没有,英文检索式错误,请注意括号需要成对出现和检索词的选择.</p>",
				CommentAttachment: nil,
			},
		},
		{
			Id:        "76121",
			CourseId:  "2014-2015-1-20750021-97",
			CreatedAt: "2014-10-22T17:19:10+0800",
			BeginAt:   "2014-10-22T00:00:00+0800",
			DueAt:     "2014-11-01T23:59:59+0800",
			Title:     "第二次作业——SCI",
			Body:      "<p>课件我传不上去,只要放在印象笔记中与大家共享,请大家通过这个链接<a href=\"http://app.yinxiang.com/l/AAmpP7Z7r6lKnqrhVrtaVajvcJNd__J4xEA/\">http://app.yinxiang.com/l/AAmpP7Z7r6lKnqrhVrtaVajvcJNd__J4xEA/</a>&nbsp;来下载,以前和以后的课件我多会放在这里。请大家按时完成作业。</p>",
			Attachment: &model.Attachment{
				Filename:    "文献检索与利用-第二次作业——SCI.docx",
				Size:        15832,
				DownloadURL: "http://learn.cic.tsinghua.edu.cn/b/resource/downloadFileStream/2004980851_2014-2015-1-20750021-97_ZY_1413969147",
			},
			Submission: &model.Submission{
				Owner:        &model.User{Id: "2013011187"},
				AssignmentId: "76121",
				CreatedAt:    "2014-11-01T23:58:44+0800",
				Late:         false,
				Body:         "",
				Attachment: &model.Attachment{
					Filename:    "文献检索与利用-第二次作业——SCI.docx",
					Size:        250204,
					DownloadURL: "http://learn.cic.tsinghua.edu.cn/b/resource/downloadFileStream/2013011187_2014-2015-1-20750021-97_ZY_1414857519",
				},
				MarkedBy:          &model.User{Name: "汤娇"},
				MarkedAt:          "2014-11-11T18:26:26+0800",
				Mark:              util.NewFloat32(8),
				Comment:           "<p><span style=\"font-size:14px;font-family:宋体\">李思涵,你好:</span></p><p><span style=\"font-size:14px;font-family:宋体\"><br/></span></p><p><span style=\"font-size:14px;font-family:宋体\">&nbsp; &nbsp;第二次作业已阅,完成得不是很理想,你可以通过优化一下你的检索式,来获得最适合你的检索结果,可以适当放开你的检索条件;否则你第三题你如何完成这部分的作业;有问题的话,请联系王老师和我.</span></p><p><span style=\"font-size:14px;font-family:宋体\"><br/></span></p><p><span style=\"font-size:14px;font-family:宋体\">&nbsp; 继续努力,将后续的作业做好!</span></p><p><span style=\"font-size:14px;font-family:宋体\"><br/></span></p><p><span style=\"font-size:14px;font-family:宋体\">汤娇</span></p>",
				CommentAttachment: nil,
			},
		},
		{
			Id:        "88053",
			CourseId:  "2014-2015-1-20750021-97",
			CreatedAt: "2014-10-30T14:56:19+0800",
			BeginAt:   "2014-10-30T00:00:00+0800",
			DueAt:     "2014-11-14T23:59:59+0800",
			Title:     "EI",
			Body:      "",
			Attachment: &model.Attachment{
				Filename:    "EI作业.doc",
				Size:        32256,
				DownloadURL: "http://learn.cic.tsinghua.edu.cn/b/resource/downloadFileStream/2004980851_2014-2015-1-20750021-97_ZY_1414652158",
			},
			Submission: &model.Submission{
				Owner:        &model.User{Id: "2013011187"},
				AssignmentId: "88053",
				CreatedAt:    "2014-11-14T11:17:18+0800",
				Late:         false,
				Body:         "",
				Attachment: &model.Attachment{
					Filename:    "EI作业.doc",
					Size:        36352,
					DownloadURL: "http://learn.cic.tsinghua.edu.cn/b/resource/downloadFileStream/2013011187_2014-2015-1-20750021-97_ZY_1415935032",
				},
				MarkedBy:          &model.User{Name: "汤娇"},
				MarkedAt:          "2014-11-19T21:11:44+0800",
				Mark:              util.NewFloat32(14),
				Comment:           "<p style=\"TEXT-ALIGN: left; MARGIN: 0px 0px 5px\"><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">李思涵,你好:</span></p><p style=\"TEXT-ALIGN: left; MARGIN: 5px 0px\"><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">&nbsp;&nbsp;&nbsp;&nbsp; </span></p><p style=\"TEXT-ALIGN: left; MARGIN: 5px 0px\"><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">&nbsp;&nbsp;&nbsp;&nbsp; EI</span><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">作业已阅,总体完成得不错,过程和思路也比较清晰,但是按照你的expert search,应该只有4个检索结果。</span></p><p style=\"TEXT-ALIGN: left; MARGIN: 5px 0px\"><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">继续努力,将检索报告好好完成!</span><span style=\"FONT-FAMILY: &#39;Arial&#39;,&#39;sans-serif&#39;; FONT-SIZE: 16px\">&nbsp;</span></p><p style=\"TEXT-ALIGN: left; MARGIN: 5px 0px\"><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">&nbsp;</span><span style=\"FONT-FAMILY: 宋体; COLOR: black; FONT-SIZE: 16px\">汤娇</span></p><p></p>",
				CommentAttachment: nil,
			},
		},
		{
			Id:         "92095",
			CourseId:   "2014-2015-1-20750021-97",
			CreatedAt:  "2014-11-15T15:27:16+0800",
			BeginAt:    "2014-11-15T00:00:00+0800",
			DueAt:      "2014-12-01T23:59:59+0800",
			Title:      "综合检索报告提交专用",
			Body:       "",
			Attachment: nil,
			Submission: &model.Submission{
				Owner:        &model.User{Id: "2013011187"},
				AssignmentId: "92095",
				CreatedAt:    "2014-12-02T13:21:56+0800",
				Late:         true,
				Body:         "",
				Attachment: &model.Attachment{
					Filename:    "final.pdf",
					Size:        223372,
					DownloadURL: "http://learn.cic.tsinghua.edu.cn/b/resource/downloadFileStream/2013011187_2014-2015-1-20750021-97_ZY_1417497712",
				},
				MarkedBy:          &model.User{Name: "王媛"},
				MarkedAt:          "2015-02-01T22:16:25+0800",
				Mark:              util.NewFloat32(38),
				Comment:           "",
				CommentAttachment: nil,
			},
		},
	}

	util.ExpectDeepEqual(t, actual, expected)
}