mirror of
https://github.com/photoprism/photoprism.git
synced 2025-11-03 02:53:36 +08:00
Tests: Add tests for internal/query
This commit is contained in:
@@ -563,6 +563,43 @@ var FileFixtures = map[string]File{
|
|||||||
UpdatedIn: 0,
|
UpdatedIn: 0,
|
||||||
DeletedAt: nil,
|
DeletedAt: nil,
|
||||||
},
|
},
|
||||||
|
"Photo25.jpg": {
|
||||||
|
ID: 1000020,
|
||||||
|
Photo: PhotoFixtures.Pointer("Photo25"),
|
||||||
|
PhotoID: PhotoFixtures.Pointer("Photo25").ID,
|
||||||
|
PhotoUID: PhotoFixtures.Pointer("Photo25").PhotoUID,
|
||||||
|
FileUID: "ft2es49qhhinlplk",
|
||||||
|
FileName: "Photo25.jpg",
|
||||||
|
FileRoot: RootOriginals,
|
||||||
|
OriginalName: "Photo25.jpg",
|
||||||
|
FileHash: "pcad9a68fa6acc5c5ba965adf6ec465ca42fd887",
|
||||||
|
ModTime: time.Date(2008, 2, 6, 2, 6, 51, 0, time.UTC).Unix(),
|
||||||
|
FileSize: 921831,
|
||||||
|
FileType: "jpg",
|
||||||
|
FileMime: "image/jpg",
|
||||||
|
FilePrimary: true,
|
||||||
|
FileSidecar: false,
|
||||||
|
FileVideo: false,
|
||||||
|
FileMissing: false,
|
||||||
|
FilePortrait: false,
|
||||||
|
FileWidth: 1200,
|
||||||
|
FileHeight: 1600,
|
||||||
|
FileOrientation: 6,
|
||||||
|
FileAspectRatio: 0.75,
|
||||||
|
FileMainColor: "magenta",
|
||||||
|
FileColors: "225221C1E",
|
||||||
|
FileLuminance: "DC42844C8",
|
||||||
|
FileDiff: 986,
|
||||||
|
FileChroma: 32,
|
||||||
|
FileError: "",
|
||||||
|
Share: []FileShare{},
|
||||||
|
Sync: []FileSync{},
|
||||||
|
CreatedAt: time.Date(2019, 1, 1, 2, 6, 51, 0, time.UTC),
|
||||||
|
CreatedIn: 2,
|
||||||
|
UpdatedAt: time.Date(2020, 3, 28, 14, 6, 0, 0, time.UTC),
|
||||||
|
UpdatedIn: 0,
|
||||||
|
DeletedAt: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var FileFixturesExampleJPG = FileFixtures["exampleFileName.jpg"]
|
var FileFixturesExampleJPG = FileFixtures["exampleFileName.jpg"]
|
||||||
|
|||||||
@@ -1253,6 +1253,59 @@ var PhotoFixtures = PhotoMap{
|
|||||||
EditedAt: nil,
|
EditedAt: nil,
|
||||||
DeletedAt: nil,
|
DeletedAt: nil,
|
||||||
},
|
},
|
||||||
|
"Photo25": {
|
||||||
|
ID: 1000025,
|
||||||
|
PhotoUID: "pt9jtdre2lvl0y45",
|
||||||
|
TakenAt: time.Date(2007, 1, 11, 9, 7, 18, 0, time.UTC),
|
||||||
|
TakenAtLocal: time.Date(2007, 1, 11, 9, 7, 18, 0, time.UTC),
|
||||||
|
TakenSrc: SrcMeta,
|
||||||
|
PhotoTitle: "photowitheditedatdate",
|
||||||
|
TitleSrc: "",
|
||||||
|
PhotoPath: "2007/christmas",
|
||||||
|
PhotoName: "PhotoWithEditedAt",
|
||||||
|
OriginalName: "OriginalPhotoWithEditedAt",
|
||||||
|
PhotoQuality: 5,
|
||||||
|
PhotoResolution: 0,
|
||||||
|
PhotoPanorama: true,
|
||||||
|
PhotoStack: IsUnstacked,
|
||||||
|
PhotoFavorite: true,
|
||||||
|
PhotoPrivate: false,
|
||||||
|
PhotoType: "image",
|
||||||
|
PhotoLat: 1.234,
|
||||||
|
PhotoLng: 4.321,
|
||||||
|
PhotoAltitude: 3,
|
||||||
|
PhotoIso: 0,
|
||||||
|
PhotoFocalLength: 0,
|
||||||
|
PhotoFNumber: 0,
|
||||||
|
PhotoExposure: "",
|
||||||
|
CameraSerial: "",
|
||||||
|
CameraSrc: "",
|
||||||
|
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,
|
||||||
|
Cell: CellFixtures.Pointer("mexico"),
|
||||||
|
CellID: CellFixtures.Pointer("mexico").ID,
|
||||||
|
PlaceSrc: "location",
|
||||||
|
Place: PlaceFixtures.Pointer("mexico"),
|
||||||
|
PlaceID: PlaceFixtures.Pointer("mexico").ID,
|
||||||
|
TimeZone: "",
|
||||||
|
PhotoCountry: PlaceFixtures.Pointer("mexico").CountryCode(),
|
||||||
|
PhotoYear: 0,
|
||||||
|
PhotoMonth: 0,
|
||||||
|
Details: DetailsFixtures.Pointer("lake", 1000015),
|
||||||
|
DescriptionSrc: "location",
|
||||||
|
Keywords: []Keyword{},
|
||||||
|
Albums: []Album{},
|
||||||
|
Files: []File{},
|
||||||
|
Labels: []PhotoLabel{
|
||||||
|
LabelFixtures.PhotoLabel(10000018, "landscape", 20, "image"),
|
||||||
|
LabelFixtures.PhotoLabel(10000018, "likeLabel", 20, "image")},
|
||||||
|
CreatedAt: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
|
UpdatedAt: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
|
EditedAt: &editTime,
|
||||||
|
DeletedAt: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePhotoFixtures inserts known entities into the database for testing.
|
// CreatePhotoFixtures inserts known entities into the database for testing.
|
||||||
|
|||||||
@@ -230,3 +230,14 @@ func TestAlbumEntryFound(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetAlbums(t *testing.T) {
|
||||||
|
t.Run("success", func(t *testing.T) {
|
||||||
|
r, err := GetAlbums(0, 3)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, 3, len(r))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,13 +1,26 @@
|
|||||||
package query
|
package query
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TODO find duplicates
|
||||||
func TestDuplicates(t *testing.T) {
|
func TestDuplicates(t *testing.T) {
|
||||||
if files, err := Duplicates(10, 0, ""); err != nil {
|
t.Run("success", func(t *testing.T) {
|
||||||
t.Fatal(err)
|
if files, err := Duplicates(10, 0, ""); err != nil {
|
||||||
} else if files == nil {
|
t.Fatal(err)
|
||||||
t.Fatal("files must not be nil")
|
} else if files == nil {
|
||||||
}
|
t.Fatal("files must not be nil")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("pathname not empty", func(t *testing.T) {
|
||||||
|
files, err := Duplicates(10, 0, "/holiday/sea.jpg")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Empty(t, files)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TODO test non empty case
|
||||||
func TestErrors(t *testing.T) {
|
func TestErrors(t *testing.T) {
|
||||||
t.Run("not existing", func(t *testing.T) {
|
t.Run("not existing", func(t *testing.T) {
|
||||||
errors, err := Errors(1000, 0, "notexistingErrorString")
|
errors, err := Errors(1000, 0, "notexistingErrorString")
|
||||||
@@ -15,14 +16,14 @@ func TestErrors(t *testing.T) {
|
|||||||
assert.Empty(t, errors)
|
assert.Empty(t, errors)
|
||||||
})
|
})
|
||||||
t.Run("error", func(t *testing.T) {
|
t.Run("error", func(t *testing.T) {
|
||||||
errors, err := Errors(1000, 0, "error")
|
errors, err := Errors(1000, 0, "errors")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Empty(t, errors)
|
assert.Empty(t, errors)
|
||||||
})
|
})
|
||||||
t.Run("warning", func(t *testing.T) {
|
t.Run("warning", func(t *testing.T) {
|
||||||
errors, err := Errors(1000, 0, "warning")
|
errors, err := Errors(1000, 0, "warnings")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,12 @@ func TestFilesByUID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Equal(t, 0, len(files))
|
assert.Equal(t, 0, len(files))
|
||||||
})
|
})
|
||||||
|
t.Run("error", func(t *testing.T) {
|
||||||
|
files, err := FilesByUID([]string{"ft8es39w45bnlxxx"}, -100, 0)
|
||||||
|
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, 0, len(files))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileByPhotoUID(t *testing.T) {
|
func TestFileByPhotoUID(t *testing.T) {
|
||||||
@@ -232,3 +238,25 @@ func TestFileHashes(t *testing.T) {
|
|||||||
|
|
||||||
t.Logf("FILE HASHES: %#v", result)
|
t.Logf("FILE HASHES: %#v", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenameFile(t *testing.T) {
|
||||||
|
t.Run("empty name", func(t *testing.T) {
|
||||||
|
err := RenameFile("xxx", "", "yyy", "yyy")
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("success", func(t *testing.T) {
|
||||||
|
assert.Equal(t, "exampleXmpFile.xmp", entity.FileFixturesExampleXMP.FileName)
|
||||||
|
assert.Equal(t, "/", entity.FileFixturesExampleXMP.FileRoot)
|
||||||
|
err := RenameFile("/", "exampleXmpFile.xmp", "test-root", "yyy.jpg")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
//TODO how to assert?
|
||||||
|
//assert.Equal(t, "", entity.FileFixturesExampleXMP.FileName)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -124,6 +124,18 @@ func TestMoment_Title(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, "de", moment.Title())
|
assert.Equal(t, "de", moment.Title())
|
||||||
})
|
})
|
||||||
|
t.Run("country name", func(t *testing.T) {
|
||||||
|
moment := Moment{
|
||||||
|
Label: "",
|
||||||
|
Country: "de",
|
||||||
|
State: "",
|
||||||
|
Year: 1800,
|
||||||
|
Month: 0,
|
||||||
|
PhotoCount: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, "Germany", moment.Title())
|
||||||
|
})
|
||||||
t.Run("country and year", func(t *testing.T) {
|
t.Run("country and year", func(t *testing.T) {
|
||||||
moment := Moment{
|
moment := Moment{
|
||||||
Label: "",
|
Label: "",
|
||||||
|
|||||||
@@ -388,4 +388,68 @@ func TestPhotosResult_ShareFileName(t *testing.T) {
|
|||||||
r := result1.ShareBase(0)
|
r := result1.ShareBase(0)
|
||||||
assert.Contains(t, r, "20151111-090718-uid123")
|
assert.Contains(t, r, "20151111-090718-uid123")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("seq > 0", func(t *testing.T) {
|
||||||
|
result1 := PhotoResult{
|
||||||
|
ID: 111111,
|
||||||
|
CreatedAt: time.Time{},
|
||||||
|
UpdatedAt: time.Time{},
|
||||||
|
DeletedAt: time.Time{},
|
||||||
|
TakenAt: time.Date(2022, 11, 11, 9, 7, 18, 0, time.UTC),
|
||||||
|
TakenAtLocal: time.Date(2022, 11, 11, 9, 7, 18, 0, time.UTC),
|
||||||
|
TakenSrc: "",
|
||||||
|
TimeZone: "",
|
||||||
|
PhotoUID: "uid123",
|
||||||
|
PhotoPath: "",
|
||||||
|
PhotoName: "",
|
||||||
|
PhotoTitle: "PhotoTitle123",
|
||||||
|
PhotoYear: 0,
|
||||||
|
PhotoMonth: 0,
|
||||||
|
PhotoCountry: "",
|
||||||
|
PhotoFavorite: false,
|
||||||
|
PhotoPrivate: false,
|
||||||
|
PhotoLat: 0,
|
||||||
|
PhotoLng: 0,
|
||||||
|
PhotoAltitude: 0,
|
||||||
|
PhotoIso: 0,
|
||||||
|
PhotoFocalLength: 0,
|
||||||
|
PhotoFNumber: 0,
|
||||||
|
PhotoExposure: "",
|
||||||
|
PhotoQuality: 0,
|
||||||
|
PhotoResolution: 0,
|
||||||
|
Merged: false,
|
||||||
|
CameraID: 0,
|
||||||
|
CameraModel: "",
|
||||||
|
CameraMake: "",
|
||||||
|
LensID: 0,
|
||||||
|
LensModel: "",
|
||||||
|
LensMake: "",
|
||||||
|
CellID: "",
|
||||||
|
PlaceID: "",
|
||||||
|
PlaceLabel: "",
|
||||||
|
PlaceCity: "",
|
||||||
|
PlaceState: "",
|
||||||
|
PlaceCountry: "",
|
||||||
|
FileID: 0,
|
||||||
|
FileUID: "",
|
||||||
|
FilePrimary: false,
|
||||||
|
FileMissing: false,
|
||||||
|
FileName: "",
|
||||||
|
FileHash: "",
|
||||||
|
FileType: "",
|
||||||
|
FileMime: "",
|
||||||
|
FileWidth: 0,
|
||||||
|
FileHeight: 0,
|
||||||
|
FileOrientation: 0,
|
||||||
|
FileAspectRatio: 0,
|
||||||
|
FileColors: "",
|
||||||
|
FileChroma: 0,
|
||||||
|
FileLuminance: "",
|
||||||
|
FileDiff: 0,
|
||||||
|
Files: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
r := result1.ShareBase(3)
|
||||||
|
assert.Contains(t, r, "20221111-090718-Phototitle123 (3)")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -629,7 +629,7 @@ func TestPhotoSearch(t *testing.T) {
|
|||||||
f.Original = "xxyy"
|
f.Original = "xxyy"
|
||||||
f.Path = "/xxx|xxx"
|
f.Path = "/xxx|xxx"
|
||||||
f.Type = "mp4"
|
f.Type = "mp4"
|
||||||
f.Stack = true
|
f.Stackable = true
|
||||||
f.Unsorted = true
|
f.Unsorted = true
|
||||||
f.Filter = ""
|
f.Filter = ""
|
||||||
f.Order = entity.SortOrderAdded
|
f.Order = entity.SortOrderAdded
|
||||||
@@ -644,4 +644,92 @@ func TestPhotoSearch(t *testing.T) {
|
|||||||
|
|
||||||
assert.IsType(t, PhotoResults{}, photos)
|
assert.IsType(t, PhotoResults{}, photos)
|
||||||
})
|
})
|
||||||
|
t.Run("search all recently edited", func(t *testing.T) {
|
||||||
|
var frm form.PhotoSearch
|
||||||
|
|
||||||
|
frm.Query = ""
|
||||||
|
frm.Count = 10
|
||||||
|
frm.Offset = 0
|
||||||
|
frm.Order = entity.SortOrderEdited
|
||||||
|
|
||||||
|
photos, _, err := PhotoSearch(frm)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.GreaterOrEqual(t, len(photos), 1)
|
||||||
|
|
||||||
|
for _, r := range photos {
|
||||||
|
assert.IsType(t, PhotoResult{}, r)
|
||||||
|
assert.NotEmpty(t, r.ID)
|
||||||
|
assert.NotEmpty(t, r.CameraID)
|
||||||
|
assert.NotEmpty(t, r.LensID)
|
||||||
|
|
||||||
|
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
|
||||||
|
assert.Equal(t, fix.PhotoName, r.PhotoName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("search unstacked panoramas", func(t *testing.T) {
|
||||||
|
var frm form.PhotoSearch
|
||||||
|
|
||||||
|
frm.Query = ""
|
||||||
|
frm.Count = 10
|
||||||
|
frm.Offset = 0
|
||||||
|
frm.Panorama = true
|
||||||
|
frm.Stackable = false
|
||||||
|
frm.Unstacked = true
|
||||||
|
|
||||||
|
photos, _, err := PhotoSearch(frm)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.GreaterOrEqual(t, len(photos), 1)
|
||||||
|
|
||||||
|
for _, r := range photos {
|
||||||
|
assert.IsType(t, PhotoResult{}, r)
|
||||||
|
assert.NotEmpty(t, r.ID)
|
||||||
|
assert.NotEmpty(t, r.CameraID)
|
||||||
|
assert.NotEmpty(t, r.LensID)
|
||||||
|
|
||||||
|
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
|
||||||
|
assert.Equal(t, fix.PhotoName, r.PhotoName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("Or search", func(t *testing.T) {
|
||||||
|
var frm form.PhotoSearch
|
||||||
|
|
||||||
|
frm.Query = ""
|
||||||
|
frm.Count = 10
|
||||||
|
frm.Offset = 0
|
||||||
|
frm.Name = "xxx|PhotoWithEditedAt"
|
||||||
|
frm.Filename = "xxx|Photo25.jpg"
|
||||||
|
frm.Original = "xxx|OriginalPhotoWithEditedAt"
|
||||||
|
frm.Title = "xxx|photowitheditedatdate"
|
||||||
|
frm.Hash = "xxx|pcad9a68fa6acc5c5ba965adf6ec465ca42fd887"
|
||||||
|
|
||||||
|
photos, _, err := PhotoSearch(frm)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(photos[0].PhotoTitle)
|
||||||
|
assert.GreaterOrEqual(t, len(photos), 1)
|
||||||
|
|
||||||
|
for _, r := range photos {
|
||||||
|
assert.IsType(t, PhotoResult{}, r)
|
||||||
|
assert.NotEmpty(t, r.ID)
|
||||||
|
assert.NotEmpty(t, r.CameraID)
|
||||||
|
assert.NotEmpty(t, r.LensID)
|
||||||
|
|
||||||
|
if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok {
|
||||||
|
assert.Equal(t, fix.PhotoName, r.PhotoName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,3 +92,13 @@ func TestOrphanPhotos(t *testing.T) {
|
|||||||
|
|
||||||
assert.IsType(t, entity.Photos{}, result)
|
assert.IsType(t, entity.Photos{}, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO How to verify?
|
||||||
|
func TestFixPrimaries(t *testing.T) {
|
||||||
|
t.Run("success", func(t *testing.T) {
|
||||||
|
err := FixPrimaries()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user