2020-01-05 14:18:40 +01:00
|
|
|
package query
|
2018-09-12 16:37:30 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-12-11 22:09:11 +01:00
|
|
|
"time"
|
2018-10-31 07:14:33 +01:00
|
|
|
|
2019-12-11 14:10:20 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-10-06 11:50:48 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2018-09-12 16:37:30 +02:00
|
|
|
)
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
func TestPhotoByID(t *testing.T) {
|
2020-02-02 13:03:08 +01:00
|
|
|
t.Run("photo found", func(t *testing.T) {
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := PhotoByID(1000000)
|
2020-05-13 11:57:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Equal(t, 2790, result.PhotoYear)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no photo found", func(t *testing.T) {
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := PhotoByID(99999)
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func TestPhotoByUID(t *testing.T) {
|
2020-02-02 13:03:08 +01:00
|
|
|
t.Run("photo found", func(t *testing.T) {
|
2020-05-23 20:58:58 +02:00
|
|
|
result, err := PhotoByUID("pt9jtdre2lvl0y12")
|
2020-05-13 11:57:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Equal(t, "Reunion", result.PhotoTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no photo found", func(t *testing.T) {
|
2020-05-23 20:58:58 +02:00
|
|
|
result, err := PhotoByUID("99999")
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func TestPreloadPhotoByUID(t *testing.T) {
|
2020-02-02 13:03:08 +01:00
|
|
|
t.Run("photo found", func(t *testing.T) {
|
2020-05-26 19:27:29 +02:00
|
|
|
result, err := PhotoPreloadByUID("pt9jtdre2lvl0y12")
|
2020-05-13 11:57:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Equal(t, "Reunion", result.PhotoTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no photo found", func(t *testing.T) {
|
2020-05-26 19:27:29 +02:00
|
|
|
result, err := PhotoPreloadByUID("99999")
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
}
|
2020-05-13 11:57:54 +02:00
|
|
|
|
|
|
|
func TestMissingPhotos(t *testing.T) {
|
2023-07-23 17:57:48 +02:00
|
|
|
result, err := MissingPhotos(15, 0)
|
2021-02-08 14:09:58 +01:00
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-02-08 14:09:58 +01:00
|
|
|
|
|
|
|
assert.LessOrEqual(t, 1, len(result))
|
2020-05-13 11:57:54 +02:00
|
|
|
}
|
|
|
|
|
2023-07-23 17:57:48 +02:00
|
|
|
func TestArchivedPhotos(t *testing.T) {
|
|
|
|
results, err := ArchivedPhotos(15, 0)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(results))
|
|
|
|
|
|
|
|
if len(results) > 1 {
|
|
|
|
result := results[0]
|
|
|
|
assert.Equal(t, "image", result.PhotoType)
|
|
|
|
assert.Equal(t, "pt9jtdre2lvl0y25", result.PhotoUID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-18 02:23:25 +01:00
|
|
|
func TestPhotosMetadataUpdate(t *testing.T) {
|
2021-11-20 19:14:00 +01:00
|
|
|
interval := entity.MetadataUpdateInterval
|
|
|
|
result, err := PhotosMetadataUpdate(10, 0, time.Second, interval)
|
2021-02-08 14:09:58 +01:00
|
|
|
|
2020-07-13 12:29:11 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-02-08 14:09:58 +01:00
|
|
|
|
2020-07-13 12:29:11 +02:00
|
|
|
assert.IsType(t, entity.Photos{}, result)
|
2020-12-09 21:49:41 +01:00
|
|
|
}
|
2021-01-24 17:46:18 +01:00
|
|
|
|
2021-02-06 16:30:30 +01:00
|
|
|
func TestOrphanPhotos(t *testing.T) {
|
|
|
|
result, err := OrphanPhotos()
|
2021-01-24 17:46:18 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.IsType(t, entity.Photos{}, result)
|
|
|
|
}
|
2021-03-03 11:49:32 +01:00
|
|
|
|
2022-08-10 16:09:21 +02:00
|
|
|
// TODO How to verify?
|
2021-03-03 11:49:32 +01:00
|
|
|
func TestFixPrimaries(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
err := FixPrimaries()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-10-06 11:50:48 +02:00
|
|
|
|
|
|
|
func TestFlagHiddenPhotos(t *testing.T) {
|
|
|
|
// Set photo quality scores to -1 if files are missing.
|
|
|
|
if err := FlagHiddenPhotos(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|