2020-05-08 15:46:16 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2020-05-18 22:18:58 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2020-05-11 17:01:19 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/classify"
|
2020-05-08 15:46:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSavePhotoForm(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-05-08 15:46:16 +02:00
|
|
|
f := form.Photo{
|
|
|
|
TakenAt: time.Date(2008, 1, 1, 2, 0, 0, 0, time.UTC),
|
|
|
|
TakenAtLocal: time.Date(2008, 1, 1, 2, 0, 0, 0, time.UTC),
|
|
|
|
TakenSrc: "manual",
|
|
|
|
TimeZone: "test",
|
|
|
|
PhotoTitle: "Pink beach",
|
2021-02-06 16:30:30 +01:00
|
|
|
TitleSrc: SrcManual,
|
2020-05-08 15:46:16 +02:00
|
|
|
PhotoFavorite: true,
|
|
|
|
PhotoPrivate: true,
|
2020-05-21 13:26:28 +02:00
|
|
|
PhotoType: "image",
|
2020-05-08 15:46:16 +02:00
|
|
|
PhotoLat: 7.9999,
|
|
|
|
PhotoLng: 8.8888,
|
|
|
|
PhotoAltitude: 2,
|
|
|
|
PhotoIso: 5,
|
|
|
|
PhotoFocalLength: 10,
|
|
|
|
PhotoFNumber: 3.3,
|
|
|
|
PhotoExposure: "exposure",
|
|
|
|
CameraID: uint(3),
|
2021-02-06 16:30:30 +01:00
|
|
|
CameraSrc: SrcMeta,
|
2020-05-08 15:46:16 +02:00
|
|
|
LensID: uint(6),
|
2020-07-12 08:27:05 +02:00
|
|
|
CellID: "1234",
|
2021-02-06 16:30:30 +01:00
|
|
|
PlaceSrc: SrcManual,
|
2020-05-29 12:56:24 +02:00
|
|
|
PlaceID: "765",
|
2020-05-08 15:46:16 +02:00
|
|
|
PhotoCountry: "de",
|
2020-05-18 22:18:58 +02:00
|
|
|
Details: form.Details{
|
|
|
|
PhotoID: uint(1000008),
|
|
|
|
Keywords: "test cat dog",
|
|
|
|
Subject: "animals",
|
|
|
|
Artist: "Bender",
|
|
|
|
Notes: "notes",
|
|
|
|
Copyright: "copy",
|
|
|
|
License: "",
|
|
|
|
},
|
2020-05-08 15:46:16 +02:00
|
|
|
}
|
|
|
|
|
2021-02-06 16:30:30 +01:00
|
|
|
m := PhotoFixtures.Get("Photo08")
|
2020-05-08 15:46:16 +02:00
|
|
|
|
2021-02-06 16:30:30 +01:00
|
|
|
if err := SavePhotoForm(m, f); err != nil {
|
2020-05-08 15:46:16 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
Db().First(&m)
|
|
|
|
|
|
|
|
assert.Equal(t, "manual", m.TakenSrc)
|
|
|
|
assert.Equal(t, "test", m.TimeZone)
|
|
|
|
assert.Equal(t, "Pink beach", m.PhotoTitle)
|
|
|
|
assert.Equal(t, "manual", m.TitleSrc)
|
|
|
|
assert.Equal(t, true, m.PhotoFavorite)
|
|
|
|
assert.Equal(t, true, m.PhotoPrivate)
|
2020-05-21 13:26:28 +02:00
|
|
|
assert.Equal(t, "image", m.PhotoType)
|
2020-05-08 15:46:16 +02:00
|
|
|
assert.Equal(t, float32(7.9999), m.PhotoLat)
|
|
|
|
assert.NotNil(t, m.EditedAt)
|
2020-07-06 19:15:57 +02:00
|
|
|
|
|
|
|
t.Log(m.GetDetails().Keywords)
|
2020-05-08 15:46:16 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
func TestPhoto_SaveLabels(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("NewPhoto", func(t *testing.T) {
|
2020-05-08 15:46:16 +02:00
|
|
|
photo := Photo{
|
2020-05-18 16:37:28 +02:00
|
|
|
ID: 11111,
|
2020-05-08 15:46:16 +02:00
|
|
|
TakenAt: time.Date(2008, 1, 1, 2, 0, 0, 0, time.UTC),
|
|
|
|
TakenAtLocal: time.Date(2008, 1, 1, 2, 0, 0, 0, time.UTC),
|
2020-05-25 19:10:44 +02:00
|
|
|
TakenSrc: "meta",
|
2020-05-08 15:46:16 +02:00
|
|
|
TimeZone: "UTC",
|
|
|
|
PhotoTitle: "Black beach",
|
|
|
|
TitleSrc: "manual",
|
|
|
|
PhotoFavorite: false,
|
|
|
|
PhotoPrivate: false,
|
2020-05-21 13:26:28 +02:00
|
|
|
PhotoType: "video",
|
2020-05-08 15:46:16 +02:00
|
|
|
PhotoLat: 9.9999,
|
|
|
|
PhotoLng: 8.8888,
|
|
|
|
PhotoAltitude: 2,
|
|
|
|
PhotoIso: 5,
|
|
|
|
PhotoFocalLength: 10,
|
|
|
|
PhotoFNumber: 3.3,
|
|
|
|
PhotoExposure: "exposure",
|
|
|
|
CameraID: uint(3),
|
2020-05-25 19:10:44 +02:00
|
|
|
CameraSrc: "meta",
|
2020-05-08 15:46:16 +02:00
|
|
|
LensID: uint(6),
|
2020-07-12 08:27:05 +02:00
|
|
|
CellID: "1234",
|
|
|
|
PlaceSrc: "geo",
|
2020-05-29 12:56:24 +02:00
|
|
|
PlaceID: "765",
|
2020-05-18 16:37:28 +02:00
|
|
|
PhotoCountry: "de",
|
|
|
|
Keywords: []Keyword{},
|
2020-07-06 19:15:57 +02:00
|
|
|
Details: &Details{
|
2020-05-19 13:48:05 +02:00
|
|
|
PhotoID: 11111,
|
|
|
|
Keywords: "test cat dog",
|
|
|
|
Subject: "animals",
|
|
|
|
Artist: "Bender",
|
|
|
|
Notes: "notes",
|
|
|
|
Copyright: "copy",
|
|
|
|
License: "",
|
|
|
|
},
|
2020-05-18 16:37:28 +02:00
|
|
|
}
|
2020-05-08 15:46:16 +02:00
|
|
|
|
2020-07-06 19:15:57 +02:00
|
|
|
err := photo.SaveLabels()
|
2020-05-19 12:51:19 +02:00
|
|
|
|
2022-01-05 11:40:44 +01:00
|
|
|
assert.EqualError(t, err, "photo: cannot save to database, id is empty")
|
2020-05-08 15:46:16 +02:00
|
|
|
})
|
2020-05-19 12:48:32 +02:00
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("ExistingPhoto", func(t *testing.T) {
|
2020-05-10 19:43:49 +02:00
|
|
|
m := PhotoFixtures.Get("19800101_000002_D640C559")
|
2020-07-06 19:15:57 +02:00
|
|
|
err := m.SaveLabels()
|
2020-05-08 15:46:16 +02:00
|
|
|
if err != nil {
|
2020-05-08 19:34:29 +02:00
|
|
|
t.Fatal(err)
|
2020-05-08 15:46:16 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_ClassifyLabels(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("NewPhoto", func(t *testing.T) {
|
2020-05-25 19:10:44 +02:00
|
|
|
m := PhotoFixtures.Get("Photo19")
|
2020-05-08 15:46:16 +02:00
|
|
|
Db().Set("gorm:auto_preload", true).Model(&m).Related(&m.Labels)
|
|
|
|
labels := m.ClassifyLabels()
|
|
|
|
assert.Empty(t, labels)
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("ExistingPhoto", func(t *testing.T) {
|
2020-05-10 19:43:49 +02:00
|
|
|
m := PhotoFixtures.Get("19800101_000002_D640C559")
|
2020-05-08 15:46:16 +02:00
|
|
|
Db().Set("gorm:auto_preload", true).Model(&m).Related(&m.Labels)
|
|
|
|
labels := m.ClassifyLabels()
|
|
|
|
assert.LessOrEqual(t, 2, labels.Len())
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("EmptyLabel", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
p := Photo{}
|
|
|
|
labels := p.ClassifyLabels()
|
|
|
|
assert.Empty(t, labels)
|
|
|
|
})
|
2020-05-08 15:46:16 +02:00
|
|
|
}
|
2020-05-11 17:01:19 +02:00
|
|
|
|
|
|
|
func TestPhoto_PreloadFiles(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.Empty(t, m.Files)
|
2021-09-02 11:12:42 +02:00
|
|
|
m.PreloadFiles()
|
2020-05-11 17:01:19 +02:00
|
|
|
assert.NotEmpty(t, m.Files)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PreloadKeywords(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.Empty(t, m.Keywords)
|
|
|
|
m.PreloadKeywords()
|
|
|
|
assert.NotEmpty(t, m.Keywords)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PreloadAlbums(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.Empty(t, m.Albums)
|
|
|
|
m.PreloadAlbums()
|
|
|
|
assert.NotEmpty(t, m.Albums)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PreloadMany(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.Empty(t, m.Albums)
|
|
|
|
assert.Empty(t, m.Files)
|
|
|
|
assert.Empty(t, m.Keywords)
|
|
|
|
|
|
|
|
m.PreloadMany()
|
|
|
|
|
|
|
|
assert.NotEmpty(t, m.Files)
|
|
|
|
assert.NotEmpty(t, m.Albums)
|
|
|
|
assert.NotEmpty(t, m.Keywords)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_NoCameraSerial(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("True", func(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
m := PhotoFixtures.Get("Photo04")
|
|
|
|
assert.True(t, m.NoCameraSerial())
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("False", func(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
m := PhotoFixtures.Get("Photo05")
|
|
|
|
assert.False(t, m.NoCameraSerial())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-06 19:15:57 +02:00
|
|
|
func TestPhoto_GetDetails(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("True", func(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
m := PhotoFixtures.Get("19800101_000002_D640C559")
|
2020-07-06 19:15:57 +02:00
|
|
|
result := m.GetDetails()
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should never be nil")
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:20:03 +02:00
|
|
|
if result.PhotoID != 1000000 {
|
|
|
|
t.Fatal("PhotoID should not be 1000000")
|
2020-07-06 19:15:57 +02:00
|
|
|
}
|
2020-05-11 17:01:19 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("False", func(t *testing.T) {
|
2020-05-19 13:48:05 +02:00
|
|
|
m := PhotoFixtures.Get("Photo12")
|
2020-07-06 19:15:57 +02:00
|
|
|
result := m.GetDetails()
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should never be nil")
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:20:03 +02:00
|
|
|
if result.PhotoID != 1000012 {
|
|
|
|
t.Fatal("PhotoID should not be 1000012")
|
2020-07-06 19:15:57 +02:00
|
|
|
}
|
2020-05-11 17:01:19 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("NoID", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
m := Photo{}
|
|
|
|
result := m.GetDetails()
|
|
|
|
assert.Equal(t, uint(0x0), result.PhotoID)
|
|
|
|
})
|
|
|
|
t.Run("new photo with ID", func(t *testing.T) {
|
|
|
|
m := Photo{ID: 79550, PhotoUID: "pthkffkgk"}
|
|
|
|
result := m.GetDetails()
|
|
|
|
assert.Equal(t, uint(0x136be), result.PhotoID)
|
|
|
|
})
|
2020-05-11 17:01:19 +02:00
|
|
|
}
|
|
|
|
|
2020-05-12 11:51:54 +02:00
|
|
|
func TestPhoto_AddLabels(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Add", func(t *testing.T) {
|
2020-05-12 11:51:54 +02:00
|
|
|
m := PhotoFixtures.Get("19800101_000002_D640C559")
|
2020-12-17 10:23:17 +01:00
|
|
|
classifyLabels := classify.Labels{{Name: "cactus", Uncertainty: 30, Source: SrcManual, Priority: 5, Categories: []string{"plant"}}}
|
2020-05-12 11:51:54 +02:00
|
|
|
len1 := len(m.Labels)
|
|
|
|
m.AddLabels(classifyLabels)
|
|
|
|
assert.Greater(t, len(m.Labels), len1)
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Update", func(t *testing.T) {
|
2020-05-12 11:51:54 +02:00
|
|
|
m := PhotoFixtures.Get("Photo15")
|
2020-12-17 10:23:17 +01:00
|
|
|
classifyLabels := classify.Labels{{Name: "landscape", Uncertainty: 10, Source: SrcManual, Priority: 5, Categories: []string{"plant"}}}
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, 20, m.Labels[0].Uncertainty)
|
2020-12-17 10:23:17 +01:00
|
|
|
assert.Equal(t, SrcImage, m.Labels[0].LabelSrc)
|
2020-05-12 11:51:54 +02:00
|
|
|
len1 := len(m.Labels)
|
|
|
|
m.AddLabels(classifyLabels)
|
|
|
|
assert.Equal(t, len(m.Labels), len1)
|
|
|
|
assert.Equal(t, 10, m.Labels[0].Uncertainty)
|
2020-12-17 10:23:17 +01:00
|
|
|
assert.Equal(t, SrcManual, m.Labels[0].LabelSrc)
|
2020-05-12 11:51:54 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetDescription(t *testing.T) {
|
|
|
|
t.Run("empty description", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
2020-05-18 22:18:58 +02:00
|
|
|
assert.Equal(t, "photo description blacklist", m.PhotoDescription)
|
2020-12-17 10:23:17 +01:00
|
|
|
m.SetDescription("", SrcManual)
|
2020-05-18 22:18:58 +02:00
|
|
|
assert.Equal(t, "photo description blacklist", m.PhotoDescription)
|
2020-05-12 11:51:54 +02:00
|
|
|
})
|
|
|
|
t.Run("description not from the same source", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
2020-05-18 22:18:58 +02:00
|
|
|
assert.Equal(t, "photo description blacklist", m.PhotoDescription)
|
2020-12-17 10:23:17 +01:00
|
|
|
m.SetDescription("new photo description", SrcName)
|
2020-05-18 22:18:58 +02:00
|
|
|
assert.Equal(t, "photo description blacklist", m.PhotoDescription)
|
2020-05-12 11:51:54 +02:00
|
|
|
})
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-05-12 11:51:54 +02:00
|
|
|
m := PhotoFixtures.Get("Photo15")
|
2020-05-18 22:18:58 +02:00
|
|
|
assert.Equal(t, "photo description blacklist", m.PhotoDescription)
|
2021-08-16 18:19:23 +02:00
|
|
|
m.SetDescription("new photo description", SrcMeta)
|
2020-05-18 22:18:58 +02:00
|
|
|
assert.Equal(t, "new photo description", m.PhotoDescription)
|
2020-05-12 11:51:54 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Delete(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("NotPermanent", func(t *testing.T) {
|
2020-05-12 11:51:54 +02:00
|
|
|
m := PhotoFixtures.Get("Photo16")
|
2021-09-24 13:13:59 +02:00
|
|
|
files, err := m.Delete(false)
|
2020-05-12 11:51:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-09-24 13:13:59 +02:00
|
|
|
assert.Len(t, files, 1)
|
2020-05-12 11:51:54 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Permanent", func(t *testing.T) {
|
2020-05-12 11:51:54 +02:00
|
|
|
m := PhotoFixtures.Get("Photo16")
|
2021-09-24 13:13:59 +02:00
|
|
|
files, err := m.Delete(true)
|
2020-05-12 11:51:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-09-24 13:13:59 +02:00
|
|
|
assert.Len(t, files, 1)
|
2020-05-12 11:51:54 +02:00
|
|
|
})
|
|
|
|
}
|
2020-07-10 17:27:06 +02:00
|
|
|
|
|
|
|
func TestPhotos_UIDs(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo1 := Photo{PhotoUID: "abc123"}
|
|
|
|
photo2 := Photo{PhotoUID: "abc456"}
|
|
|
|
photos := Photos{photo1, photo2}
|
|
|
|
assert.Equal(t, []string{"abc123", "abc456"}, photos.UIDs())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_String(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("ReturnOriginal", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "", PhotoName: "", OriginalName: "holidayOriginal"}
|
|
|
|
assert.Equal(t, "holidayOriginal", photo.String())
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Unknown", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "", PhotoName: "", OriginalName: ""}
|
|
|
|
assert.Equal(t, "(unknown)", photo.String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Create(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "567", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
err := photo.Create()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Save(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "567", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
err := photo.Save()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Error", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "pt9jtdre2lvl0yh0"}
|
|
|
|
assert.Error(t, photo.Save())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
func TestFindPhoto(t *testing.T) {
|
|
|
|
t.Run("Save", func(t *testing.T) {
|
2021-02-06 16:30:30 +01:00
|
|
|
photo := Photo{PhotoUID: "pt9atdre2lvl0yhx", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
if err := photo.Save(); err != nil {
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
assert.NotNil(t, FindPhoto(photo))
|
2020-07-10 17:27:06 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Found", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "pt9jtdre2lvl0yh0"}
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.NotNil(t, photo.Find())
|
|
|
|
assert.NotNil(t, FindPhoto(photo))
|
2020-07-10 17:27:06 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("EmptyStruct", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{}
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Nil(t, FindPhoto(photo))
|
|
|
|
assert.Nil(t, photo.Find())
|
2020-07-10 17:27:06 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("InvalidID", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{ID: 647487}
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Nil(t, FindPhoto(photo))
|
|
|
|
assert.Nil(t, photo.Find())
|
2020-07-10 17:27:06 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("InvalidUID", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "pt9jtdre2lvl0iuj"}
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Nil(t, FindPhoto(photo))
|
|
|
|
assert.Nil(t, photo.Find())
|
2020-07-10 17:27:06 +02:00
|
|
|
})
|
|
|
|
}
|
2022-09-28 09:01:17 +02:00
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
func TestPhoto_RemoveKeyword(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
keyword := Keyword{Keyword: "snake"}
|
|
|
|
keyword2 := Keyword{Keyword: "otter"}
|
|
|
|
keywords := []Keyword{keyword, keyword2}
|
|
|
|
photo := &Photo{Keywords: keywords}
|
|
|
|
err := photo.Save()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 2, len(photo.Keywords))
|
|
|
|
err = photo.RemoveKeyword("otter")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 2, len(photo.Keywords))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SyncKeywordLabels(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
keyword := Keyword{Keyword: "snake"}
|
|
|
|
keyword2 := Keyword{Keyword: "otter"}
|
|
|
|
keywords := []Keyword{keyword, keyword2}
|
|
|
|
label := Label{LabelName: "otter", LabelSlug: "otter"}
|
|
|
|
var deleteTime = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
|
|
label2 := Label{LabelName: "snake", LabelSlug: "snake", DeletedAt: &deleteTime}
|
|
|
|
photo := &Photo{ID: 34567, Keywords: keywords}
|
|
|
|
err := photo.Save()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = label.Save()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = label2.Save()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = photo.SyncKeywordLabels()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 2, len(photo.Keywords))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_LocationLoaded(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Photo", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "56798", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
assert.False(t, photo.LocationLoaded())
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("PhotoWithCell", func(t *testing.T) {
|
2020-07-12 08:27:05 +02:00
|
|
|
location := &Cell{Place: nil}
|
|
|
|
photo := Photo{PhotoName: "Holiday", Cell: location}
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.False(t, photo.LocationLoaded())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_LoadLocation(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := PhotoFixtures.Get("Photo03")
|
2022-09-28 09:01:17 +02:00
|
|
|
if err := photo.LoadLocation(); err != nil {
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("UnknownLocation", func(t *testing.T) {
|
2020-07-12 08:27:05 +02:00
|
|
|
location := &Cell{Place: nil}
|
|
|
|
photo := Photo{PhotoName: "Holiday", Cell: location}
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.Error(t, photo.LoadLocation())
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("KnownLocation", func(t *testing.T) {
|
2021-02-24 18:10:15 +01:00
|
|
|
location := CellFixtures.Pointer("mexico")
|
|
|
|
photo := Photo{PhotoName: "Holiday", Cell: location}
|
|
|
|
assert.Error(t, photo.LoadLocation())
|
|
|
|
})
|
2020-07-10 17:27:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PlaceLoaded(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("False", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "56798", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
assert.False(t, photo.PlaceLoaded())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_LoadPlace(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := PhotoFixtures.Get("Photo03")
|
|
|
|
err := photo.LoadPlace()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("UnknownLocation", func(t *testing.T) {
|
2020-07-12 08:27:05 +02:00
|
|
|
location := &Cell{Place: nil}
|
|
|
|
photo := Photo{PhotoName: "Holiday", Cell: location}
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.Error(t, photo.LoadPlace())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_HasDescription(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("False", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoDescription: ""}
|
|
|
|
assert.False(t, photo.HasDescription())
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("True", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoDescription: "bcss"}
|
|
|
|
assert.True(t, photo.HasDescription())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_NoDescription(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("True", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoDescription: ""}
|
|
|
|
assert.True(t, photo.NoDescription())
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("False", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoDescription: "bcss"}
|
|
|
|
assert.False(t, photo.NoDescription())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_AllFilesMissing(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("True", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{ID: 6969866}
|
|
|
|
assert.True(t, photo.AllFilesMissing())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Updates(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoDescription: "bcss", PhotoName: "InitialName"}
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
if err := photo.Save(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.Equal(t, "InitialName", photo.PhotoName)
|
|
|
|
assert.Equal(t, "bcss", photo.PhotoDescription)
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
if err := photo.Updates(Photo{PhotoName: "UpdatedName", PhotoDescription: "UpdatedDesc"}); err != nil {
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-09-28 09:01:17 +02:00
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.Equal(t, "UpdatedName", photo.PhotoName)
|
|
|
|
assert.Equal(t, "UpdatedDesc", photo.PhotoDescription)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetFavorite(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("SetTrue", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoFavorite: true}
|
|
|
|
|
2021-11-24 14:32:40 +01:00
|
|
|
if err := photo.Save(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := photo.SetFavorite(false); err != nil {
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-11-24 14:32:40 +01:00
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.Equal(t, false, photo.PhotoFavorite)
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("SetFalse", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoFavorite: false}
|
|
|
|
|
2021-11-24 14:32:40 +01:00
|
|
|
if err := photo.Save(); err != nil {
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-11-24 14:32:40 +01:00
|
|
|
|
|
|
|
if err := photo.SetFavorite(true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.Equal(t, true, photo.PhotoFavorite)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-06 14:33:49 +01:00
|
|
|
func TestPhoto_SetStack(t *testing.T) {
|
|
|
|
t.Run("Ignore", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo27")
|
|
|
|
assert.Equal(t, IsStackable, m.PhotoStack)
|
|
|
|
m.SetStack(IsStackable)
|
|
|
|
assert.Equal(t, IsStackable, m.PhotoStack)
|
|
|
|
})
|
|
|
|
t.Run("Update", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo27")
|
|
|
|
assert.Equal(t, IsStackable, m.PhotoStack)
|
|
|
|
m.SetStack(IsUnstacked)
|
|
|
|
assert.Equal(t, IsUnstacked, m.PhotoStack)
|
|
|
|
m.SetStack(IsStackable)
|
|
|
|
assert.Equal(t, IsStackable, m.PhotoStack)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
func TestPhoto_Approve(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Quality4", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoQuality: 4}
|
|
|
|
|
2020-12-11 17:21:13 +01:00
|
|
|
if err := photo.Save(); err != nil {
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-12-11 17:21:13 +01:00
|
|
|
|
|
|
|
if err := photo.Approve(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-11 22:09:11 +01:00
|
|
|
assert.Equal(t, 4, photo.PhotoQuality)
|
2020-07-10 17:27:06 +02:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Quality1", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoQuality: 1}
|
|
|
|
|
2020-12-11 17:21:13 +01:00
|
|
|
if err := photo.Save(); err != nil {
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-12-11 17:21:13 +01:00
|
|
|
|
|
|
|
if err := photo.Approve(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:27:06 +02:00
|
|
|
assert.Equal(t, 3, photo.PhotoQuality)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Links(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("OneResult", func(t *testing.T) {
|
2020-07-10 17:27:06 +02:00
|
|
|
photo := Photo{PhotoUID: "pt9k3pw1wowuy3c3"}
|
|
|
|
links := photo.Links()
|
|
|
|
assert.Equal(t, "7jxf3jfn2k", links[0].LinkToken)
|
|
|
|
})
|
|
|
|
}
|
2021-01-24 20:40:40 +01:00
|
|
|
|
|
|
|
func TestPhoto_SetPrimary(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2021-01-24 20:40:40 +01:00
|
|
|
m := PhotoFixtures.Get("19800101_000002_D640C559")
|
|
|
|
|
|
|
|
if err := m.SetPrimary(""); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-02-24 18:10:15 +01:00
|
|
|
|
|
|
|
func TestMapKey(t *testing.T) {
|
|
|
|
assert.Equal(t, "ogh006/abc236", MapKey(time.Date(2016, 11, 11, 9, 7, 18, 0, time.UTC), "abc236"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPhoto(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Stackable", func(t *testing.T) {
|
2021-02-24 18:10:15 +01:00
|
|
|
m := NewPhoto(true)
|
|
|
|
assert.Equal(t, IsStackable, m.PhotoStack)
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("NotStackable", func(t *testing.T) {
|
2021-02-24 18:10:15 +01:00
|
|
|
m := NewPhoto(false)
|
|
|
|
assert.Equal(t, IsUnstacked, m.PhotoStack)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_FirstOrCreate(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("ExistingPhoto", func(t *testing.T) {
|
|
|
|
initialUID := "567454"
|
|
|
|
photo := Photo{PhotoUID: initialUID, PhotoName: "Light", OriginalName: "lightBlub.jpg"}
|
|
|
|
|
|
|
|
if err := photo.Save(); err != nil {
|
2021-02-24 18:10:15 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
assert.NotNil(t, FindPhoto(photo))
|
|
|
|
assert.Nil(t, FindPhoto(Photo{PhotoUID: initialUID}))
|
|
|
|
|
|
|
|
created := photo.FirstOrCreate()
|
|
|
|
|
|
|
|
assert.NotNil(t, created)
|
|
|
|
assert.Equal(t, photo.ID, created.ID)
|
|
|
|
assert.Equal(t, photo.PhotoUID, created.PhotoUID)
|
2021-02-24 18:10:15 +01:00
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("NewPhoto", func(t *testing.T) {
|
|
|
|
initialUID := "567459"
|
|
|
|
photo := Photo{PhotoUID: initialUID, PhotoName: "Light2", OriginalName: "lightBlub2.jpg"}
|
|
|
|
|
|
|
|
assert.Nil(t, FindPhoto(photo))
|
|
|
|
|
|
|
|
if created := photo.FirstOrCreate(); created == nil {
|
|
|
|
t.Fatal("created must not be nil")
|
|
|
|
} else {
|
|
|
|
assert.Truef(t, created.ID > 0, "%d should be > 0", created.ID)
|
|
|
|
assert.Equal(t, photo.PhotoUID, created.PhotoUID)
|
|
|
|
assert.Nil(t, FindPhoto(Photo{PhotoUID: initialUID}))
|
|
|
|
assert.NotNil(t, FindPhoto(photo))
|
|
|
|
assert.NotNil(t, FindPhoto(*created))
|
2021-02-24 18:10:15 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_UnknownCamera(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
photo := Photo{}
|
|
|
|
assert.True(t, photo.UnknownCamera())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := Photo{CameraID: 100000}
|
|
|
|
assert.False(t, photo.UnknownCamera())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_UnknownLens(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
photo := Photo{}
|
|
|
|
assert.True(t, photo.UnknownLens())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := Photo{LensID: 100000}
|
|
|
|
assert.False(t, photo.UnknownLens())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_UpdateDateFields(t *testing.T) {
|
|
|
|
t.Run("year < 1000", func(t *testing.T) {
|
|
|
|
photo := &Photo{TakenAt: time.Date(900, 11, 11, 9, 7, 18, 0, time.UTC)}
|
|
|
|
photo.UpdateDateFields()
|
|
|
|
assert.Equal(t, time.Date(900, 11, 11, 9, 7, 18, 0, time.UTC), photo.TakenAt)
|
|
|
|
assert.Empty(t, photo.TakenAtLocal)
|
|
|
|
})
|
|
|
|
t.Run("set to unknown", func(t *testing.T) {
|
|
|
|
photo := &Photo{TakenAt: time.Date(1900, 11, 11, 9, 7, 18, 0, time.UTC), TakenSrc: SrcAuto, CreatedAt: time.Date(1900, 11, 11, 5, 7, 18, 0, time.UTC)}
|
|
|
|
photo.UpdateDateFields()
|
2021-08-16 00:29:36 +02:00
|
|
|
assert.Equal(t, UnknownYear, photo.PhotoYear)
|
2021-02-24 18:10:15 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetCamera(t *testing.T) {
|
|
|
|
t.Run("camera nil", func(t *testing.T) {
|
|
|
|
photo := &Photo{}
|
|
|
|
photo.SetCamera(nil, SrcAuto)
|
|
|
|
assert.Empty(t, photo.Camera)
|
|
|
|
})
|
|
|
|
t.Run("camera unknown", func(t *testing.T) {
|
|
|
|
photo := &Photo{}
|
|
|
|
camera := &Camera{CameraSlug: ""}
|
|
|
|
photo.SetCamera(camera, SrcAuto)
|
|
|
|
assert.Empty(t, photo.Camera)
|
|
|
|
})
|
|
|
|
t.Run("do not overwrite manual changes", func(t *testing.T) {
|
|
|
|
cameraOld := &Camera{CameraSlug: "OldCamera", ID: 10000000111}
|
|
|
|
photo := &Photo{CameraSrc: SrcManual, Camera: cameraOld, CameraID: 10000000111}
|
|
|
|
assert.Equal(t, "OldCamera", photo.Camera.CameraSlug)
|
|
|
|
assert.Equal(t, SrcManual, photo.CameraSrc)
|
|
|
|
assert.False(t, photo.UnknownCamera())
|
|
|
|
camera := &Camera{CameraSlug: "NewCamera"}
|
|
|
|
photo.SetCamera(camera, SrcAuto)
|
|
|
|
assert.Equal(t, "OldCamera", photo.Camera.CameraSlug)
|
|
|
|
})
|
|
|
|
t.Run("set new camera", func(t *testing.T) {
|
|
|
|
cameraOld := &Camera{CameraSlug: "OldCamera", ID: 10000000111}
|
|
|
|
photo := &Photo{CameraSrc: SrcAuto, Camera: cameraOld, CameraID: 10000000111}
|
|
|
|
assert.Equal(t, "OldCamera", photo.Camera.CameraSlug)
|
|
|
|
camera := &Camera{CameraSlug: "NewCamera"}
|
|
|
|
photo.SetCamera(camera, SrcMeta)
|
|
|
|
assert.Equal(t, "NewCamera", photo.Camera.CameraSlug)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetLens(t *testing.T) {
|
|
|
|
t.Run("lens nil", func(t *testing.T) {
|
|
|
|
photo := &Photo{}
|
|
|
|
photo.SetLens(nil, SrcAuto)
|
|
|
|
assert.Empty(t, photo.Lens)
|
|
|
|
})
|
|
|
|
t.Run("lens unknown", func(t *testing.T) {
|
|
|
|
photo := &Photo{}
|
|
|
|
lens := &Lens{LensSlug: ""}
|
|
|
|
photo.SetLens(lens, SrcAuto)
|
|
|
|
assert.Empty(t, photo.Lens)
|
|
|
|
})
|
|
|
|
t.Run("do not overwrite manual changes", func(t *testing.T) {
|
|
|
|
lensOld := &Lens{LensSlug: "OldLens", ID: 10000000111}
|
|
|
|
photo := &Photo{CameraSrc: SrcManual, Lens: lensOld, LensID: 10000000111}
|
|
|
|
assert.Equal(t, "OldLens", photo.Lens.LensSlug)
|
|
|
|
lens := &Lens{LensSlug: "NewLens"}
|
|
|
|
photo.SetLens(lens, SrcAuto)
|
|
|
|
assert.Equal(t, "OldLens", photo.Lens.LensSlug)
|
|
|
|
})
|
|
|
|
t.Run("set new camera", func(t *testing.T) {
|
|
|
|
lensOld := &Lens{LensSlug: "OldLens", ID: 10000000111}
|
|
|
|
photo := &Photo{CameraSrc: SrcAuto, Lens: lensOld, LensID: 10000000111}
|
|
|
|
assert.Equal(t, "OldLens", photo.Lens.LensSlug)
|
|
|
|
lens := &Lens{LensSlug: "NewLens"}
|
|
|
|
photo.SetLens(lens, SrcMeta)
|
|
|
|
assert.Equal(t, "NewLens", photo.Lens.LensSlug)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetExposure(t *testing.T) {
|
|
|
|
t.Run("changes have priority", func(t *testing.T) {
|
|
|
|
photo := &Photo{PhotoFocalLength: 5, PhotoFNumber: 3, PhotoIso: 300, PhotoExposure: "45", CameraSrc: SrcMeta}
|
|
|
|
photo.SetExposure(8, 9, 500, "66", SrcManual)
|
|
|
|
assert.Equal(t, 8, photo.PhotoFocalLength)
|
|
|
|
assert.Equal(t, float32(9), photo.PhotoFNumber)
|
|
|
|
assert.Equal(t, 500, photo.PhotoIso)
|
|
|
|
assert.Equal(t, "66", photo.PhotoExposure)
|
|
|
|
})
|
|
|
|
t.Run("changes have no priority", func(t *testing.T) {
|
|
|
|
photo := &Photo{PhotoFocalLength: 5, PhotoFNumber: 3, PhotoIso: 300, PhotoExposure: "45", CameraSrc: SrcManual}
|
|
|
|
photo.SetExposure(8, 9, 500, "66", SrcMeta)
|
|
|
|
assert.Equal(t, 5, photo.PhotoFocalLength)
|
|
|
|
assert.Equal(t, float32(3), photo.PhotoFNumber)
|
|
|
|
assert.Equal(t, 300, photo.PhotoIso)
|
|
|
|
assert.Equal(t, "45", photo.PhotoExposure)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_AllFiles(t *testing.T) {
|
|
|
|
t.Run("photo with files", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
files := m.AllFiles()
|
|
|
|
assert.Equal(t, 2, len(files))
|
|
|
|
})
|
|
|
|
t.Run("photo without files", func(t *testing.T) {
|
2021-08-26 17:26:48 +02:00
|
|
|
m := &Photo{ID: 100000023456}
|
2021-02-24 18:10:15 +01:00
|
|
|
files := m.AllFiles()
|
|
|
|
assert.Equal(t, 0, len(files))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Archive(t *testing.T) {
|
|
|
|
t.Run("archive not yet archived photo", func(t *testing.T) {
|
|
|
|
m := &Photo{PhotoTitle: "HappyLilly"}
|
|
|
|
assert.Empty(t, m.DeletedAt)
|
|
|
|
err := m.Archive()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.NotEmpty(t, m.DeletedAt)
|
|
|
|
err = m.Restore()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Empty(t, m.DeletedAt)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetCameraSerial(t *testing.T) {
|
|
|
|
m := &Photo{}
|
|
|
|
assert.Empty(t, m.CameraSerial)
|
|
|
|
m.SetCameraSerial("abcCamera")
|
|
|
|
assert.Equal(t, "abcCamera", m.CameraSerial)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_MapKey(t *testing.T) {
|
|
|
|
m := &Photo{TakenAt: time.Date(2016, 11, 11, 9, 7, 18, 0, time.UTC), CellID: "abc236"}
|
|
|
|
assert.Equal(t, "ogh006/abc236", m.MapKey())
|
|
|
|
}
|