2020-01-11 01:59:43 +01:00
|
|
|
// +build osm
|
|
|
|
|
2019-12-19 17:17:13 +01:00
|
|
|
package osm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-12-31 07:16:11 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/s2"
|
2019-12-19 17:17:13 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFindLocation(t *testing.T) {
|
2019-12-31 07:16:11 +01:00
|
|
|
t.Run("Fernsehturm Berlin 1", func(t *testing.T) {
|
2019-12-19 17:17:13 +01:00
|
|
|
lat := 52.5208
|
2019-12-20 11:30:58 +01:00
|
|
|
lng := 13.40953
|
2020-01-02 04:08:33 +01:00
|
|
|
id := s2.Token(lat, lng)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
2019-12-31 07:16:11 +01:00
|
|
|
l, err := FindLocation(id)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.False(t, l.Cached)
|
2019-12-27 05:18:52 +01:00
|
|
|
assert.Equal(t, "Fernsehturm Berlin", l.LocName)
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.Equal(t, "10178", l.Address.Postcode)
|
|
|
|
assert.Equal(t, "Berlin", l.Address.State)
|
|
|
|
assert.Equal(t, "de", l.Address.CountryCode)
|
|
|
|
assert.Equal(t, "Germany", l.Address.Country)
|
|
|
|
|
|
|
|
l.PlaceID = 123456
|
|
|
|
|
|
|
|
assert.Equal(t, 123456, l.PlaceID)
|
|
|
|
|
2019-12-31 07:16:11 +01:00
|
|
|
cached, err := FindLocation(id)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, cached.Cached)
|
2019-12-27 05:18:52 +01:00
|
|
|
assert.Equal(t, l.LocName, cached.LocName)
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.Equal(t, l.Address.Postcode, cached.Address.Postcode)
|
|
|
|
assert.Equal(t, l.Address.State, cached.Address.State)
|
|
|
|
assert.Equal(t, l.Address.CountryCode, cached.Address.CountryCode)
|
|
|
|
assert.Equal(t, l.Address.Country, cached.Address.Country)
|
|
|
|
})
|
|
|
|
|
2019-12-31 07:16:11 +01:00
|
|
|
t.Run("Fernsehturm Berlin 2", func(t *testing.T) {
|
2019-12-19 17:17:13 +01:00
|
|
|
lat := 52.52057
|
2019-12-20 11:30:58 +01:00
|
|
|
lng := 13.40889
|
2020-01-02 04:08:33 +01:00
|
|
|
id := s2.Token(lat, lng)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
2019-12-31 07:16:11 +01:00
|
|
|
l, err := FindLocation(id)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.False(t, l.Cached)
|
2020-01-11 01:59:43 +01:00
|
|
|
assert.Equal(t, "Menschen Museum", l.LocName)
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.Equal(t, "10178", l.Address.Postcode)
|
|
|
|
assert.Equal(t, "Berlin", l.Address.State)
|
|
|
|
assert.Equal(t, "de", l.Address.CountryCode)
|
|
|
|
assert.Equal(t, "Germany", l.Address.Country)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("No Location", func(t *testing.T) {
|
|
|
|
lat := 0.0
|
2019-12-20 11:30:58 +01:00
|
|
|
lng := 0.0
|
2020-01-02 04:08:33 +01:00
|
|
|
id := s2.Token(lat, lng)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
2019-12-31 07:16:11 +01:00
|
|
|
l, err := FindLocation(id)
|
2019-12-19 17:17:13 +01:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("err should not be nil")
|
|
|
|
}
|
|
|
|
|
2019-12-31 07:16:11 +01:00
|
|
|
assert.Equal(t, "osm: invalid location id", err.Error())
|
2019-12-19 17:17:13 +01:00
|
|
|
assert.False(t, l.Cached)
|
|
|
|
})
|
|
|
|
}
|
2019-12-22 21:38:55 +01:00
|
|
|
|
|
|
|
func TestOSM_State(t *testing.T) {
|
|
|
|
t.Run("Berlin", func(t *testing.T) {
|
|
|
|
|
|
|
|
a := Address{CountryCode: "de", City: "Berlin", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln"}
|
2019-12-31 07:16:11 +01:00
|
|
|
l := &Location{LocCategory: "natural", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
2019-12-22 21:38:55 +01:00
|
|
|
assert.Equal(t, "Berlin", l.State())
|
|
|
|
})
|
|
|
|
}
|
2019-12-28 20:39:51 +01:00
|
|
|
|
2019-12-22 21:38:55 +01:00
|
|
|
func TestOSM_Suburb(t *testing.T) {
|
|
|
|
t.Run("Neukölln", func(t *testing.T) {
|
|
|
|
|
|
|
|
a := Address{CountryCode: "de", City: "Berlin", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln"}
|
2019-12-31 07:16:11 +01:00
|
|
|
l := &Location{LocCategory: "natural", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
2019-12-22 21:38:55 +01:00
|
|
|
assert.Equal(t, "Neukölln", l.Suburb())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOSM_CountryCode(t *testing.T) {
|
|
|
|
t.Run("de", func(t *testing.T) {
|
|
|
|
|
|
|
|
a := Address{CountryCode: "de", City: "Berlin", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln"}
|
2019-12-31 07:16:11 +01:00
|
|
|
l := &Location{LocCategory: "natural", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
2019-12-22 21:38:55 +01:00
|
|
|
assert.Equal(t, "de", l.CountryCode())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOSM_Keywords(t *testing.T) {
|
|
|
|
t.Run("cat", func(t *testing.T) {
|
|
|
|
|
|
|
|
a := Address{CountryCode: "de", City: "Berlin", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln"}
|
2019-12-31 07:16:11 +01:00
|
|
|
l := &Location{LocCategory: "natural", LocName: "Nice title", LocType: "hill", LocDisplayName: "cat", Address: a}
|
2019-12-22 21:38:55 +01:00
|
|
|
assert.Equal(t, []string{"cat"}, l.Keywords())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOSM_Source(t *testing.T) {
|
|
|
|
|
|
|
|
a := Address{CountryCode: "de", City: "Berlin", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln"}
|
2019-12-31 07:16:11 +01:00
|
|
|
l := &Location{LocCategory: "natural", LocName: "Nice title", LocType: "hill", LocDisplayName: "cat", Address: a}
|
2019-12-22 21:38:55 +01:00
|
|
|
assert.Equal(t, "osm", l.Source())
|
|
|
|
}
|