From 223bc415118658477cec998f4b23353a3f3da6c5 Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Mon, 8 May 2017 12:10:33 +1000 Subject: [PATCH] video media upload/download test started, with success, (but need to decoe video json automatically in following works. --- mediaId.go | 12 ++++++++++++ upload_test.go | 22 ++++++++++++++++++++-- wechat_hitxy_access_token | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/mediaId.go b/mediaId.go index 8065cb3..6c6f2ff 100644 --- a/mediaId.go +++ b/mediaId.go @@ -23,6 +23,18 @@ func uploadImage(filename string) (mediaid string) { return } +func uploadVideo(filename string) (mediaid string) { + url, _ := getPostVideoURL() + + jstr, _ := postFileForm(filename, url, "media") + //{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789} + var m = MediaID{} + json.Unmarshal([]byte(jstr), &m) + mediaid = m.MediaID + return + +} + func checkImageSanity() bool { //check file size should < 2M fmt.Println(" should check image file size") diff --git a/upload_test.go b/upload_test.go index 549a705..0d27427 100644 --- a/upload_test.go +++ b/upload_test.go @@ -16,8 +16,6 @@ func TestUploadImage(t *testing.T) { fmt.Printf("get MediaID: %s \n", mediaID) //200 OK //{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549} - //mediaID = "3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2" - //mediaID = "L2Cyf6F5GvVXpubv75Pnf51f-Z7Ah5fOROqt1qsZTLmrebtOmeQy9Co2xw7JI6ck" assert.NotEqual(t, mediaID, "", "MediaID should not be Empty") //download the media back using the media id @@ -30,3 +28,23 @@ func TestUploadImage(t *testing.T) { AssertEqual(t, err, nil, "file should be equal ") AssertEqual(t, equal, true, "file should be equal ") } + +func TestUploadVideo(t *testing.T) { + SetupConfig() + src := "media_for_test/video.mp4" + mediaID := uploadVideo(src) + fmt.Printf("get MediaID: %s \n", mediaID) + //200 OK + //{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549} + assert.NotEqual(t, mediaID, "", "MediaID should not be Empty") + + //download the media back using the media id + filename, e := saveMedia2File(mediaID) // this isi a json with video link, we should download it and compare it. + log.Println("saved :" + filename) + AssertEqual(t, e, nil, "mediaID should be saved without any error") + //make sure two files are the same + cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode + equal, err := cmp.CompareFile(src, filename) + AssertEqual(t, err, nil, "file should be equal ") + AssertEqual(t, equal, true, "file should be equal ") +} diff --git a/wechat_hitxy_access_token b/wechat_hitxy_access_token index ea2e0c5..a83beea 100644 --- a/wechat_hitxy_access_token +++ b/wechat_hitxy_access_token @@ -1 +1 @@ -{"access_token":"VkqKPaCmYeSLh5p4-0AA7pew_ncB7YY-u5P4S-hc2T8V1KQiRoSsXwjvh4QVb4_eZqEaG_gdrL0e-o9Lz3ajV3HzqftUdzMhi_K7gr0ueguf4MQLFGfahofD7VFoSf98LXVbAHABNL","expires_in":7200,"created_at":"2017-05-07T20:32:46.746644722+10:00"} \ No newline at end of file +{"access_token":"p0-QwbIjK_jEqc-MvDTODjZgQDrrA0hUkcF2zk8y38_9P7xPodtiKx9dePoTs92bGrrthcUp-dj3izRXMt-Hfd0nFa1CW7nq0LzNLx7g1BCM2GyRxyt2q03G0CgOM3GpKIPiAHAXVC","expires_in":7200,"created_at":"2017-05-08T12:06:22.041624283+10:00"} \ No newline at end of file