2020-05-08 15:46:16 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2020-05-18 22:18:58 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
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"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSavePhotoForm(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
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",
|
|
|
|
TitleSrc: "manual",
|
|
|
|
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),
|
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: "manual",
|
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
|
|
|
}
|
|
|
|
|
|
|
|
m := PhotoFixtures["Photo08"]
|
|
|
|
|
2020-12-05 00:13:44 +01:00
|
|
|
err := SavePhotoForm(m, f)
|
2020-05-08 15:46:16 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
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) {
|
2020-05-08 15:46:16 +02:00
|
|
|
t.Run("new photo", func(t *testing.T) {
|
|
|
|
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
|
|
|
|
|
|
|
assert.EqualError(t, err, "photo: can't save to database, id is empty")
|
2020-05-08 15:46:16 +02:00
|
|
|
})
|
2020-05-19 12:48:32 +02:00
|
|
|
|
2020-05-08 15:46:16 +02:00
|
|
|
t.Run("existing photo", 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) {
|
|
|
|
t.Run("new photo", 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)
|
|
|
|
})
|
|
|
|
t.Run("existing photo", 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())
|
|
|
|
})
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Run("empty label", func(t *testing.T) {
|
|
|
|
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) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.Empty(t, m.Files)
|
|
|
|
m.PreloadFiles()
|
|
|
|
assert.NotEmpty(t, m.Files)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PreloadKeywords(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.Empty(t, m.Keywords)
|
|
|
|
m.PreloadKeywords()
|
|
|
|
assert.NotEmpty(t, m.Keywords)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PreloadAlbums(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.Empty(t, m.Albums)
|
|
|
|
m.PreloadAlbums()
|
|
|
|
assert.NotEmpty(t, m.Albums)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PreloadMany(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
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_NoLocation(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
2020-05-28 15:12:18 +02:00
|
|
|
assert.True(t, m.UnknownLocation())
|
2020-05-11 17:01:19 +02:00
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo08")
|
2020-05-25 19:10:44 +02:00
|
|
|
// t.Logf("MODEL: %+v", m)
|
|
|
|
assert.True(t, m.HasLocation())
|
2020-05-28 15:12:18 +02:00
|
|
|
assert.False(t, m.UnknownLocation())
|
2020-05-11 17:01:19 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_HasLocation(t *testing.T) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.False(t, m.HasLocation())
|
|
|
|
})
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo08")
|
|
|
|
assert.True(t, m.HasLocation())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_HasLatLng(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.True(t, m.HasLatLng())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo08")
|
|
|
|
assert.False(t, m.HasLatLng())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_NoLatLng(t *testing.T) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.False(t, m.NoLatLng())
|
|
|
|
})
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo08")
|
|
|
|
assert.True(t, m.NoLatLng())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_NoPlace(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
2020-05-28 15:12:18 +02:00
|
|
|
assert.True(t, m.UnknownPlace())
|
2020-05-11 17:01:19 +02:00
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo08")
|
2020-05-28 15:12:18 +02:00
|
|
|
assert.False(t, m.UnknownPlace())
|
2020-05-11 17:01:19 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_HasPlace(t *testing.T) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo01")
|
|
|
|
assert.False(t, m.HasPlace())
|
|
|
|
})
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo08")
|
|
|
|
assert.True(t, m.HasPlace())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_HasTitle(t *testing.T) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo03")
|
|
|
|
assert.False(t, m.HasTitle())
|
|
|
|
})
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo04")
|
|
|
|
assert.True(t, m.HasTitle())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_NoTitle(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo03")
|
|
|
|
assert.True(t, m.NoTitle())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo04")
|
|
|
|
assert.False(t, m.NoTitle())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_NoCameraSerial(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo04")
|
|
|
|
assert.True(t, m.NoCameraSerial())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo05")
|
|
|
|
assert.False(t, m.NoCameraSerial())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-06 19:15:57 +02:00
|
|
|
func TestPhoto_GetDetails(t *testing.T) {
|
2020-05-11 17:01:19 +02:00
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
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
|
|
|
})
|
|
|
|
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
|
|
|
})
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Run("no ID", func(t *testing.T) {
|
|
|
|
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-07-06 11:31:03 +02:00
|
|
|
func TestPhoto_FileTitle(t *testing.T) {
|
2020-12-27 16:37:28 +01:00
|
|
|
t.Run("non-latin", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoName: "桥", PhotoPath: "", OriginalName: ""}
|
|
|
|
result := photo.FileTitle()
|
|
|
|
assert.Equal(t, "桥", result)
|
|
|
|
})
|
2020-05-31 14:42:41 +02:00
|
|
|
t.Run("changing-of-the-guard--buckingham-palace_7925318070_o.jpg", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoName: "20200102_194030_9EFA9E5E", PhotoPath: "2000/05", OriginalName: "flickr import/changing-of-the-guard--buckingham-palace_7925318070_o.jpg"}
|
2020-07-06 11:31:03 +02:00
|
|
|
result := photo.FileTitle()
|
2020-05-31 14:42:41 +02:00
|
|
|
assert.Equal(t, "Changing of the Guard / Buckingham Palace", result)
|
|
|
|
})
|
2020-07-10 17:27:06 +02:00
|
|
|
t.Run("empty title", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoName: "", PhotoPath: "", OriginalName: ""}
|
|
|
|
result := photo.FileTitle()
|
|
|
|
assert.Equal(t, "", result)
|
|
|
|
})
|
|
|
|
t.Run("return title", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoName: "sun, beach, fun", PhotoPath: "", OriginalName: "", PhotoTitle: ""}
|
|
|
|
result := photo.FileTitle()
|
|
|
|
assert.Equal(t, "Sun, Beach, Fun", result)
|
|
|
|
})
|
|
|
|
t.Run("return title", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoName: "", PhotoPath: "vacation", OriginalName: "20200102_194030_9EFA9E5E", PhotoTitle: ""}
|
|
|
|
result := photo.FileTitle()
|
|
|
|
assert.Equal(t, "Vacation", result)
|
|
|
|
})
|
2020-05-31 14:42:41 +02:00
|
|
|
}
|
|
|
|
|
2020-05-11 17:01:19 +02:00
|
|
|
func TestPhoto_UpdateTitle(t *testing.T) {
|
|
|
|
t.Run("wont update title was modified", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo08")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "Black beach", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal()
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Black beach", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("photo with location without city and label", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo10")
|
|
|
|
classifyLabels := &classify.Labels{{Name: "tree", Uncertainty: 30, Source: "manual", Priority: 5, Categories: []string{"plant"}}}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Tree / Germany / 2016", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("photo with location and short city and label", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo09")
|
|
|
|
classifyLabels := &classify.Labels{{Name: "tree", Uncertainty: 30, Source: "manual", Priority: 5, Categories: []string{"plant"}}}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Tree / Teotihuacán / 2016", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("photo with location and locname >45", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo13")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "LonglonglonglonglonglonglonglonglonglonglonglonglongName", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("photo with location and locname >20", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo14")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "longlonglonglonglonglongName / 2016", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("photo with location and short city", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo09")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Adosada Platform / Teotihuacán / 2016", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("photo with location without city", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo10")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Holiday Park / Germany / 2016", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("photo with location without loc name and long city", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo11")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "longlonglonglonglongcity / 2016", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("photo with location without loc name and short city", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo12")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "Title", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "shortcity / Germany / 2016", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("no location", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("19800101_000002_D640C559")
|
2020-12-17 10:23:17 +01:00
|
|
|
classifyLabels := &classify.Labels{{Name: "classify", Uncertainty: 30, Source: SrcManual, Priority: 5, Categories: []string{"flower", "plant"}}}
|
2020-05-11 17:01:19 +02:00
|
|
|
assert.Equal(t, "", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Classify / 2008", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("no location no labels", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo02")
|
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Unknown / 2008", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("no location no labels no takenAt", func(t *testing.T) {
|
2020-12-11 17:21:13 +01:00
|
|
|
m := PhotoFixtures.Get("Photo20")
|
2020-05-11 17:01:19 +02:00
|
|
|
classifyLabels := &classify.Labels{}
|
|
|
|
assert.Equal(t, "", m.PhotoTitle)
|
|
|
|
err := m.UpdateTitle(*classifyLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Unknown", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
}
|
2020-05-12 11:51:54 +02:00
|
|
|
|
|
|
|
func TestPhoto_AddLabels(t *testing.T) {
|
|
|
|
t.Run("add label", func(t *testing.T) {
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
t.Run("update label", func(t *testing.T) {
|
|
|
|
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_SetTitle(t *testing.T) {
|
|
|
|
t.Run("empty title", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, "TitleToBeSet", m.PhotoTitle)
|
2020-12-17 10:23:17 +01:00
|
|
|
m.SetTitle("", SrcManual)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, "TitleToBeSet", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("title not from the same source", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, "TitleToBeSet", m.PhotoTitle)
|
2020-12-17 10:23:17 +01:00
|
|
|
m.SetTitle("NewTitleSet", SrcAuto)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, "TitleToBeSet", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, "TitleToBeSet", m.PhotoTitle)
|
2020-12-17 10:23:17 +01:00
|
|
|
m.SetTitle("NewTitleSet", SrcLocation)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, "NewTitleSet", m.PhotoTitle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
})
|
|
|
|
t.Run("success", 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", SrcManual)
|
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_SetTakenAt(t *testing.T) {
|
|
|
|
t.Run("empty taken", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
2020-12-17 10:23:17 +01:00
|
|
|
m.SetTakenAt(time.Time{}, time.Time{}, "", SrcManual)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
})
|
|
|
|
t.Run("taken not from the same source", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
m.SetTakenAt(time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC),
|
2020-12-17 10:23:17 +01:00
|
|
|
time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC), "", SrcAuto)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
})
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
|
|
|
m.SetTakenAt(time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC),
|
2020-12-17 10:23:17 +01:00
|
|
|
time.Date(2019, 12, 11, 10, 7, 18, 0, time.UTC), "", SrcMeta)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
assert.Equal(t, time.Date(2019, 12, 11, 10, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
|
|
|
})
|
2020-08-18 10:42:09 +02:00
|
|
|
t.Run("time > max year", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
|
|
|
m.SetTakenAt(time.Date(2123, 12, 11, 9, 7, 18, 0, time.UTC),
|
2020-12-17 10:23:17 +01:00
|
|
|
time.Date(2123, 12, 11, 10, 7, 18, 0, time.UTC), "", SrcManual)
|
2020-08-18 10:42:09 +02:00
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
|
|
|
})
|
2020-05-12 11:51:54 +02:00
|
|
|
t.Run("success with empty takenAtLocal", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
assert.Equal(t, time.Date(2013, 11, 11, 9, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
|
|
|
m.SetTakenAt(time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC),
|
2020-12-17 10:23:17 +01:00
|
|
|
time.Time{}, "test", SrcXmp)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC), m.TakenAt)
|
|
|
|
assert.Equal(t, time.Date(2019, 12, 11, 9, 7, 18, 0, time.UTC), m.TakenAtLocal)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetCoordinates(t *testing.T) {
|
|
|
|
t.Run("empty coordinates", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, float32(1.234), m.PhotoLat)
|
|
|
|
assert.Equal(t, float32(4.321), m.PhotoLng)
|
|
|
|
assert.Equal(t, 3, m.PhotoAltitude)
|
2020-12-17 10:23:17 +01:00
|
|
|
m.SetCoordinates(0, 0, 5, SrcManual)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, float32(1.234), m.PhotoLat)
|
|
|
|
assert.Equal(t, float32(4.321), m.PhotoLng)
|
|
|
|
assert.Equal(t, 3, m.PhotoAltitude)
|
|
|
|
})
|
|
|
|
t.Run("different source", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, float32(1.234), m.PhotoLat)
|
|
|
|
assert.Equal(t, float32(4.321), m.PhotoLng)
|
|
|
|
assert.Equal(t, 3, m.PhotoAltitude)
|
2021-01-19 11:38:35 +01:00
|
|
|
m.SetCoordinates(5.555, 5.555, 5, SrcName)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, float32(1.234), m.PhotoLat)
|
|
|
|
assert.Equal(t, float32(4.321), m.PhotoLng)
|
|
|
|
assert.Equal(t, 3, m.PhotoAltitude)
|
|
|
|
})
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo15")
|
|
|
|
assert.Equal(t, float32(1.234), m.PhotoLat)
|
|
|
|
assert.Equal(t, float32(4.321), m.PhotoLng)
|
|
|
|
assert.Equal(t, 3, m.PhotoAltitude)
|
2021-01-19 11:38:35 +01:00
|
|
|
m.SetCoordinates(5.555, 5.555, 5, SrcLocation)
|
2020-05-12 11:51:54 +02:00
|
|
|
assert.Equal(t, float32(5.555), m.PhotoLat)
|
|
|
|
assert.Equal(t, float32(5.555), m.PhotoLng)
|
|
|
|
assert.Equal(t, 5, m.PhotoAltitude)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Delete(t *testing.T) {
|
|
|
|
t.Run("not permanent", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo16")
|
|
|
|
err := m.Delete(false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("permanent", func(t *testing.T) {
|
|
|
|
m := PhotoFixtures.Get("Photo16")
|
|
|
|
err := m.Delete(true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-07-10 17:27:06 +02:00
|
|
|
|
|
|
|
func TestPhotos_UIDs(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
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) {
|
|
|
|
t.Run("return original", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "", PhotoName: "", OriginalName: "holidayOriginal"}
|
|
|
|
assert.Equal(t, "holidayOriginal", photo.String())
|
|
|
|
})
|
|
|
|
t.Run("unknown", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "", PhotoName: "", OriginalName: ""}
|
|
|
|
assert.Equal(t, "(unknown)", photo.String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Create(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "567", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
err := photo.Create()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Save(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "567", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
err := photo.Save()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("error", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "pt9jtdre2lvl0yh0"}
|
|
|
|
assert.Error(t, photo.Save())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Find(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "567", ID: 55, PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
err := photo.Save()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = photo.Find()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "pt9jtdre2lvl0yh0"}
|
|
|
|
err := photo.Find()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("photo uid and id empty", func(t *testing.T) {
|
|
|
|
photo := Photo{}
|
|
|
|
assert.Error(t, photo.Find())
|
|
|
|
})
|
|
|
|
t.Run("error", func(t *testing.T) {
|
|
|
|
photo := Photo{ID: 647487}
|
|
|
|
assert.Error(t, photo.Find())
|
|
|
|
})
|
|
|
|
t.Run("error", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "pt9jtdre2lvl0iuj"}
|
|
|
|
assert.Error(t, photo.Find())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
func TestPhoto_RemoveKeyword(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
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) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
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) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "56798", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
assert.False(t, photo.LocationLoaded())
|
|
|
|
})
|
|
|
|
t.Run("false", 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) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo03")
|
|
|
|
err := photo.LoadLocation()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("unknown location", 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())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_PlaceLoaded(t *testing.T) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "56798", PhotoName: "Holiday", OriginalName: "holidayOriginal2"}
|
|
|
|
assert.False(t, photo.PlaceLoaded())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_LoadPlace(t *testing.T) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo03")
|
|
|
|
err := photo.LoadPlace()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("unknown location", 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) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoDescription: ""}
|
|
|
|
assert.False(t, photo.HasDescription())
|
|
|
|
})
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoDescription: "bcss"}
|
|
|
|
assert.True(t, photo.HasDescription())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_NoDescription(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoDescription: ""}
|
|
|
|
assert.True(t, photo.NoDescription())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoDescription: "bcss"}
|
|
|
|
assert.False(t, photo.NoDescription())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_AllFilesMissing(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
photo := Photo{ID: 6969866}
|
|
|
|
assert.True(t, photo.AllFilesMissing())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Updates(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoDescription: "bcss", PhotoName: "InitialName"}
|
|
|
|
photo.Save()
|
|
|
|
assert.Equal(t, "InitialName", photo.PhotoName)
|
|
|
|
assert.Equal(t, "bcss", photo.PhotoDescription)
|
|
|
|
|
|
|
|
err := photo.Updates(Photo{PhotoName: "UpdatedName", PhotoDescription: "UpdatedDesc"})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "UpdatedName", photo.PhotoName)
|
|
|
|
assert.Equal(t, "UpdatedDesc", photo.PhotoDescription)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_SetFavorite(t *testing.T) {
|
|
|
|
t.Run("set to true", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoFavorite: true}
|
|
|
|
photo.Save()
|
|
|
|
|
|
|
|
err := photo.SetFavorite(false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, false, photo.PhotoFavorite)
|
|
|
|
})
|
|
|
|
t.Run("set to false", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoFavorite: false}
|
|
|
|
photo.Save()
|
|
|
|
|
|
|
|
err := photo.SetFavorite(true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, true, photo.PhotoFavorite)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Approve(t *testing.T) {
|
|
|
|
t.Run("quality = 4", func(t *testing.T) {
|
|
|
|
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
|
|
|
})
|
|
|
|
t.Run("quality = 1", func(t *testing.T) {
|
|
|
|
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) {
|
|
|
|
t.Run("1 result", func(t *testing.T) {
|
|
|
|
photo := Photo{PhotoUID: "pt9k3pw1wowuy3c3"}
|
|
|
|
links := photo.Links()
|
|
|
|
assert.Equal(t, "7jxf3jfn2k", links[0].LinkToken)
|
|
|
|
})
|
|
|
|
}
|