Fix faces not getting scanned

- This fixes #344
- Add integration tests for face recognition
- Properly check that the user own the queried album
This commit is contained in:
viktorstrate
2021-04-26 12:21:15 +02:00
parent d03923992c
commit 1029b61a4c
14 changed files with 126 additions and 92 deletions

View File

@@ -3,9 +3,11 @@ package scanner_test
import (
"os"
"testing"
"time"
"github.com/photoview/photoview/api/graphql/models"
"github.com/photoview/photoview/api/scanner"
"github.com/photoview/photoview/api/scanner/face_detection"
"github.com/photoview/photoview/api/test_utils"
"github.com/stretchr/testify/assert"
)
@@ -42,6 +44,10 @@ func TestFullScan(t *testing.T) {
return
}
if !assert.NoError(t, face_detection.InitializeFaceDetector(db)) {
return
}
if !assert.NoError(t, scanner.AddUserToQueue(user)) {
return
}
@@ -54,6 +60,32 @@ func TestFullScan(t *testing.T) {
return
}
assert.Equal(t, 10, len(all_media))
assert.Equal(t, 9, len(all_media))
var all_media_url []*models.MediaURL
if !assert.NoError(t, db.Find(&all_media_url).Error) {
return
}
assert.Equal(t, 18, len(all_media_url))
// Verify that faces was recognized
assert.Eventually(t, func() bool {
var all_face_groups []*models.FaceGroup
if !assert.NoError(t, db.Find(&all_face_groups).Error) {
return false
}
return len(all_face_groups) == 3
}, time.Second*5, time.Millisecond*500)
assert.Eventually(t, func() bool {
var all_image_faces []*models.ImageFace
if !assert.NoError(t, db.Find(&all_image_faces).Error) {
return false
}
return len(all_image_faces) == 6
}, time.Second*5, time.Millisecond*500)
}