Additional photo location unit tests (#918)
This commit is contained in:
parent
bbbc6a737e
commit
c27e809308
2 changed files with 107 additions and 11 deletions
|
@ -1057,6 +1057,54 @@ var PhotoFixtures = PhotoMap{
|
|||
EditedAt: nil,
|
||||
DeletedAt: nil,
|
||||
},
|
||||
"Photo21": {
|
||||
ID: 1000021,
|
||||
PhotoUID: "pt9jtxrexxvl0y21",
|
||||
TakenAt: time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
TakenAtLocal: time.Time{},
|
||||
TakenSrc: "",
|
||||
PhotoTitle: "",
|
||||
TitleSrc: "",
|
||||
PhotoPath: "1990/04",
|
||||
PhotoName: "Photo21",
|
||||
PhotoQuality: 1,
|
||||
PhotoResolution: 2,
|
||||
PhotoFavorite: false,
|
||||
PhotoPrivate: false,
|
||||
PhotoType: "image",
|
||||
PhotoLat: 0,
|
||||
PhotoLng: 0,
|
||||
PhotoAltitude: 0,
|
||||
PhotoIso: 0,
|
||||
PhotoFocalLength: 0,
|
||||
PhotoFNumber: 0,
|
||||
PhotoExposure: "",
|
||||
CameraSerial: "",
|
||||
CameraSrc: "",
|
||||
Place: &UnknownPlace,
|
||||
Cell: &UnknownLocation,
|
||||
PlaceID: UnknownPlace.ID,
|
||||
CellID: UnknownLocation.ID,
|
||||
PlaceSrc: SrcEstimate,
|
||||
TimeZone: "",
|
||||
PhotoCountry: UnknownPlace.CountryCode(),
|
||||
PhotoYear: 1990,
|
||||
PhotoMonth: 4,
|
||||
Details: DetailsFixtures.Pointer("bridge", 1000019),
|
||||
DescriptionSrc: "",
|
||||
Camera: CameraFixtures.Pointer("canon-eos-6d"),
|
||||
CameraID: CameraFixtures.Pointer("canon-eos-6d").ID,
|
||||
Lens: LensFixtures.Pointer("lens-f-380"),
|
||||
LensID: LensFixtures.Pointer("lens-f-380").ID,
|
||||
Keywords: []Keyword{},
|
||||
Albums: []Album{},
|
||||
Files: []File{},
|
||||
Labels: []PhotoLabel{},
|
||||
CreatedAt: time.Date(2009, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
UpdatedAt: time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
EditedAt: nil,
|
||||
DeletedAt: nil,
|
||||
},
|
||||
}
|
||||
|
||||
// CreatePhotoFixtures inserts known entities into the database for testing.
|
||||
|
|
|
@ -723,30 +723,78 @@ func TestPhoto_UpdateTimeZone(t *testing.T) {
|
|||
func TestPhoto_SetCoordinates(t *testing.T) {
|
||||
t.Run("empty coordinates", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
assert.Equal(t, float32(1.234), m.PhotoLat)
|
||||
assert.Equal(t, float32(4.321), m.PhotoLng)
|
||||
assert.Equal(t, 3, m.PhotoAltitude)
|
||||
|
||||
m.SetCoordinates(0, 0, 5, SrcManual)
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
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)
|
||||
m.SetCoordinates(5.555, 5.555, 5, SrcName)
|
||||
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) {
|
||||
t.Run("same source new values", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
assert.Equal(t, float32(1.234), m.PhotoLat)
|
||||
assert.Equal(t, float32(4.321), m.PhotoLng)
|
||||
assert.Equal(t, 3, m.PhotoAltitude)
|
||||
|
||||
m.SetCoordinates(5.555, 5.555, 5, SrcLocation)
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLat)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLng)
|
||||
assert.Equal(t, 5, m.PhotoAltitude)
|
||||
})
|
||||
t.Run("different source lower priority", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
assert.Equal(t, float32(1.234), m.PhotoLat)
|
||||
assert.Equal(t, float32(4.321), m.PhotoLng)
|
||||
assert.Equal(t, 3, m.PhotoAltitude)
|
||||
|
||||
m.SetCoordinates(5.555, 5.555, 5, SrcName)
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
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 equal priority", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
assert.Equal(t, float32(1.234), m.PhotoLat)
|
||||
assert.Equal(t, float32(4.321), m.PhotoLng)
|
||||
assert.Equal(t, 3, m.PhotoAltitude)
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
|
||||
m.SetCoordinates(5.555, 5.555, 5, SrcImage)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLat)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLng)
|
||||
assert.Equal(t, 5, m.PhotoAltitude)
|
||||
})
|
||||
t.Run("different source higher priority", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo21")
|
||||
assert.Equal(t, SrcEstimate, m.PlaceSrc)
|
||||
assert.Equal(t, float32(0), m.PhotoLat)
|
||||
assert.Equal(t, float32(0), m.PhotoLng)
|
||||
assert.Equal(t, 0, m.PhotoAltitude)
|
||||
|
||||
m.SetCoordinates(5.555, 5.555, 5, SrcMeta)
|
||||
assert.Equal(t, SrcMeta, m.PlaceSrc)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLat)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLng)
|
||||
assert.Equal(t, 5, m.PhotoAltitude)
|
||||
})
|
||||
t.Run("different source highest priority (manual)", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo15")
|
||||
assert.Equal(t, SrcLocation, m.PlaceSrc)
|
||||
assert.Equal(t, float32(1.234), m.PhotoLat)
|
||||
assert.Equal(t, float32(4.321), m.PhotoLng)
|
||||
assert.Equal(t, 3, m.PhotoAltitude)
|
||||
|
||||
m.SetCoordinates(5.555, 5.555, 5, SrcManual)
|
||||
assert.Equal(t, SrcManual, m.PlaceSrc)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLat)
|
||||
assert.Equal(t, float32(5.555), m.PhotoLng)
|
||||
assert.Equal(t, 5, m.PhotoAltitude)
|
||||
|
|
Loading…
Reference in a new issue