mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Unit testing for performers,studios,movies FindByName/s (#581)
This commit is contained in:
@@ -16,15 +16,19 @@ import (
|
||||
|
||||
"github.com/stashapp/stash/pkg/database"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
const totalScenes = 12
|
||||
const totalPerformers = 3
|
||||
const totalMovies = 1
|
||||
const performersNameCase = 3
|
||||
const performersNameNoCase = 2
|
||||
const moviesNameCase = 1
|
||||
const moviesNameNoCase = 1
|
||||
const totalGalleries = 1
|
||||
const tagsNameNoCase = 2
|
||||
const tagsNameCase = 5
|
||||
const totalStudios = 1
|
||||
const studiosNameCase = 1
|
||||
const studiosNameNoCase = 1
|
||||
|
||||
var sceneIDs []int
|
||||
var performerIDs []int
|
||||
@@ -35,6 +39,9 @@ var studioIDs []int
|
||||
var markerIDs []int
|
||||
|
||||
var tagNames []string
|
||||
var studioNames []string
|
||||
var movieNames []string
|
||||
var performerNames []string
|
||||
|
||||
const sceneIdxWithMovie = 0
|
||||
const sceneIdxWithGallery = 1
|
||||
@@ -46,24 +53,35 @@ const sceneIdxWithStudio = 6
|
||||
const sceneIdxWithMarker = 7
|
||||
|
||||
const performerIdxWithScene = 0
|
||||
const performerIdx1WithScene = 1
|
||||
const performerIdx2WithScene = 2
|
||||
|
||||
// performers with dup names start from the end
|
||||
const performerIdx1WithDupName = 3
|
||||
const performerIdxWithDupName = 4
|
||||
|
||||
const movieIdxWithScene = 0
|
||||
|
||||
const galleryIdxWithScene = 0
|
||||
// movies with dup names start from the end
|
||||
const movieIdxWithDupName = 1
|
||||
|
||||
const performerIdx1WithScene = 1
|
||||
const performerIdx2WithScene = 2
|
||||
const galleryIdxWithScene = 0
|
||||
|
||||
const tagIdxWithScene = 0
|
||||
const tagIdx1WithScene = 1
|
||||
const tagIdx2WithScene = 2
|
||||
const tagIdxWithPrimaryMarker = 3
|
||||
const tagIdxWithMarker = 4
|
||||
|
||||
// tags with dup names start from the end
|
||||
const tagIdx1WithDupName = 5
|
||||
const tagIdxWithDupName = 6
|
||||
|
||||
const studioIdxWithScene = 0
|
||||
|
||||
// studios with dup names start from the end
|
||||
const studioIdxWithDupName = 1
|
||||
|
||||
const markerIdxWithScene = 0
|
||||
|
||||
const pathField = "Path"
|
||||
@@ -125,12 +143,12 @@ func populateDB() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := createMovies(tx, totalMovies); err != nil {
|
||||
if err := createMovies(tx, moviesNameCase, moviesNameNoCase); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
if err := createPerformers(tx, totalPerformers); err != nil {
|
||||
if err := createPerformers(tx, performersNameCase, performersNameNoCase); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
@@ -140,7 +158,7 @@ func populateDB() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := createStudios(tx, totalStudios); err != nil {
|
||||
if err := createStudios(tx, studiosNameCase, studiosNameNoCase); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
@@ -288,13 +306,27 @@ func getMovieStringValue(index int, field string) string {
|
||||
return "movie_" + strconv.FormatInt(int64(index), 10) + "_" + field
|
||||
}
|
||||
|
||||
func createMovies(tx *sqlx.Tx, n int) error {
|
||||
//createMoviees creates n movies with plain Name and o movies with camel cased NaMe included
|
||||
func createMovies(tx *sqlx.Tx, n int, o int) error {
|
||||
mqb := models.NewMovieQueryBuilder()
|
||||
const namePlain = "Name"
|
||||
const nameNoCase = "NaMe"
|
||||
|
||||
name := namePlain
|
||||
|
||||
for i := 0; i < n+o; i++ {
|
||||
index := i
|
||||
|
||||
if i >= n { // i<n tags get normal names
|
||||
name = nameNoCase // i>=n movies get dup names if case is not checked
|
||||
index = n + o - (i + 1) // for the name to be the same the number (index) must be the same also
|
||||
} // so count backwards to 0 as needed
|
||||
// movies [ i ] and [ n + o - i - 1 ] should have similar names with only the Name!=NaMe part different
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
movie := models.Movie{
|
||||
Name: sql.NullString{String: getMovieStringValue(i, "Name"), Valid: true},
|
||||
Name: sql.NullString{String: getMovieStringValue(index, name), Valid: true},
|
||||
FrontImage: []byte(models.DefaultMovieImage),
|
||||
Checksum: utils.MD5FromString(name),
|
||||
}
|
||||
|
||||
created, err := mqb.Create(movie, tx)
|
||||
@@ -304,6 +336,7 @@ func createMovies(tx *sqlx.Tx, n int) error {
|
||||
}
|
||||
|
||||
movieIDs = append(movieIDs, created.ID)
|
||||
movieNames = append(movieNames, created.Name.String)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -318,12 +351,25 @@ func getPerformerBoolValue(index int) bool {
|
||||
return index == 1
|
||||
}
|
||||
|
||||
func createPerformers(tx *sqlx.Tx, n int) error {
|
||||
//createPerformers creates n performers with plain Name and o performers with camel cased NaMe included
|
||||
func createPerformers(tx *sqlx.Tx, n int, o int) error {
|
||||
pqb := models.NewPerformerQueryBuilder()
|
||||
const namePlain = "Name"
|
||||
const nameNoCase = "NaMe"
|
||||
|
||||
name := namePlain
|
||||
|
||||
for i := 0; i < n+o; i++ {
|
||||
index := i
|
||||
|
||||
if i >= n { // i<n tags get normal names
|
||||
name = nameNoCase // i>=n performers get dup names if case is not checked
|
||||
index = n + o - (i + 1) // for the name to be the same the number (index) must be the same also
|
||||
} // so count backwards to 0 as needed
|
||||
// performers [ i ] and [ n + o - i - 1 ] should have similar names with only the Name!=NaMe part different
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
performer := models.Performer{
|
||||
Name: sql.NullString{String: getPerformerStringValue(i, "Name"), Valid: true},
|
||||
Name: sql.NullString{String: getPerformerStringValue(index, name), Valid: true},
|
||||
Checksum: getPerformerStringValue(i, checksumField),
|
||||
// just use movie image
|
||||
Image: []byte(models.DefaultMovieImage),
|
||||
@@ -337,6 +383,7 @@ func createPerformers(tx *sqlx.Tx, n int) error {
|
||||
}
|
||||
|
||||
performerIDs = append(performerIDs, created.ID)
|
||||
performerNames = append(performerNames, created.Name.String)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -385,13 +432,27 @@ func getStudioStringValue(index int, field string) string {
|
||||
return "studio_" + strconv.FormatInt(int64(index), 10) + "_" + field
|
||||
}
|
||||
|
||||
func createStudios(tx *sqlx.Tx, n int) error {
|
||||
//createStudios creates n studios with plain Name and o studios with camel cased NaMe included
|
||||
func createStudios(tx *sqlx.Tx, n int, o int) error {
|
||||
sqb := models.NewStudioQueryBuilder()
|
||||
const namePlain = "Name"
|
||||
const nameNoCase = "NaMe"
|
||||
|
||||
name := namePlain
|
||||
|
||||
for i := 0; i < n+o; i++ {
|
||||
index := i
|
||||
|
||||
if i >= n { // i<n studios get normal names
|
||||
name = nameNoCase // i>=n studios get dup names if case is not checked
|
||||
index = n + o - (i + 1) // for the name to be the same the number (index) must be the same also
|
||||
} // so count backwards to 0 as needed
|
||||
// studios [ i ] and [ n + o - i - 1 ] should have similar names with only the Name!=NaMe part different
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
tag := models.Studio{
|
||||
Name: sql.NullString{String: getStudioStringValue(i, "Name"), Valid: true},
|
||||
Image: []byte(models.DefaultStudioImage),
|
||||
Name: sql.NullString{String: getStudioStringValue(index, name), Valid: true},
|
||||
Image: []byte(models.DefaultStudioImage),
|
||||
Checksum: utils.MD5FromString(name),
|
||||
}
|
||||
|
||||
created, err := sqb.Create(tag, tx)
|
||||
@@ -401,6 +462,7 @@ func createStudios(tx *sqlx.Tx, n int) error {
|
||||
}
|
||||
|
||||
studioIDs = append(studioIDs, created.ID)
|
||||
studioNames = append(studioNames, created.Name.String)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user