Backend: Add unit tests for internal/photoprism
This commit is contained in:
parent
5648c9616e
commit
edb9bba671
3 changed files with 20 additions and 21 deletions
internal
|
@ -181,7 +181,7 @@ var PhotoFixtures = PhotoMap{
|
|||
"Photo03": {
|
||||
ID: 1000003,
|
||||
PhotoUID: "pt9jtdre2lvl0yh0",
|
||||
TakenAt: time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
TakenAt: time.Date(2008, 1, 1, 1, 0, 0, 0, time.UTC),
|
||||
TakenAtLocal: time.Time{},
|
||||
TakenSrc: "meta",
|
||||
PhotoTitle: "",
|
||||
|
|
19
internal/photoprism/filename_test.go
Normal file
19
internal/photoprism/filename_test.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package photoprism
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFileName(t *testing.T) {
|
||||
t.Run("sidecar", func(t *testing.T) {
|
||||
assert.Equal(t, ".photoprism/test.jpg", FileName("sidecar", "test.jpg"))
|
||||
})
|
||||
t.Run("import", func(t *testing.T) {
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/import/test.jpg", FileName("import", "test.jpg"))
|
||||
})
|
||||
t.Run("examples", func(t *testing.T) {
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/examples/test.jpg", FileName("examples", "test.jpg"))
|
||||
})
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package photoprism
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/pkg/txt"
|
||||
)
|
||||
|
||||
func (ind *Index) estimateLocation(photo *entity.Photo) {
|
||||
var recentPhoto entity.Photo
|
||||
|
||||
if result := ind.db.Unscoped().Order(gorm.Expr("ABS(DATEDIFF(taken_at, ?)) ASC", photo.TakenAt)).Preload("Place").First(&recentPhoto); result.Error == nil {
|
||||
if recentPhoto.HasPlace() {
|
||||
photo.Place = recentPhoto.Place
|
||||
photo.PhotoCountry = photo.Place.PlaceCountry
|
||||
photo.PlaceSrc = entity.SrcAuto
|
||||
log.Debugf("index: approximate location is %s", txt.Quote(recentPhoto.Place.Label()))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue