From c78e3d199e7f1263e5804b6b7ed7853db998bc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kris=20N=C3=B3va?= Date: Thu, 11 Feb 2021 17:25:03 -0800 Subject: [PATCH] Working photo and album endpoints with super amazing unit and itnegrations tests - please run my fucking code i dare you MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kris NĂ³va --- api/v1/album.go | 2 +- .../storage/albums/album/aqoe4m9204aigugh.yml | 4 +- .../storage/albums/album/aqoe68w1gxzard2c.yml | 9 ++ .../storage/albums/album/aqoe68w1lzpyk5zg.yml | 9 ++ .../storage/albums/album/aqoe68w245je8zni.yml | 9 ++ .../storage/albums/album/aqoe68wxhb91hvje.yml | 10 ++ .../storage/albums/album/aqoe6k91z2qayg4w.yml | 9 ++ .../storage/albums/album/aqoe6k922s2v6yp1.yml | 9 ++ .../storage/albums/album/aqoe6k93d879bjgg.yml | 10 ++ .../storage/albums/album/aqoe6k9k0kkmx79g.yml | 9 ++ .../photoprism/storage/cache/sessions.json | 20 +++ sample-app/photoprism/storage/index.db | Bin 442368 -> 442368 bytes .../2021/02/20210204_031706_5B740007.yml | 6 +- test/album_test.go | 153 ++++++++++-------- 14 files changed, 184 insertions(+), 75 deletions(-) create mode 100755 sample-app/photoprism/storage/albums/album/aqoe68w1gxzard2c.yml create mode 100755 sample-app/photoprism/storage/albums/album/aqoe68w1lzpyk5zg.yml create mode 100755 sample-app/photoprism/storage/albums/album/aqoe68w245je8zni.yml create mode 100755 sample-app/photoprism/storage/albums/album/aqoe68wxhb91hvje.yml create mode 100755 sample-app/photoprism/storage/albums/album/aqoe6k91z2qayg4w.yml create mode 100755 sample-app/photoprism/storage/albums/album/aqoe6k922s2v6yp1.yml create mode 100755 sample-app/photoprism/storage/albums/album/aqoe6k93d879bjgg.yml create mode 100755 sample-app/photoprism/storage/albums/album/aqoe6k9k0kkmx79g.yml diff --git a/api/v1/album.go b/api/v1/album.go index 7dd0eb0..2b3d6ad 100644 --- a/api/v1/album.go +++ b/api/v1/album.go @@ -146,6 +146,6 @@ func (v1 *V1Client) DeletePhotosFromAlbum(albumUUID string, photoIDs []string) e func (v1 *V1Client) GetAlbumDownload(uuid string) ([]byte, error) { // NOTE: Even though this method is singular GetAlbum // if will call the "albums" plural endpoint. - resp := v1.GET("/api/v1/albums/%s", uuid) + resp := v1.GET("/api/v1/albums/%s?t=%s", uuid, v1.downloadToken) return resp.Body, resp.Error } diff --git a/sample-app/photoprism/storage/albums/album/aqoe4m9204aigugh.yml b/sample-app/photoprism/storage/albums/album/aqoe4m9204aigugh.yml index bffede1..0ca2805 100755 --- a/sample-app/photoprism/storage/albums/album/aqoe4m9204aigugh.yml +++ b/sample-app/photoprism/storage/albums/album/aqoe4m9204aigugh.yml @@ -6,6 +6,4 @@ Order: oldest Country: zz CreatedAt: 2021-02-12T00:42:10Z UpdatedAt: 2021-02-12T00:42:10Z -Photos: -- UID: pqnzigq351j2fqgn - CreatedAt: 2021-02-12T00:42:09.791065836Z +DeletedAt: 2021-02-12T01:19:49.19521169Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe68w1gxzard2c.yml b/sample-app/photoprism/storage/albums/album/aqoe68w1gxzard2c.yml new file mode 100755 index 0000000..d2b8cca --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe68w1gxzard2c.yml @@ -0,0 +1,9 @@ +UID: aqoe68w1gxzard2c +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:17:21Z +UpdatedAt: 2021-02-12T01:17:21Z +DeletedAt: 2021-02-12T01:17:20.582731838Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe68w1lzpyk5zg.yml b/sample-app/photoprism/storage/albums/album/aqoe68w1lzpyk5zg.yml new file mode 100755 index 0000000..b2f5ef0 --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe68w1lzpyk5zg.yml @@ -0,0 +1,9 @@ +UID: aqoe68w1lzpyk5zg +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:17:21Z +UpdatedAt: 2021-02-12T01:17:21Z +DeletedAt: 2021-02-12T01:17:20.549276966Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe68w245je8zni.yml b/sample-app/photoprism/storage/albums/album/aqoe68w245je8zni.yml new file mode 100755 index 0000000..928842c --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe68w245je8zni.yml @@ -0,0 +1,9 @@ +UID: aqoe68w245je8zni +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:17:21Z +UpdatedAt: 2021-02-12T01:17:21Z +DeletedAt: 2021-02-12T01:17:20.626364883Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe68wxhb91hvje.yml b/sample-app/photoprism/storage/albums/album/aqoe68wxhb91hvje.yml new file mode 100755 index 0000000..87bbfac --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe68wxhb91hvje.yml @@ -0,0 +1,10 @@ +UID: aqoe68wxhb91hvje +Slug: testalbum +Type: album +Title: TestAlbum +Description: An updated album description +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:17:20Z +UpdatedAt: 2021-02-12T01:17:20.480072684Z +DeletedAt: 2021-02-12T01:17:20.493622671Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe6k91z2qayg4w.yml b/sample-app/photoprism/storage/albums/album/aqoe6k91z2qayg4w.yml new file mode 100755 index 0000000..0eceb8d --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe6k91z2qayg4w.yml @@ -0,0 +1,9 @@ +UID: aqoe6k91z2qayg4w +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:24:10Z +UpdatedAt: 2021-02-12T01:24:10Z +DeletedAt: 2021-02-12T01:24:09.719043974Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe6k922s2v6yp1.yml b/sample-app/photoprism/storage/albums/album/aqoe6k922s2v6yp1.yml new file mode 100755 index 0000000..caecb9e --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe6k922s2v6yp1.yml @@ -0,0 +1,9 @@ +UID: aqoe6k922s2v6yp1 +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:24:10Z +UpdatedAt: 2021-02-12T01:24:10Z +DeletedAt: 2021-02-12T01:24:09.794949796Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe6k93d879bjgg.yml b/sample-app/photoprism/storage/albums/album/aqoe6k93d879bjgg.yml new file mode 100755 index 0000000..d3f8c16 --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe6k93d879bjgg.yml @@ -0,0 +1,10 @@ +UID: aqoe6k93d879bjgg +Slug: testalbum +Type: album +Title: TestAlbum +Description: An updated album description +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:24:10Z +UpdatedAt: 2021-02-12T01:24:09.652930019Z +DeletedAt: 2021-02-12T01:24:09.664933038Z diff --git a/sample-app/photoprism/storage/albums/album/aqoe6k9k0kkmx79g.yml b/sample-app/photoprism/storage/albums/album/aqoe6k9k0kkmx79g.yml new file mode 100755 index 0000000..0d545ac --- /dev/null +++ b/sample-app/photoprism/storage/albums/album/aqoe6k9k0kkmx79g.yml @@ -0,0 +1,9 @@ +UID: aqoe6k9k0kkmx79g +Slug: testalbum +Type: album +Title: TestAlbum +Order: oldest +Country: zz +CreatedAt: 2021-02-12T01:24:10Z +UpdatedAt: 2021-02-12T01:24:10Z +DeletedAt: 2021-02-12T01:24:09.744169818Z diff --git a/sample-app/photoprism/storage/cache/sessions.json b/sample-app/photoprism/storage/cache/sessions.json index 573218c..6bf2e4c 100644 --- a/sample-app/photoprism/storage/cache/sessions.json +++ b/sample-app/photoprism/storage/cache/sessions.json @@ -314,6 +314,11 @@ "tokens": null, "expiration": 1613686778812288997 }, + "5e45fef754afe86cd06fdece3654e1d096844e9bb06e656a": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613697849631150727 + }, "5fccb8ed1ac9f5ca4152b071128078b3da8810e88c1d9728": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -539,6 +544,11 @@ "tokens": null, "expiration": 1613513937752119685 }, + "a195acf32c21a87fc81c92363ed95faaa01abfc91b481179": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613697851138920617 + }, "a3139951989d33f77e643cf68bdd8e2c7cbb88f344200903": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -714,6 +724,11 @@ "tokens": null, "expiration": 1613514516062495823 }, + "dd302423a35c910b5cd65027f2fba9edb7efbf0ee0f81157": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613697440458652837 + }, "e089dfbed493744e24c0cdf9be5f06c81979a17e166d098c": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -764,6 +779,11 @@ "tokens": null, "expiration": 1613512474632135880 }, + "eed103dd37ee5347149d459bfb393d682416adceb8da887e": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613697441816718340 + }, "f27ef3af1a5139eb23ab2d2cd5adb54dd63e147c74f12208": { "user": "uqnzie01i1nypnt9", "tokens": null, diff --git a/sample-app/photoprism/storage/index.db b/sample-app/photoprism/storage/index.db index 16f3e28e2837757a190cfc2437db4e9727e9b61d..4230813f47de1ac4421cf1105c993a4226efff6a 100644 GIT binary patch delta 2406 zcmb_cTWl0n7~bibo!!~lnb|_CB6Ml{fN0Zt&Y63qgi9k2u($3+BT}HHb=z)>-Et|c zn(i6{_`)R{9MPJfkd$zVXeDb?Zx2{ae4)`d4bc#d#$c$C5E3!Y?CfrLka|hXB!B+@ z)y(VkfVC(LkCd z>p9OAV-YvXjc`L;AGd?s%00#D{7o~-)BmaHL&X2zK-QD<+&EstKF+qWBHP3^vP;+i z>)~(mKbiSG>CZ*(c-QD&ceU3`q|@<|(os@kB_&!?A|)kUQbLoFJCjxZWiB18ck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43|6y))*V`h4MN85U>GK7e@po^VD)#*PV;ks z-CW55nQL?*i8zN(3P@T&^Xtao_9ig5H*FaekaK-7c>=?(qk>Rd+tnSt+1Ao6tNwPW zxw|DA?(U4Jz2xeZNN=>6$U1%V6lDlLnaGl^Ni=;PWz()_h$~H@6wzf#D<-6rkSHgV zln95VR5}caDB-r2>n*Lce*$IkhM#DvF4O79D1+XeKz6|(nxq)2VV0G{W#Hs+C4)cV z89an5&9u|-ICkxC4AG$wJmT(*97x?7f)5~v$4tHk4&cHAhD=xjtnv06%*h6L@-OGt zN{K@It3ejss%ML=?XjZbQ&gSEswV4Z;bnH|(g{l@`y@3W%K=r>y(L5^#9LE)(c5vV zSo0~0VHmohsua(%9si#|(+oAB>k0))lts_ILLNFb$9e`AXIXP`maF(GtuVO3{o1wb zs&mdbGsP;$q(ii~3r_^dH=zyWn<0x!4Jx7lO4=+|(mB#ie4T(R*s?@g$h_JsPNVk)y K$m~g?d+a|FfAzxv diff --git a/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml b/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml index 33e6423..3572ade 100755 --- a/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml +++ b/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml @@ -3,7 +3,7 @@ UID: pqnzigq351j2fqgn Type: image Title: A really great photo! TitleSrc: manual -Description: 'Sample App Description: 2021-02-11 17:16:03.257337568 -0800 PST m=+6.449998955' +Description: 'Sample App Description: 2021-02-11 17:24:09.899837223 -0800 PST m=+6.509602721' DescriptionSrc: manual OriginalName: IMG_3044 Year: -1 @@ -13,5 +13,5 @@ Details: Keywords: green, tambourine KeywordsSrc: manual CreatedAt: 2021-02-04T03:17:14.613092062Z -UpdatedAt: 2021-02-12T01:16:03.266957884Z -EditedAt: 2021-02-12T01:16:03Z +UpdatedAt: 2021-02-12T01:24:09.908530756Z +EditedAt: 2021-02-12T01:24:10Z diff --git a/test/album_test.go b/test/album_test.go index 3e8efee..808e9cd 100644 --- a/test/album_test.go +++ b/test/album_test.go @@ -179,74 +179,91 @@ func TestSadCloneAlbum(t *testing.T) { // TestAlbumAddDeletePhoto is a giant integration test // that will exercise many methods in the SDK -//func TestAlbumAddDeletePhoto(t *testing.T) { -// album := api.Album{ -// AlbumTitle: WellKnownAlbumTitle, -// } // -// newAlbum, err := Client.V1().CreateAlbum(album) -// if err != nil { -// t.Errorf("expected success creating album: %v", err) -// t.FailNow() -// } -// -// // Add Photos -// photos := []string{ -// WellKnownPhotoID, -// } -// err = Client.V1().AddPhotosToAlbum(newAlbum.AlbumUID, photos) -// if err != nil { -// t.Errorf("expected to add photos to album: %v", err) -// // Note: We do NOT FailNow() here because we want to clean up -// } -// -// // Get the photos by album -// updatedPhotos, err := Client.V1().GetPhotos(&api.PhotoOptions{ -// Count: 100, -// AlbumUID: newAlbum.AlbumUID, -// }) -// if err != nil { -// t.Errorf("expecting to list photos by album: %v", err) -// // Note: We do NOT FailNow() here because we want to clean up -// } -// -// var updatedPhotoIDs []string -// for _, photo := range updatedPhotos { -// updatedPhotoIDs = append(updatedPhotoIDs, photo.PhotoUID) -// } -// if len(updatedPhotos) != 1 { -// t.Errorf("expecting 1 well known photo in album, found: %d", len(updatedPhotos)) -// } -// -// err = Client.V1().DeletePhotosFromAlbum(newAlbum.AlbumUID, updatedPhotoIDs) -// if err != nil { -// t.Errorf("expected to delete newly created photos from album: %v", err) -// // Note: We do NOT FailNow() here because we want to clean up -// } -// -// // Get the photos by album -// updatedPhotos, err = Client.V1().GetPhotos(&api.PhotoOptions{ -// Count: 100, -// AlbumUID: newAlbum.AlbumUID, -// }) -// if err != nil { -// t.Errorf("expecting to list photos by album: %v", err) -// // Note: We do NOT FailNow() here because we want to clean up -// } -// -// if len(updatedPhotos) != 0 { -// t.Errorf("expected empty album, found %d photos", len(updatedPhotos)) -// // Note: We do NOT FailNow() here because we want to clean up -// } -// -// err = Client.V1().DeleteAlbums([]string{newAlbum.AlbumUID}) -// if err != nil { -// t.Errorf("expected delete album %s, album not deleted: %v", newAlbum.AlbumUID, err) -// t.FailNow() -// } -//} +// This is the most complete integration test in the suite +// and is the test that will also exercise adding and deleting +// photos from an album +func TestAlbumAddDeletePhoto(t *testing.T) { + album := api.Album{ + AlbumTitle: WellKnownAlbumTitle, + } -// AddPhotosToAlbum -// DeletePhotosFromAlbum + newAlbum, err := Client.V1().CreateAlbum(album) + if err != nil { + t.Errorf("expected success creating album: %v", err) + t.FailNow() + } -// GetAlbumDownload + // Add Photos + photos := []string{ + WellKnownPhotoID, + } + err = Client.V1().AddPhotosToAlbum(newAlbum.AlbumUID, photos) + if err != nil { + t.Errorf("expected to add photos to album: %v", err) + // Note: We do NOT FailNow() here because we want to clean up + } + + // Get the photos by album + updatedPhotos, err := Client.V1().GetPhotos(&api.PhotoOptions{ + Count: 100, + AlbumUID: newAlbum.AlbumUID, + }) + if err != nil { + t.Errorf("expecting to list photos by album: %v", err) + // Note: We do NOT FailNow() here because we want to clean up + } + + var updatedPhotoIDs []string + for _, photo := range updatedPhotos { + updatedPhotoIDs = append(updatedPhotoIDs, photo.PhotoUID) + } + if len(updatedPhotos) != 1 { + t.Errorf("expecting 1 well known photo in album, found: %d", len(updatedPhotos)) + } + + err = Client.V1().DeletePhotosFromAlbum(newAlbum.AlbumUID, updatedPhotoIDs) + if err != nil { + t.Errorf("expected to delete newly created photos from album: %v", err) + // Note: We do NOT FailNow() here because we want to clean up + } + + // Get the photos by album + updatedPhotos, err = Client.V1().GetPhotos(&api.PhotoOptions{ + Count: 100, + AlbumUID: newAlbum.AlbumUID, + }) + if err != nil { + t.Errorf("expecting to list photos by album: %v", err) + // Note: We do NOT FailNow() here because we want to clean up + } + + if len(updatedPhotos) != 0 { + t.Errorf("expected empty album, found %d photos", len(updatedPhotos)) + // Note: We do NOT FailNow() here because we want to clean up + } + + err = Client.V1().DeleteAlbums([]string{newAlbum.AlbumUID}) + if err != nil { + t.Errorf("expected delete album %s, album not deleted: %v", newAlbum.AlbumUID, err) + t.FailNow() + } +} + +func TestHappyGetAlbumDownload(t *testing.T) { + // GetAlbumDownload should return a .zip file + bytes, err := Client.V1().GetAlbumDownload(WellKnownAlbumID) + if err != nil { + t.Errorf("expecting album download: %v", err) + t.FailNow() + } + t.Logf("bytes of .zip file downloaded: %db", len(bytes)) +} + +func TestSadGetAlbumDownload(t *testing.T) { + _, err := Client.V1().GetPhotoDownload(UnknownAlbumID) + if err == nil { + t.Errorf("expected failure getting well known album: %v", err) + t.FailNow() + } +}