Backend: Add tests to internal/query
This commit is contained in:
parent
25da779c43
commit
e634fd97a7
5 changed files with 216 additions and 20 deletions
39
internal/query/geo_result_test.go
Normal file
39
internal/query/geo_result_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package query
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGeoResult_Lat(t *testing.T) {
|
||||
geo := GeoResult{
|
||||
ID: "123",
|
||||
PhotoLat: 7.775,
|
||||
PhotoLng: 8.775,
|
||||
PhotoUUID: "",
|
||||
PhotoTitle: "",
|
||||
PhotoFavorite: false,
|
||||
FileHash: "",
|
||||
FileWidth: 0,
|
||||
FileHeight: 0,
|
||||
TakenAt: time.Time{},
|
||||
}
|
||||
assert.Equal(t, 7.775000095367432, geo.Lat())
|
||||
}
|
||||
|
||||
func TestGeoResult_Lng(t *testing.T) {
|
||||
geo := GeoResult{
|
||||
ID: "123",
|
||||
PhotoLat: 7.775,
|
||||
PhotoLng: 8.775,
|
||||
PhotoUUID: "",
|
||||
PhotoTitle: "",
|
||||
PhotoFavorite: false,
|
||||
FileHash: "",
|
||||
FileWidth: 0,
|
||||
FileHeight: 0,
|
||||
TakenAt: time.Time{},
|
||||
}
|
||||
assert.Equal(t, 8.774999618530273, geo.Lng())
|
||||
}
|
|
@ -2,6 +2,7 @@ package query
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/form"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -12,16 +13,20 @@ func TestGeo(t *testing.T) {
|
|||
query := form.NewGeoSearch("")
|
||||
result, err := Geo(query)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(result))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.LessOrEqual(t, 5, len(result))
|
||||
})
|
||||
|
||||
t.Run("search for bridge", func(t *testing.T) {
|
||||
query := form.NewGeoSearch("Query:bridge Before:3006-01-02")
|
||||
result, err := Geo(query)
|
||||
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "Neckarbrücke", result[0].PhotoTitle)
|
||||
|
||||
})
|
||||
|
@ -30,9 +35,103 @@ func TestGeo(t *testing.T) {
|
|||
query := form.NewGeoSearch("After:2014-12-02 Before:3006-01-02")
|
||||
result, err := Geo(query)
|
||||
|
||||
assert.Nil(t, err)
|
||||
t.Log(result)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "Reunion", result[0].PhotoTitle)
|
||||
|
||||
})
|
||||
t.Run("search for review true, quality 0", func(t *testing.T) {
|
||||
f := form.GeoSearch{
|
||||
Query: "",
|
||||
Before: time.Time{},
|
||||
After: time.Time{},
|
||||
Favorite: true,
|
||||
Lat: 1.234,
|
||||
Lng: 4.321,
|
||||
S2: "",
|
||||
Olc: "",
|
||||
Dist: 0,
|
||||
Quality: 0,
|
||||
Review: true,
|
||||
}
|
||||
|
||||
result, err := Geo(f)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.LessOrEqual(t, 1, len(result))
|
||||
assert.Equal(t, "1000017", result[0].ID)
|
||||
assert.IsType(t, GeoResults{}, result)
|
||||
})
|
||||
|
||||
t.Run("search for review false, quality > 0", func(t *testing.T) {
|
||||
f := form.GeoSearch{
|
||||
Query: "",
|
||||
Before: time.Time{},
|
||||
After: time.Time{},
|
||||
Favorite: false,
|
||||
Lat: 0,
|
||||
Lng: 0,
|
||||
S2: "",
|
||||
Olc: "",
|
||||
Dist: 0,
|
||||
Quality: 3,
|
||||
Review: false,
|
||||
}
|
||||
|
||||
result, err := Geo(f)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.LessOrEqual(t, 4, len(result))
|
||||
assert.IsType(t, GeoResults{}, result)
|
||||
})
|
||||
t.Run("search for s2", func(t *testing.T) {
|
||||
f := form.GeoSearch{
|
||||
Query: "",
|
||||
Before: time.Time{},
|
||||
After: time.Time{},
|
||||
Favorite: false,
|
||||
Lat: 0,
|
||||
Lng: 0,
|
||||
S2: "85",
|
||||
Olc: "",
|
||||
Dist: 0,
|
||||
Quality: 0,
|
||||
Review: false,
|
||||
}
|
||||
|
||||
result, err := Geo(f)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Empty(t, result)
|
||||
assert.IsType(t, GeoResults{}, result)
|
||||
})
|
||||
t.Run("search for Olc", func(t *testing.T) {
|
||||
f := form.GeoSearch{
|
||||
Query: "",
|
||||
Before: time.Time{},
|
||||
After: time.Time{},
|
||||
Favorite: false,
|
||||
Lat: 0,
|
||||
Lng: 0,
|
||||
S2: "",
|
||||
Olc: "9",
|
||||
Dist: 0,
|
||||
Quality: 0,
|
||||
Review: false,
|
||||
}
|
||||
|
||||
result, err := Geo(f)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.IsType(t, GeoResults{}, result)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func TestLabelBySlug(t *testing.T) {
|
||||
t.Run("files found", func(t *testing.T) {
|
||||
t.Run("file found", func(t *testing.T) {
|
||||
label, err := LabelBySlug("flower")
|
||||
|
||||
if err != nil {
|
||||
|
@ -17,7 +17,7 @@ func TestLabelBySlug(t *testing.T) {
|
|||
assert.Equal(t, "Flower", label.LabelName)
|
||||
})
|
||||
|
||||
t.Run("no files found", func(t *testing.T) {
|
||||
t.Run("no file found", func(t *testing.T) {
|
||||
label, err := LabelBySlug("111")
|
||||
|
||||
assert.Error(t, err, "record not found")
|
||||
|
@ -26,7 +26,7 @@ func TestLabelBySlug(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLabelByUUID(t *testing.T) {
|
||||
t.Run("files found", func(t *testing.T) {
|
||||
t.Run("file found", func(t *testing.T) {
|
||||
label, err := LabelByUUID("lt9k3pw1wowuy3c5")
|
||||
|
||||
if err != nil {
|
||||
|
@ -36,7 +36,7 @@ func TestLabelByUUID(t *testing.T) {
|
|||
assert.Equal(t, "COW", label.LabelName)
|
||||
})
|
||||
|
||||
t.Run("no files found", func(t *testing.T) {
|
||||
t.Run("no file found", func(t *testing.T) {
|
||||
label, err := LabelByUUID("111")
|
||||
|
||||
assert.Error(t, err, "record not found")
|
||||
|
@ -45,7 +45,7 @@ func TestLabelByUUID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLabelThumbBySlug(t *testing.T) {
|
||||
t.Run("files found", func(t *testing.T) {
|
||||
t.Run("file found", func(t *testing.T) {
|
||||
file, err := LabelThumbBySlug("flower")
|
||||
|
||||
if err != nil {
|
||||
|
@ -55,7 +55,7 @@ func TestLabelThumbBySlug(t *testing.T) {
|
|||
assert.Equal(t, "exampleFileName.jpg", file.FileName)
|
||||
})
|
||||
|
||||
t.Run("no files found", func(t *testing.T) {
|
||||
t.Run("no file found", func(t *testing.T) {
|
||||
file, err := LabelThumbBySlug("cow")
|
||||
|
||||
assert.Error(t, err, "record not found")
|
||||
|
@ -64,7 +64,7 @@ func TestLabelThumbBySlug(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLabelThumbByUUID(t *testing.T) {
|
||||
t.Run("files found", func(t *testing.T) {
|
||||
t.Run("file found", func(t *testing.T) {
|
||||
file, err := LabelThumbByUUID("lt9k3pw1wowuy3c4")
|
||||
|
||||
if err != nil {
|
||||
|
@ -74,10 +74,25 @@ func TestLabelThumbByUUID(t *testing.T) {
|
|||
assert.Equal(t, "exampleFileName.jpg", file.FileName)
|
||||
})
|
||||
|
||||
t.Run("no files found", func(t *testing.T) {
|
||||
t.Run("no file found", func(t *testing.T) {
|
||||
file, err := LabelThumbByUUID("14")
|
||||
|
||||
assert.Error(t, err, "record not found")
|
||||
t.Log(file)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPhotoLabel(t *testing.T) {
|
||||
t.Run("photo label found", func(t *testing.T) {
|
||||
r, err := PhotoLabel(uint(1000000), uint(1000001))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, 38, r.Uncertainty)
|
||||
})
|
||||
t.Run("no photo label found", func(t *testing.T) {
|
||||
r, err := PhotoLabel(uint(1000000), uint(1000003))
|
||||
assert.Equal(t, "record not found", err.Error())
|
||||
t.Log(r)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package query
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/form"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLabels(t *testing.T) {
|
||||
|
@ -37,7 +36,7 @@ func TestLabels(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("search for favorites", func(t *testing.T) {
|
||||
query := form.NewLabelSearch("Favorites:true")
|
||||
query := form.NewLabelSearch("Favorites:true Count:15")
|
||||
result, err := Labels(query)
|
||||
|
||||
if err != nil {
|
||||
|
@ -70,6 +69,7 @@ func TestLabels(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Log(result)
|
||||
assert.LessOrEqual(t, 3, len(result))
|
||||
})
|
||||
|
||||
|
@ -80,4 +80,26 @@ func TestLabels(t *testing.T) {
|
|||
assert.Error(t, err, "unknown filter")
|
||||
assert.Empty(t, result)
|
||||
})
|
||||
|
||||
t.Run("search for ID", func(t *testing.T) {
|
||||
f := form.LabelSearch{
|
||||
Query: "",
|
||||
ID: "lt9k3pw1wowuy3c4",
|
||||
Slug: "",
|
||||
Name: "",
|
||||
All: false,
|
||||
Favorites: false,
|
||||
Count: 0,
|
||||
Offset: 0,
|
||||
Order: "",
|
||||
}
|
||||
|
||||
result, err := Labels(f)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "cake", result[0].LabelSlug)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ import (
|
|||
func TestPhotoByID(t *testing.T) {
|
||||
t.Run("photo found", func(t *testing.T) {
|
||||
result, err := PhotoByID(1000000)
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, 2790, result.PhotoYear)
|
||||
})
|
||||
|
||||
|
@ -23,7 +25,9 @@ func TestPhotoByID(t *testing.T) {
|
|||
func TestPhotoByUUID(t *testing.T) {
|
||||
t.Run("photo found", func(t *testing.T) {
|
||||
result, err := PhotoByUUID("pt9jtdre2lvl0y12")
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "Reunion", result.PhotoTitle)
|
||||
})
|
||||
|
||||
|
@ -37,7 +41,9 @@ func TestPhotoByUUID(t *testing.T) {
|
|||
func TestPreloadPhotoByUUID(t *testing.T) {
|
||||
t.Run("photo found", func(t *testing.T) {
|
||||
result, err := PreloadPhotoByUUID("pt9jtdre2lvl0y12")
|
||||
assert.Nil(t, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, "Reunion", result.PhotoTitle)
|
||||
})
|
||||
|
||||
|
@ -47,3 +53,18 @@ func TestPreloadPhotoByUUID(t *testing.T) {
|
|||
t.Log(result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMissingPhotos(t *testing.T) {
|
||||
r, err := MissingPhotos(15, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.LessOrEqual(t, 1, len(r))
|
||||
}
|
||||
|
||||
func TestResetPhotosQuality(t *testing.T) {
|
||||
err := ResetPhotosQuality()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue