MCPcopy
hub / github.com/perkeep/perkeep / MakeTestData

Method MakeTestData

pkg/importer/flickr/testdata.go:47–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45}
46
47func (im imp) MakeTestData() http.RoundTripper {
48 const (
49 nPhotosets = 5 // Arbitrary number of sets.
50 perPage = 3 // number of photos per page (both when getting sets and when getting photos).
51 fakeUserId = "fakeUserId"
52 )
53 // Photoset N has N photos, so we've got 15 ( = 5 + 4 + 3 + 2 + 1) photos in total.
54 var nPhotos int
55 for i := 1; i <= nPhotosets; i++ {
56 nPhotos += i
57 }
58 nPhotosPages := nPhotos / perPage
59 if nPhotos%perPage != 0 {
60 nPhotosPages++
61 }
62
63 okHeader := `HTTP/1.1 200 OK
64Content-Type: application/json; charset=UTF-8
65
66`
67
68 // TODO(mpl): this scheme does not take into account that we could have the same photo
69 // in different albums. These two photos will end up with a different photoId.
70 buildPhotoIds := func(nsets, perPage int) []string {
71 var ids []string
72 for i := 1; i <= nsets; i++ {
73 photosetId := blob.RefFromString(fmt.Sprintf("Photoset %d", i)).DigestPrefix(10)
74 page := 1
75 // Photoset N has N photos.
76 indexOnPage := 1
77 for j := 1; j <= i; j++ {
78 photoId := blob.RefFromString(fmt.Sprintf("Photo %d on page %d of photoset %s", indexOnPage, page, photosetId)).DigestPrefix(10)
79 ids = append(ids, photoId)
80 indexOnPage++
81 if indexOnPage > perPage {
82 page++
83 indexOnPage = 1
84 }
85 }
86 }
87 return ids
88 }
89 photoIds := buildPhotoIds(nPhotosets, perPage)
90
91 responses := make(map[string]func() *http.Response)
92 // Initial photo sets list
93 photosetsURL := fmt.Sprintf("%s?format=json&method=%s&nojsoncallback=1&user_id=%s", apiURL, photosetsAPIPath, fakeUserId)
94 response := fmt.Sprintf("%s%s", okHeader, fakePhotosetsList(nPhotosets))
95 responses[photosetsURL] = httputil.StaticResponder(response)
96
97 // All the photoset calls. One call for each page of each photoset.
98 // Each page as perPage photos, or maybe less if end of the photoset.
99 {
100 pageStart := 0
101 albumEnd, pageEnd, albumNum, pages, page := 1, 1, 1, 1, 1
102 photosetId := blob.RefFromString(fmt.Sprintf("Photoset %d", albumNum)).DigestPrefix(10)
103 photosURL := fmt.Sprintf("%s?extras=original_format&format=json&method=%s&nojsoncallback=1&page=%d&photoset_id=%s&user_id=%s",
104 apiURL, photosetAPIPath, page, photosetId, fakeUserId)

Callers

nothing calls this directly

Calls 9

RefFromStringFunction · 0.92
StaticResponderFunction · 0.92
FileResponderFunction · 0.92
NewFakeTransportFunction · 0.92
fakePhotosetsListFunction · 0.85
fakePhotosetFunction · 0.85
fakePhotosPageFunction · 0.85
DigestPrefixMethod · 0.80
fakePictureFunction · 0.70

Tested by

no test coverage detected