Explorar el Código

video media upload/download test started, with success, (but need to decoe video json automatically in following works.

master
Patrick Peng Sun hace 8 años
padre
commit
223bc41511
Se han modificado 3 ficheros con 33 adiciones y 3 borrados
  1. +12
    -0
      mediaId.go
  2. +20
    -2
      upload_test.go
  3. +1
    -1
      wechat_hitxy_access_token

+ 12
- 0
mediaId.go Ver fichero

return 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 { func checkImageSanity() bool {
//check file size should < 2M //check file size should < 2M
fmt.Println(" should check image file size") fmt.Println(" should check image file size")

+ 20
- 2
upload_test.go Ver fichero

fmt.Printf("get MediaID: %s \n", mediaID) fmt.Printf("get MediaID: %s \n", mediaID)
//200 OK //200 OK
//{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549} //{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549}
//mediaID = "3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2"
//mediaID = "L2Cyf6F5GvVXpubv75Pnf51f-Z7Ah5fOROqt1qsZTLmrebtOmeQy9Co2xw7JI6ck"
assert.NotEqual(t, mediaID, "", "MediaID should not be Empty") assert.NotEqual(t, mediaID, "", "MediaID should not be Empty")


//download the media back using the media id //download the media back using the media id
AssertEqual(t, err, nil, "file should be equal ") AssertEqual(t, err, nil, "file should be equal ")
AssertEqual(t, equal, true, "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 ")
}

+ 1
- 1
wechat_hitxy_access_token Ver fichero

{"access_token":"VkqKPaCmYeSLh5p4-0AA7pew_ncB7YY-u5P4S-hc2T8V1KQiRoSsXwjvh4QVb4_eZqEaG_gdrL0e-o9Lz3ajV3HzqftUdzMhi_K7gr0ueguf4MQLFGfahofD7VFoSf98LXVbAHABNL","expires_in":7200,"created_at":"2017-05-07T20:32:46.746644722+10:00"}
{"access_token":"p0-QwbIjK_jEqc-MvDTODjZgQDrrA0hUkcF2zk8y38_9P7xPodtiKx9dePoTs92bGrrthcUp-dj3izRXMt-Hfd0nFa1CW7nq0LzNLx7g1BCM2GyRxyt2q03G0CgOM3GpKIPiAHAXVC","expires_in":7200,"created_at":"2017-05-08T12:06:22.041624283+10:00"}

Cargando…
Cancelar
Guardar