People: Add unit tests #22

This commit is contained in:
theresa 2021-09-20 14:05:44 +02:00
parent e8443cd715
commit 895d41cd61
3 changed files with 306 additions and 1 deletions

View file

@ -1008,7 +1008,7 @@ var PhotoFixtures = PhotoMap{
OriginalName: "",
PhotoFavorite: false,
PhotoPrivate: false,
PhotoScan: false,
PhotoScan: true,
PhotoPanorama: false,
TimeZone: "",
Place: &UnknownPlace,

View file

@ -341,4 +341,77 @@ func TestGeo(t *testing.T) {
assert.GreaterOrEqual(t, len(photos), 2)
})
t.Run("query: videos", func(t *testing.T) {
var frm form.PhotoSearchGeo
frm.Query = "videos"
photos, err := PhotosGeo(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, GeoResult{}, r)
assert.NotEmpty(t, r.ID)
assert.Equal(t, "video", r.PhotoType)
}
})
t.Run("query: faces", func(t *testing.T) {
var frm form.PhotoSearchGeo
frm.Query = "faces"
photos, err := PhotosGeo(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, GeoResult{}, r)
assert.NotEmpty(t, r.ID)
}
})
t.Run("query: people", func(t *testing.T) {
var frm form.PhotoSearchGeo
frm.Query = "people"
photos, err := PhotosGeo(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, GeoResult{}, r)
assert.NotEmpty(t, r.ID)
}
})
t.Run("query: favorites", func(t *testing.T) {
var frm form.PhotoSearchGeo
frm.Query = "favorites"
photos, err := PhotosGeo(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, GeoResult{}, r)
assert.NotEmpty(t, r.ID)
assert.True(t, r.PhotoFavorite)
}
})
}

View file

@ -864,6 +864,238 @@ func TestPhotos(t *testing.T) {
assert.GreaterOrEqual(t, len(photos), 1)
})
t.Run("Subject", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "John"
frm.Subject = ""
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.NotEmpty(t, r.CameraID)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: videos", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "videos"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.Equal(t, "video", r.PhotoType)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: faces", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "faces"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.LessOrEqual(t, 1, r.PhotoFaces)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: people", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "people"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.LessOrEqual(t, 1, r.PhotoFaces)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: favorites", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "favorites"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.True(t, r.PhotoFavorite)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: stacks", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "stacks"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: panoramas", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "panoramas"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.Equal(t, true, r.PhotoPanorama)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: scans", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "scans"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.Equal(t, true, r.PhotoScan)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("query: monochrome", func(t *testing.T) {
var frm form.PhotoSearch
frm.Query = "monochrome"
frm.Count = 10
frm.Offset = 0
photos, _, err := Photos(frm)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
for _, r := range photos {
assert.IsType(t, Photo{}, r)
assert.NotEmpty(t, r.ID)
assert.NotEmpty(t, r.LensID)
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
assert.Equal(t, fix.PhotoName, r.PhotoName)
}
}
})
t.Run("filename", func(t *testing.T) {
var f form.PhotoSearch
f.Filename = "1990/04/Quality1FavoriteTrue.jpg"