mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Fix bulk performer tagger (#4024)
* Fix tagger modal checkboxes * Fix UNIQUE constraint detection * Performer tagger cache invalidation * Fix batch performer tagger * Use ToPerformer in identify * Add missing excluded fields * Internationalize excluded fields * Replace deprecated substr() * Check RemoteSiteID nil
This commit is contained in:
@@ -3,14 +3,11 @@ package identify
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/models/mocks"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
@@ -22,6 +19,7 @@ func Test_getPerformerID(t *testing.T) {
|
||||
invalidStoredID := "invalidStoredID"
|
||||
validStoredIDStr := "1"
|
||||
validStoredID := 1
|
||||
remoteSiteID := "2"
|
||||
name := "name"
|
||||
|
||||
mockPerformerReaderWriter := mocks.PerformerReaderWriter{}
|
||||
@@ -121,7 +119,8 @@ func Test_getPerformerID(t *testing.T) {
|
||||
args{
|
||||
emptyEndpoint,
|
||||
&models.ScrapedPerformer{
|
||||
Name: &name,
|
||||
Name: &name,
|
||||
RemoteSiteID: &remoteSiteID,
|
||||
},
|
||||
true,
|
||||
false,
|
||||
@@ -179,7 +178,8 @@ func Test_createMissingPerformer(t *testing.T) {
|
||||
args{
|
||||
emptyEndpoint,
|
||||
&models.ScrapedPerformer{
|
||||
Name: &validName,
|
||||
Name: &validName,
|
||||
RemoteSiteID: &remoteSiteID,
|
||||
},
|
||||
},
|
||||
&performerID,
|
||||
@@ -190,7 +190,8 @@ func Test_createMissingPerformer(t *testing.T) {
|
||||
args{
|
||||
emptyEndpoint,
|
||||
&models.ScrapedPerformer{
|
||||
Name: &invalidName,
|
||||
Name: &invalidName,
|
||||
RemoteSiteID: &remoteSiteID,
|
||||
},
|
||||
},
|
||||
nil,
|
||||
@@ -222,120 +223,3 @@ func Test_createMissingPerformer(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_scrapedToPerformerInput(t *testing.T) {
|
||||
name := "name"
|
||||
|
||||
var stringValues []string
|
||||
for i := 0; i < 20; i++ {
|
||||
stringValues = append(stringValues, strconv.Itoa(i))
|
||||
}
|
||||
|
||||
upTo := 0
|
||||
nextVal := func() *string {
|
||||
ret := stringValues[upTo]
|
||||
upTo = (upTo + 1) % len(stringValues)
|
||||
return &ret
|
||||
}
|
||||
|
||||
nextIntVal := func() *int {
|
||||
ret := upTo
|
||||
upTo = (upTo + 1) % len(stringValues)
|
||||
return &ret
|
||||
}
|
||||
|
||||
dateFromInt := func(i int) *models.Date {
|
||||
t := time.Date(2001, 1, i, 0, 0, 0, 0, time.UTC)
|
||||
d := models.Date{Time: t}
|
||||
return &d
|
||||
}
|
||||
dateStrFromInt := func(i int) *string {
|
||||
s := dateFromInt(i).String()
|
||||
return &s
|
||||
}
|
||||
|
||||
genderFromInt := func(i int) *models.GenderEnum {
|
||||
g := models.AllGenderEnum[i%len(models.AllGenderEnum)]
|
||||
return &g
|
||||
}
|
||||
genderStrFromInt := func(i int) *string {
|
||||
s := genderFromInt(i).String()
|
||||
return &s
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
performer *models.ScrapedPerformer
|
||||
want models.Performer
|
||||
}{
|
||||
{
|
||||
"set all",
|
||||
&models.ScrapedPerformer{
|
||||
Name: &name,
|
||||
Disambiguation: nextVal(),
|
||||
Birthdate: dateStrFromInt(*nextIntVal()),
|
||||
DeathDate: dateStrFromInt(*nextIntVal()),
|
||||
Gender: genderStrFromInt(*nextIntVal()),
|
||||
Ethnicity: nextVal(),
|
||||
Country: nextVal(),
|
||||
EyeColor: nextVal(),
|
||||
HairColor: nextVal(),
|
||||
Height: nextVal(),
|
||||
Weight: nextVal(),
|
||||
Measurements: nextVal(),
|
||||
FakeTits: nextVal(),
|
||||
CareerLength: nextVal(),
|
||||
Tattoos: nextVal(),
|
||||
Piercings: nextVal(),
|
||||
Aliases: nextVal(),
|
||||
Twitter: nextVal(),
|
||||
Instagram: nextVal(),
|
||||
URL: nextVal(),
|
||||
Details: nextVal(),
|
||||
},
|
||||
models.Performer{
|
||||
Name: name,
|
||||
Disambiguation: *nextVal(),
|
||||
Birthdate: dateFromInt(*nextIntVal()),
|
||||
DeathDate: dateFromInt(*nextIntVal()),
|
||||
Gender: genderFromInt(*nextIntVal()),
|
||||
Ethnicity: *nextVal(),
|
||||
Country: *nextVal(),
|
||||
EyeColor: *nextVal(),
|
||||
HairColor: *nextVal(),
|
||||
Height: nextIntVal(),
|
||||
Weight: nextIntVal(),
|
||||
Measurements: *nextVal(),
|
||||
FakeTits: *nextVal(),
|
||||
CareerLength: *nextVal(),
|
||||
Tattoos: *nextVal(),
|
||||
Piercings: *nextVal(),
|
||||
Aliases: models.NewRelatedStrings([]string{*nextVal()}),
|
||||
Twitter: *nextVal(),
|
||||
Instagram: *nextVal(),
|
||||
URL: *nextVal(),
|
||||
Details: *nextVal(),
|
||||
},
|
||||
},
|
||||
{
|
||||
"set none",
|
||||
&models.ScrapedPerformer{
|
||||
Name: &name,
|
||||
},
|
||||
models.Performer{
|
||||
Name: name,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := scrapedToPerformerInput(tt.performer)
|
||||
|
||||
// clear created/updated dates
|
||||
got.CreatedAt = time.Time{}
|
||||
got.UpdatedAt = got.CreatedAt
|
||||
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user