photoprism/internal/query/faces_test.go
2021-08-27 15:33:06 +02:00

70 lines
1.3 KiB
Go

package query
import (
"testing"
"github.com/photoprism/photoprism/internal/entity"
"github.com/stretchr/testify/assert"
)
func TestFaces(t *testing.T) {
results, err := Faces(true, "")
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, len(results), 1)
for _, val := range results {
assert.IsType(t, entity.Face{}, val)
}
}
func TestMatchFaceMarkers(t *testing.T) {
const faceFixtureId = uint(6)
if m, err := MarkerByID(faceFixtureId); err != nil {
t.Fatal(err)
} else {
assert.Empty(t, m.SubjectUID)
}
// Reset subject_uid.
if err := Db().Model(&entity.Marker{}).
Where("subject_src = ?", entity.SrcAuto).
Where("subject_uid = ?", "jqu0xs11qekk9jx8").
Updates(entity.Values{"SubjectUID": ""}).Error; err != nil {
t.Fatal(err)
}
affected, err := MatchFaceMarkers()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, int64(1), affected)
if m, err := MarkerByID(faceFixtureId); err != nil {
t.Fatal(err)
} else {
assert.Equal(t, "jqu0xs11qekk9jx8", m.SubjectUID)
}
}
func TestRemoveAnonymousFaceClusters(t *testing.T) {
removed, err := RemoveAnonymousFaceClusters()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, int64(2), removed)
}
func TestCountNewFaceMarkers(t *testing.T) {
n := CountNewFaceMarkers(1)
assert.GreaterOrEqual(t, n, 1)
}