mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Studio Tagger (#3510)
* Studio image and parent studio support in scene tagger * Refactor studio backend and add studio tagger --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -15,12 +15,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
studioID = 1
|
||||
noImageID = 2
|
||||
errImageID = 3
|
||||
missingParentStudioID = 4
|
||||
errStudioID = 5
|
||||
errAliasID = 6
|
||||
|
||||
parentStudioID = 10
|
||||
missingStudioID = 11
|
||||
@@ -31,17 +29,19 @@ var (
|
||||
studioName = "testStudio"
|
||||
url = "url"
|
||||
details = "details"
|
||||
rating = 5
|
||||
parentStudioName = "parentStudio"
|
||||
autoTagIgnored = true
|
||||
)
|
||||
|
||||
var studioID = 1
|
||||
var rating = 5
|
||||
var parentStudio models.Studio = models.Studio{
|
||||
Name: parentStudioName,
|
||||
}
|
||||
|
||||
var imageBytes = []byte("imageBytes")
|
||||
|
||||
var aliases = []string{"alias"}
|
||||
var stashID = models.StashID{
|
||||
StashID: "StashID",
|
||||
Endpoint: "Endpoint",
|
||||
@@ -67,6 +67,8 @@ func createFullStudio(id int, parentID int) models.Studio {
|
||||
UpdatedAt: updateTime,
|
||||
Rating: &rating,
|
||||
IgnoreAutoTag: autoTagIgnored,
|
||||
Aliases: models.NewRelatedStrings(aliases),
|
||||
StashIDs: models.NewRelatedStashIDs(stashIDs),
|
||||
}
|
||||
|
||||
if parentID != 0 {
|
||||
@@ -81,6 +83,8 @@ func createEmptyStudio(id int) models.Studio {
|
||||
ID: id,
|
||||
CreatedAt: createTime,
|
||||
UpdatedAt: updateTime,
|
||||
Aliases: models.NewRelatedStrings([]string{}),
|
||||
StashIDs: models.NewRelatedStashIDs([]models.StashID{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,13 +99,11 @@ func createFullJSONStudio(parentStudio, image string, aliases []string) *jsonsch
|
||||
UpdatedAt: json.JSONTime{
|
||||
Time: updateTime,
|
||||
},
|
||||
ParentStudio: parentStudio,
|
||||
Image: image,
|
||||
Rating: rating,
|
||||
Aliases: aliases,
|
||||
StashIDs: []models.StashID{
|
||||
stashID,
|
||||
},
|
||||
ParentStudio: parentStudio,
|
||||
Image: image,
|
||||
Rating: rating,
|
||||
Aliases: aliases,
|
||||
StashIDs: stashIDs,
|
||||
IgnoreAutoTag: autoTagIgnored,
|
||||
}
|
||||
}
|
||||
@@ -114,6 +116,8 @@ func createEmptyJSONStudio() *jsonschema.Studio {
|
||||
UpdatedAt: json.JSONTime{
|
||||
Time: updateTime,
|
||||
},
|
||||
Aliases: []string{},
|
||||
StashIDs: []models.StashID{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,13 +143,13 @@ func initTestTable() {
|
||||
},
|
||||
{
|
||||
createFullStudio(errImageID, parentStudioID),
|
||||
createFullJSONStudio(parentStudioName, "", nil),
|
||||
createFullJSONStudio(parentStudioName, "", []string{"alias"}),
|
||||
// failure to get image is not an error
|
||||
false,
|
||||
},
|
||||
{
|
||||
createFullStudio(missingParentStudioID, missingStudioID),
|
||||
createFullJSONStudio("", image, nil),
|
||||
createFullJSONStudio("", image, []string{"alias"}),
|
||||
false,
|
||||
},
|
||||
{
|
||||
@@ -153,11 +157,6 @@ func initTestTable() {
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
createFullStudio(errAliasID, parentStudioID),
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +173,6 @@ func TestToJSON(t *testing.T) {
|
||||
mockStudioReader.On("GetImage", ctx, errImageID).Return(nil, imageErr).Once()
|
||||
mockStudioReader.On("GetImage", ctx, missingParentStudioID).Return(imageBytes, nil).Maybe()
|
||||
mockStudioReader.On("GetImage", ctx, errStudioID).Return(imageBytes, nil).Maybe()
|
||||
mockStudioReader.On("GetImage", ctx, errAliasID).Return(imageBytes, nil).Maybe()
|
||||
|
||||
parentStudioErr := errors.New("error getting parent studio")
|
||||
|
||||
@@ -182,19 +180,6 @@ func TestToJSON(t *testing.T) {
|
||||
mockStudioReader.On("Find", ctx, missingStudioID).Return(nil, nil)
|
||||
mockStudioReader.On("Find", ctx, errParentStudioID).Return(nil, parentStudioErr)
|
||||
|
||||
aliasErr := errors.New("error getting aliases")
|
||||
|
||||
mockStudioReader.On("GetAliases", ctx, studioID).Return([]string{"alias"}, nil).Once()
|
||||
mockStudioReader.On("GetAliases", ctx, noImageID).Return(nil, nil).Once()
|
||||
mockStudioReader.On("GetAliases", ctx, errImageID).Return(nil, nil).Once()
|
||||
mockStudioReader.On("GetAliases", ctx, missingParentStudioID).Return(nil, nil).Once()
|
||||
mockStudioReader.On("GetAliases", ctx, errAliasID).Return(nil, aliasErr).Once()
|
||||
|
||||
mockStudioReader.On("GetStashIDs", ctx, studioID).Return(stashIDs, nil).Once()
|
||||
mockStudioReader.On("GetStashIDs", ctx, noImageID).Return(nil, nil).Once()
|
||||
mockStudioReader.On("GetStashIDs", ctx, missingParentStudioID).Return(stashIDs, nil).Once()
|
||||
mockStudioReader.On("GetStashIDs", ctx, errImageID).Return(stashIDs, nil).Once()
|
||||
|
||||
for i, s := range scenarios {
|
||||
studio := s.input
|
||||
json, err := ToJSON(ctx, mockStudioReader, &studio)
|
||||
|
||||
Reference in New Issue
Block a user