2020-12-30 11:11:58 +01:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2021-02-25 15:17:47 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
2021-04-19 13:48:46 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-12-30 11:11:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPhoto_EstimateCountry(t *testing.T) {
|
|
|
|
t.Run("uk", func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m := Photo{CameraID: 2, PhotoName: "20200102_194030_9EFA9E5E", PhotoPath: "2000/05", OriginalName: "flickr import/changing-of-the-guard--buckingham-palace_7925318070_o.jpg"}
|
2020-12-30 11:11:58 +01:00
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, "gb", m.CountryCode())
|
|
|
|
assert.Equal(t, "United Kingdom", m.CountryName())
|
|
|
|
})
|
2021-08-19 21:12:38 +02:00
|
|
|
t.Run(UnknownID, func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m := Photo{CameraID: 2, PhotoName: "20200102_194030_ADADADAD", PhotoPath: "2020/Berlin", OriginalName: "Zimmermannstrasse.jpg"}
|
2020-12-30 11:11:58 +01:00
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, "de", m.CountryCode())
|
|
|
|
assert.Equal(t, "Germany", m.CountryName())
|
|
|
|
})
|
|
|
|
t.Run("de", func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m := Photo{CameraID: 2, PhotoName: "Brauhaus", PhotoPath: "2020/Bayern", OriginalName: "München.jpg"}
|
2020-12-30 11:11:58 +01:00
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, "de", m.CountryCode())
|
|
|
|
assert.Equal(t, "Germany", m.CountryName())
|
|
|
|
})
|
|
|
|
t.Run("ca", func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m := Photo{CameraID: 2, PhotoTitle: "Port Lands / Gardiner Expressway / Toronto", PhotoPath: "2012/09", PhotoName: "20120910_231851_CA06E1AD", OriginalName: "demo/Toronto/port-lands--gardiner-expressway--toronto_7999515645_o.jpg"}
|
2020-12-30 11:11:58 +01:00
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, "ca", m.CountryCode())
|
|
|
|
assert.Equal(t, "Canada", m.CountryName())
|
|
|
|
})
|
|
|
|
t.Run("photo has latlng", func(t *testing.T) {
|
2021-02-11 19:48:33 +01:00
|
|
|
m := Photo{
|
|
|
|
PhotoTitle: "Port Lands / Gardiner Expressway / Toronto",
|
|
|
|
PhotoLat: 13.333,
|
|
|
|
PhotoLng: 40.998,
|
2021-08-19 21:12:38 +02:00
|
|
|
PhotoCountry: UnknownID,
|
2021-02-11 19:48:33 +01:00
|
|
|
CellID: "161437aab90c",
|
|
|
|
PhotoName: "20120910_231851_CA06E1AD",
|
|
|
|
OriginalName: "demo/Toronto/port-lands--gardiner-expressway--toronto_7999515645_o.jpg",
|
|
|
|
}
|
2020-12-30 11:11:58 +01:00
|
|
|
m.EstimateCountry()
|
2021-08-19 21:12:38 +02:00
|
|
|
assert.Equal(t, UnknownID, m.CountryCode())
|
2020-12-30 11:11:58 +01:00
|
|
|
assert.Equal(t, "Unknown", m.CountryName())
|
|
|
|
})
|
2021-02-25 15:17:47 +01:00
|
|
|
}
|
|
|
|
|
2021-11-22 18:18:41 +01:00
|
|
|
func TestPhoto_EstimateLocation(t *testing.T) {
|
2021-02-25 15:17:47 +01:00
|
|
|
t.Run("photo already has location", func(t *testing.T) {
|
|
|
|
p := &Place{ID: "1000000001", PlaceCountry: "mx"}
|
2021-11-24 21:06:30 +01:00
|
|
|
m := Photo{CameraID: 2, TakenSrc: SrcMeta, PhotoName: "PhotoWithLocation", OriginalName: "demo/xyz.jpg", Place: p, PlaceID: "1000000001", PlaceSrc: SrcManual, PhotoCountry: "mx"}
|
2021-02-25 15:17:47 +01:00
|
|
|
assert.True(t, m.HasPlace())
|
|
|
|
assert.Equal(t, "mx", m.CountryCode())
|
|
|
|
assert.Equal(t, "Mexico", m.CountryName())
|
2021-11-22 18:18:41 +01:00
|
|
|
m.EstimateLocation(true)
|
2021-02-25 15:17:47 +01:00
|
|
|
assert.Equal(t, "mx", m.CountryCode())
|
|
|
|
assert.Equal(t, "Mexico", m.CountryName())
|
|
|
|
})
|
2021-11-18 02:23:25 +01:00
|
|
|
t.Run("RecentlyEstimates", func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m2 := Photo{CameraID: 2, TakenSrc: SrcMeta, PhotoName: "PhotoWithoutLocation", OriginalName: "demo/xyy.jpg", EstimatedAt: TimePointer(), TakenAt: time.Date(2016, 11, 11, 8, 7, 18, 0, time.UTC)}
|
2021-11-18 02:23:25 +01:00
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
2021-11-22 18:18:41 +01:00
|
|
|
m2.EstimateLocation(false)
|
2021-11-18 02:23:25 +01:00
|
|
|
assert.Equal(t, "zz", m2.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m2.CountryName())
|
|
|
|
assert.Equal(t, SrcAuto, m2.PlaceSrc)
|
|
|
|
})
|
2023-03-03 03:39:25 +01:00
|
|
|
t.Run("NotRecentlyEstimated", func(t *testing.T) {
|
|
|
|
estimateTime := TimeStamp().Add(-1 * (MetadataEstimateInterval + 2*time.Hour))
|
|
|
|
m2 := Photo{
|
|
|
|
CameraID: 2,
|
|
|
|
TakenSrc: SrcMeta,
|
|
|
|
PhotoName: "PhotoWithoutLocation",
|
|
|
|
OriginalName: "demo/xyy.jpg",
|
|
|
|
EstimatedAt: &estimateTime,
|
|
|
|
TakenAt: time.Date(2016, 11, 11, 8, 7, 18, 0, time.UTC)}
|
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
|
|
|
m2.EstimateLocation(false)
|
|
|
|
assert.Equal(t, "mx", m2.CountryCode())
|
|
|
|
assert.Equal(t, "Mexico", m2.CountryName())
|
|
|
|
assert.Equal(t, SrcEstimate, m2.PlaceSrc)
|
|
|
|
})
|
2021-11-18 02:23:25 +01:00
|
|
|
t.Run("ForceEstimate", func(t *testing.T) {
|
2021-11-22 18:18:41 +01:00
|
|
|
m2 := Photo{
|
2021-11-24 21:06:30 +01:00
|
|
|
CameraID: 2,
|
2021-11-22 18:18:41 +01:00
|
|
|
TakenSrc: SrcMeta,
|
|
|
|
PhotoName: "PhotoWithoutLocation",
|
|
|
|
OriginalName: "demo/xyy.jpg",
|
|
|
|
EstimatedAt: TimePointer(),
|
|
|
|
TakenAt: time.Date(2016, 11, 11, 8, 7, 18, 0, time.UTC)}
|
2021-11-18 02:23:25 +01:00
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
2021-11-22 18:18:41 +01:00
|
|
|
m2.EstimateLocation(true)
|
2021-11-18 02:23:25 +01:00
|
|
|
assert.Equal(t, "mx", m2.CountryCode())
|
|
|
|
assert.Equal(t, "Mexico", m2.CountryName())
|
|
|
|
assert.Equal(t, SrcEstimate, m2.PlaceSrc)
|
|
|
|
})
|
2021-02-25 15:17:47 +01:00
|
|
|
t.Run("recent photo has place", func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m2 := Photo{CameraID: 2, TakenSrc: SrcMeta, PhotoName: "PhotoWithoutLocation", OriginalName: "demo/xyy.jpg", TakenAt: time.Date(2016, 11, 11, 8, 7, 18, 0, time.UTC)}
|
2021-08-19 21:12:38 +02:00
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
2021-11-22 18:18:41 +01:00
|
|
|
m2.EstimateLocation(false)
|
2021-02-25 15:17:47 +01:00
|
|
|
assert.Equal(t, "mx", m2.CountryCode())
|
|
|
|
assert.Equal(t, "Mexico", m2.CountryName())
|
|
|
|
assert.Equal(t, SrcEstimate, m2.PlaceSrc)
|
|
|
|
})
|
2021-11-20 16:36:34 +01:00
|
|
|
t.Run("SrcAuto", func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m2 := Photo{CameraID: 2, TakenSrc: SrcAuto, PhotoName: "PhotoWithoutLocation", OriginalName: "demo/xyy.jpg", TakenAt: time.Date(2016, 11, 11, 8, 7, 18, 0, time.UTC)}
|
2021-11-20 16:36:34 +01:00
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
2021-11-22 18:18:41 +01:00
|
|
|
m2.EstimateLocation(false)
|
2021-11-20 16:36:34 +01:00
|
|
|
assert.Equal(t, "zz", m2.CountryCode())
|
|
|
|
assert.Equal(t, "Unknown", m2.CountryName())
|
|
|
|
assert.Equal(t, "zz", m2.PlaceID)
|
2021-11-23 19:23:10 +01:00
|
|
|
assert.Equal(t, SrcAuto, m2.PlaceSrc)
|
2021-11-20 16:36:34 +01:00
|
|
|
})
|
2021-02-25 15:17:47 +01:00
|
|
|
t.Run("cant estimate - out of scope", func(t *testing.T) {
|
2021-11-24 21:06:30 +01:00
|
|
|
m2 := Photo{CameraID: 2, TakenSrc: SrcMeta, PhotoName: "PhotoWithoutLocation", OriginalName: "demo/xyy.jpg", TakenAt: time.Date(2016, 11, 13, 8, 7, 18, 0, time.UTC)}
|
2021-08-19 21:12:38 +02:00
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
2021-11-22 18:18:41 +01:00
|
|
|
m2.EstimateLocation(true)
|
2021-08-19 21:12:38 +02:00
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
2021-02-25 15:17:47 +01:00
|
|
|
})
|
|
|
|
/*t.Run("recent photo has country", func(t *testing.T) {
|
|
|
|
m2 := Photo{PhotoName: "PhotoWithoutLocation", OriginalName: "demo/zzz.jpg", TakenAt: time.Date(2001, 1, 1, 7, 20, 0, 0, time.UTC)}
|
2021-08-19 21:12:38 +02:00
|
|
|
assert.Equal(t, UnknownID, m2.CountryCode())
|
2021-11-22 18:18:41 +01:00
|
|
|
m2.EstimateLocation()
|
2021-02-25 15:17:47 +01:00
|
|
|
assert.Equal(t, "mx", m2.CountryCode())
|
|
|
|
assert.Equal(t, "Mexico", m2.CountryName())
|
|
|
|
assert.Equal(t, SrcEstimate, m2.PlaceSrc)
|
|
|
|
})*/
|
2020-12-30 11:11:58 +01:00
|
|
|
}
|