Skip to content

Commit

Permalink
Querybuilder integration tests (stashapp#513)
Browse files Browse the repository at this point in the history
* Vet fixes
* Change low resolution to < 480
  • Loading branch information
WithoutPants authored May 4, 2020
1 parent 2234949 commit d2b0644
Show file tree
Hide file tree
Showing 33 changed files with 8,490 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.5.1
github.com/vektah/gqlparser v1.1.2
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
107 changes: 107 additions & 0 deletions pkg/models/querybuilder_gallery_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// +build integration

package models_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/stashapp/stash/pkg/models"
)

func TestGalleryFind(t *testing.T) {
gqb := models.NewGalleryQueryBuilder()

const galleryIdx = 0
gallery, err := gqb.Find(galleryIDs[galleryIdx])

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Equal(t, getGalleryStringValue(galleryIdx, "Path"), gallery.Path)

gallery, err = gqb.Find(0)

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Nil(t, gallery)
}

func TestGalleryFindByChecksum(t *testing.T) {
gqb := models.NewGalleryQueryBuilder()

const galleryIdx = 0
galleryChecksum := getGalleryStringValue(galleryIdx, "Checksum")
gallery, err := gqb.FindByChecksum(galleryChecksum, nil)

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Equal(t, getGalleryStringValue(galleryIdx, "Path"), gallery.Path)

galleryChecksum = "not exist"
gallery, err = gqb.FindByChecksum(galleryChecksum, nil)

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Nil(t, gallery)
}

func TestGalleryFindByPath(t *testing.T) {
gqb := models.NewGalleryQueryBuilder()

const galleryIdx = 0
galleryPath := getGalleryStringValue(galleryIdx, "Path")
gallery, err := gqb.FindByPath(galleryPath)

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Equal(t, galleryPath, gallery.Path)

galleryPath = "not exist"
gallery, err = gqb.FindByPath(galleryPath)

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Nil(t, gallery)
}

func TestGalleryFindBySceneID(t *testing.T) {
gqb := models.NewGalleryQueryBuilder()

sceneID := sceneIDs[sceneIdxWithGallery]
gallery, err := gqb.FindBySceneID(sceneID, nil)

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Equal(t, getGalleryStringValue(galleryIdxWithScene, "Path"), gallery.Path)

gallery, err = gqb.FindBySceneID(0, nil)

if err != nil {
t.Fatalf("Error finding gallery: %s", err.Error())
}

assert.Nil(t, gallery)
}

// TODO ValidGalleriesForScenePath
// TODO Count
// TODO All
// TODO Query
// TODO Update
// TODO Destroy
// TODO ClearGalleryId
44 changes: 44 additions & 0 deletions pkg/models/querybuilder_movies_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// +build integration

package models_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/stashapp/stash/pkg/models"
)

func TestMovieFindBySceneID(t *testing.T) {
mqb := models.NewMovieQueryBuilder()
sceneID := sceneIDs[sceneIdxWithMovie]

movies, err := mqb.FindBySceneID(sceneID, nil)

if err != nil {
t.Fatalf("Error finding movie: %s", err.Error())
}

assert.Equal(t, 1, len(movies), "expect 1 movie")

movie := movies[0]
assert.Equal(t, getMovieStringValue(movieIdxWithScene, "Name"), movie.Name.String)

movies, err = mqb.FindBySceneID(0, nil)

if err != nil {
t.Fatalf("Error finding movie: %s", err.Error())
}

assert.Equal(t, 0, len(movies))
}

// TODO Update
// TODO Destroy
// TODO Find
// TODO FindByName
// TODO FindByNames
// TODO Count
// TODO All
// TODO Query
45 changes: 45 additions & 0 deletions pkg/models/querybuilder_performer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// +build integration

package models_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/stashapp/stash/pkg/models"
)

func TestPerformerFindBySceneID(t *testing.T) {
pqb := models.NewPerformerQueryBuilder()
sceneID := sceneIDs[sceneIdxWithPerformer]

performers, err := pqb.FindBySceneID(sceneID, nil)

if err != nil {
t.Fatalf("Error finding performer: %s", err.Error())
}

assert.Equal(t, 1, len(performers))
performer := performers[0]

assert.Equal(t, getPerformerStringValue(performerIdxWithScene, "Name"), performer.Name.String)

performers, err = pqb.FindBySceneID(0, nil)

if err != nil {
t.Fatalf("Error finding performer: %s", err.Error())
}

assert.Equal(t, 0, len(performers))
}

// TODO Update
// TODO Destroy
// TODO Find
// TODO FindNameBySceneID
// TODO FindByNames
// TODO Count
// TODO All
// TODO AllSlim
// TODO Query
4 changes: 1 addition & 3 deletions pkg/models/querybuilder_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (qb *SceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
if resolution := resolutionFilter.String(); resolutionFilter.IsValid() {
switch resolution {
case "LOW":
whereClauses = append(whereClauses, "(scenes.height >= 240 AND scenes.height < 480)")
whereClauses = append(whereClauses, "scenes.height < 480")
case "STANDARD":
whereClauses = append(whereClauses, "(scenes.height >= 480 AND scenes.height < 720)")
case "STANDARD_HD":
Expand All @@ -293,8 +293,6 @@ func (qb *SceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
whereClauses = append(whereClauses, "(scenes.height >= 1080 AND scenes.height < 2160)")
case "FOUR_K":
whereClauses = append(whereClauses, "scenes.height >= 2160")
default:
whereClauses = append(whereClauses, "scenes.height < 240")
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions pkg/models/querybuilder_scene_marker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// +build integration

package models_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/stashapp/stash/pkg/models"
)

func TestMarkerFindBySceneID(t *testing.T) {
mqb := models.NewSceneMarkerQueryBuilder()

sceneID := sceneIDs[sceneIdxWithMarker]
markers, err := mqb.FindBySceneID(sceneID, nil)

if err != nil {
t.Fatalf("Error finding markers: %s", err.Error())
}

assert.Len(t, markers, 1)
assert.Equal(t, markerIDs[markerIdxWithScene], markers[0].ID)

markers, err = mqb.FindBySceneID(0, nil)

if err != nil {
t.Fatalf("Error finding marker: %s", err.Error())
}

assert.Len(t, markers, 0)
}

// TODO Update
// TODO Destroy
// TODO Find
// TODO CountByTagID
// TODO GetMarkerStrings
// TODO Wall
// TODO Query
Loading

0 comments on commit d2b0644

Please sign in to comment.