Test: Add test for query/geo

This commit is contained in:
Theresa Gresch 2020-01-28 22:16:59 +01:00
parent 204646babd
commit 4b2259740b
4 changed files with 62 additions and 8 deletions

View file

@ -9,13 +9,20 @@ INSERT INTO countries (id, country_slug, country_name, country_description, coun
INSERT INTO albums (id, album_uuid, album_name, album_slug, album_favorite) VALUES ('2', '3', 'Christmas2030', 'christmas2030', 0);
INSERT INTO albums (id, album_uuid, cover_uuid, album_name, album_slug, album_favorite) VALUES ('1', '4', '654', 'Holiday2030', 'holiday-2030', 1);
INSERT INTO photos_albums (album_uuid, photo_uuid) VALUES ('4', '654');
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash) VALUES ('1', '1', '654', 'exampleFileName.jpg', 1, '123xxx');
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash) VALUES ('2', '2', '655', 'exampleDNGFile.dng', 1, '124xxx');
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash) VALUES ('3', '2', '655', 'exampleXmpFile.xmp', 0, '125xxx');
INSERT INTO photos (id, photo_uuid, photo_year, photo_month) VALUES ('1', '654', 2790, 2);
INSERT INTO photos (id, photo_uuid, photo_year, photo_month) VALUES ('2', '655', 2790, 2);
INSERT INTO photos (id, photo_uuid, photo_year, photo_month) VALUES ('3', '656', 1990, 3);
INSERT INTO photos (id, photo_uuid, photo_year, photo_month) VALUES ('4', '657', 1990, 4);
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash, file_missing) VALUES ('1', '1', '654', 'exampleFileName.jpg', 1, '123xxx', 0);
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash, file_missing) VALUES ('2', '2', '655', 'exampleDNGFile.dng', 1, '124xxx', 0);
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash, file_missing) VALUES ('3', '2', '655', 'exampleXmpFile.xmp', 0, '125xxx', 0);
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash, file_missing) VALUES ('4', '5', '658', 'bridge.jpg', 1, '126xxx', 0);
INSERT INTO files (id, photo_id, photo_uuid, file_name, file_primary, file_hash, file_missing) VALUES ('5', '6', '659', 'reunion.jpg', 1, '127xxx', 0);
INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES ('1', '654', 2790, 2, '48.519235', '9.057996666666666');
INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES ('2', '655', 2790, 2, '48.519235', '9.057996666666666');
INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES ('3', '656', 1990, 3, '48.519235', '9.057996666666666');
INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES ('4', '657', 1990, 4, '48.519235', '9.057996666666666');
INSERT INTO photos (id, photo_uuid, taken_at, photo_lat, photo_lng, photo_title) VALUES ('5', '658', '2014-07-17 15:42:12', '48.519235', '9.057996666666666', 'Neckarbrücke');
INSERT INTO photos (id, photo_uuid, taken_at, photo_lat, photo_lng, photo_title) VALUES ('6', '659', '2015-11-11 09:07:18', '-21.34263611111111', '55.466944444444444', 'Reunion');
INSERT INTO keywords (id, keyword, skip) VALUES (1, 'bridge', 0);
INSERT INTO keywords (id, keyword, skip) VALUES (2, 'beach', 0);
INSERT INTO photos_keywords (photo_id, keyword_id) VALUES (5, 1);
INSERT INTO categories (label_id, category_id) VALUES ('1', '1');
INSERT INTO labels (id, label_uuid, label_slug, label_name, label_priority, label_favorite) VALUES ('1', '12', 'flower', 'Flower', 1, 1);
INSERT INTO labels (id, label_uuid, label_slug, label_name, label_priority, label_favorite) VALUES ('2', '13', 'cake', 'Cake', 5, 0);

View file

@ -28,3 +28,7 @@ func (f *GeoSearch) SetQuery(q string) {
func (f *GeoSearch) ParseQueryString() error {
return ParseQueryString(f)
}
func NewGeoSearch(query string) GeoSearch {
return GeoSearch{Query: query}
}

View file

@ -16,7 +16,7 @@ func TestRepo_FindFiles(t *testing.T) {
files, err := search.FindFiles(1000, 0)
assert.Nil(t, err)
assert.Equal(t, 3, len(files))
assert.Equal(t, 5, len(files))
})
}

View file

@ -0,0 +1,43 @@
package query
import (
"github.com/photoprism/photoprism/internal/form"
"github.com/stretchr/testify/assert"
"testing"
"github.com/photoprism/photoprism/internal/config"
)
func TestRepo_Geo(t *testing.T) {
conf := config.TestConfig()
search := New(conf.OriginalsPath(), conf.Db())
t.Run("search all photos", func(t *testing.T) {
query := form.NewGeoSearch("")
result, err := search.Geo(query)
assert.Nil(t, err)
assert.Equal(t, 4, len(result))
})
t.Run("search for bridge", func(t *testing.T) {
query := form.NewGeoSearch("Query:bridge Before:3006-01-02")
result, err := search.Geo(query)
assert.Nil(t, err)
assert.Equal(t, "Neckarbrücke", result[0].PhotoTitle)
})
t.Run("search for timeframe", func(t *testing.T) {
query := form.NewGeoSearch("After:2014-12-02 Before:3006-01-02")
result, err := search.Geo(query)
assert.Nil(t, err)
t.Log(result)
assert.Equal(t, "Reunion", result[0].PhotoTitle)
})
}