photoprism/internal/query/photo_test.go

82 lines
1.6 KiB
Go
Raw Normal View History

package query
import (
"testing"
"time"
2020-11-21 18:08:41 +01:00
"github.com/photoprism/photoprism/internal/entity"
"github.com/stretchr/testify/assert"
)
func TestPhotoByID(t *testing.T) {
2020-02-02 13:03:08 +01:00
t.Run("photo found", func(t *testing.T) {
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) {
result, err := PhotoByID(99999)
2020-02-02 13:03:08 +01:00
assert.Error(t, err, "record not found")
t.Log(result)
})
}
func TestPhotoByUID(t *testing.T) {
2020-02-02 13:03:08 +01:00
t.Run("photo found", func(t *testing.T) {
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) {
result, err := PhotoByUID("99999")
2020-02-02 13:03:08 +01:00
assert.Error(t, err, "record not found")
t.Log(result)
})
}
func TestPreloadPhotoByUID(t *testing.T) {
2020-02-02 13:03:08 +01:00
t.Run("photo found", func(t *testing.T) {
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) {
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) {
r, err := PhotosMissing(15, 0)
2020-05-13 11:57:54 +02:00
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(r))
}
func TestResetPhotosQuality(t *testing.T) {
err := ResetPhotoQuality()
2020-05-13 11:57:54 +02:00
if err != nil {
t.Fatal(err)
}
}
func TestPhotosCheck(t *testing.T) {
result, err := PhotosCheck(10, 0, time.Second)
if err != nil {
t.Fatal(err)
}
assert.IsType(t, entity.Photos{}, result)
}