Metadata: Add testfiles and tests

This commit is contained in:
theresa 2021-03-30 11:39:20 +02:00
parent defe3d5cba
commit db889c7841
5 changed files with 181 additions and 45 deletions

25
internal/meta/testdata/apple-test-2.xmp vendored Normal file
View file

@ -0,0 +1,25 @@
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:exif="http://ns.adobe.com/exif/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
<exif:GPSLongitude>13.369367199999999</exif:GPSLongitude>
<exif:GPSLongitudeRef>E</exif:GPSLongitudeRef>
<exif:GPSHPositioningError>1</exif:GPSHPositioningError>
<exif:GPSLatitude>52.5250816</exif:GPSLatitude>
<exif:GPSLatitudeRef>N</exif:GPSLatitudeRef>
<exif:GPSTimeStamp>2021-03-26T09:18:59Z</exif:GPSTimeStamp>
<dc:title>Botanischer Garten</dc:title>
<dc:description>Tulpen am See</dc:description>
<dc:subject>
<rdf:Seq>
<rdf:li>Krokus</rdf:li>
<rdf:li>Blume</rdf:li>
<rdf:li>Schöne Wiese</rdf:li>
</rdf:Seq>
</dc:subject>
<photoshop:DateCreated>2021-03-24T13:07:29+01:00</photoshop:DateCreated>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>

View file

@ -2,11 +2,25 @@ package meta
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestXMP(t *testing.T) {
t.Run("apple xmp 2", func(t *testing.T) {
data, err := XMP("testdata/apple-test-2.xmp")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "Botanischer Garten", data.Title)
assert.Equal(t, time.Date(2021, 3, 24, 13, 07, 29, 0, time.FixedZone("", +3600)), data.TakenAt)
assert.Equal(t, "Tulpen am See", data.Description)
assert.Equal(t, "Krokus, Blume, Schöne Wiese", data.Keywords)
})
t.Run("photoshop", func(t *testing.T) {
data, err := XMP("testdata/photoshop.xmp")
@ -15,6 +29,8 @@ func TestXMP(t *testing.T) {
}
assert.Equal(t, "Night Shift / Berlin / 2020", data.Title)
t.Log(data.TakenAt)
assert.Equal(t, time.Date(2020, 1, 1, 17, 28, 25, 729626112, time.UTC), data.TakenAt)
assert.Equal(t, "Michael Mayer", data.Artist)
assert.Equal(t, "Example file for development", data.Description)
assert.Equal(t, "This is an (edited) legal notice", data.Copyright)

View file

@ -13,61 +13,131 @@ import (
)
func TestIndexRelated(t *testing.T) {
conf := config.TestConfig()
t.Run("/2018-04-12 19_24_49.gif", func(t *testing.T) {
conf := config.TestConfig()
testFile, err := NewMediaFile("testdata/2018-04-12 19_24_49.gif")
testFile, err := NewMediaFile("testdata/2018-04-12 19_24_49.gif")
if err != nil {
t.Fatal(err)
}
testRelated, err := testFile.RelatedFiles(true)
if err != nil {
t.Fatal(err)
}
testToken := rnd.Token(8)
testPath := filepath.Join(conf.OriginalsPath(), testToken)
for _, f := range testRelated.Files {
dest := filepath.Join(testPath, f.BaseName())
if err := f.Copy(dest); err != nil {
t.Fatalf("COPY FAILED: %s", err)
if err != nil {
t.Fatal(err)
}
}
mainFile, err := NewMediaFile(filepath.Join(testPath, "2018-04-12 19_24_49.gif"))
testRelated, err := testFile.RelatedFiles(true)
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Fatal(err)
}
related, err := mainFile.RelatedFiles(true)
testToken := rnd.Token(8)
testPath := filepath.Join(conf.OriginalsPath(), testToken)
if err != nil {
t.Fatal(err)
}
for _, f := range testRelated.Files {
dest := filepath.Join(testPath, f.BaseName())
tf := classify.New(conf.AssetsPath(), conf.DisableTensorFlow())
nd := nsfw.New(conf.NSFWModelPath())
convert := NewConvert(conf)
if err := f.Copy(dest); err != nil {
t.Fatalf("COPY FAILED: %s", err)
}
}
ind := NewIndex(conf, tf, nd, convert, NewFiles(), NewPhotos())
opt := IndexOptionsAll()
mainFile, err := NewMediaFile(filepath.Join(testPath, "2018-04-12 19_24_49.gif"))
result := IndexRelated(related, ind, opt)
if err != nil {
t.Fatal(err)
}
assert.False(t, result.Failed())
assert.False(t, result.Stacked())
assert.True(t, result.Success())
assert.Equal(t, IndexAdded, result.Status)
related, err := mainFile.RelatedFiles(true)
if photo, err := query.PhotoByUID(result.PhotoUID); err != nil {
t.Fatal(err)
} else {
assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", photo.TakenAt.String())
assert.Equal(t, "name", photo.TakenSrc)
}
if err != nil {
t.Fatal(err)
}
tf := classify.New(conf.AssetsPath(), conf.DisableTensorFlow())
nd := nsfw.New(conf.NSFWModelPath())
convert := NewConvert(conf)
ind := NewIndex(conf, tf, nd, convert, NewFiles(), NewPhotos())
opt := IndexOptionsAll()
result := IndexRelated(related, ind, opt)
assert.False(t, result.Failed())
assert.False(t, result.Stacked())
assert.True(t, result.Success())
assert.Equal(t, IndexAdded, result.Status)
if photo, err := query.PhotoByUID(result.PhotoUID); err != nil {
t.Fatal(err)
} else {
assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", photo.TakenAt.String())
assert.Equal(t, "name", photo.TakenSrc)
}
})
//TODO this test MUST run before PR 1151 can be merged
/*t.Run("/apple-test-2.jpg", func(t *testing.T) {
conf := config.TestConfig()
testFile, err := NewMediaFile("testdata/apple-test-2.jpg")
if err != nil {
t.Fatal(err)
}
testRelated, err := testFile.RelatedFiles(true)
if err != nil {
t.Fatal(err)
}
testToken := rnd.Token(8)
testPath := filepath.Join(conf.OriginalsPath(), testToken)
for _, f := range testRelated.Files {
dest := filepath.Join(testPath, f.BaseName())
if err := f.Copy(dest); err != nil {
t.Fatalf("COPY FAILED: %s", err)
}
}
mainFile, err := NewMediaFile(filepath.Join(testPath, "apple-test-2.jpg"))
if err != nil {
t.Fatal(err)
}
related, err := mainFile.RelatedFiles(true)
if err != nil {
t.Fatal(err)
}
tf := classify.New(conf.AssetsPath(), conf.DisableTensorFlow())
nd := nsfw.New(conf.NSFWModelPath())
convert := NewConvert(conf)
ind := NewIndex(conf, tf, nd, convert, NewFiles(), NewPhotos())
opt := IndexOptionsAll()
result := IndexRelated(related, ind, opt)
assert.False(t, result.Failed())
assert.False(t, result.Stacked())
assert.True(t, result.Success())
assert.Equal(t, IndexAdded, result.Status)
if photo, err := query.PhotoByUID(result.PhotoUID); err != nil {
t.Fatal(err)
} else {
assert.Equal(t, "Botanischer Garten", photo.PhotoTitle)
assert.Equal(t, "Tulpen am See", photo.PhotoDescription)
assert.Contains(t, photo.Details.Keywords, "apple")
assert.Contains(t, photo.Details.Keywords, "green")
assert.Contains(t, photo.Details.Keywords, "krokus")
assert.Contains(t, photo.Details.Keywords, "blume")
assert.Contains(t, photo.Details.Keywords, "schöne wiese")
assert.Equal(t, "2021-03-24 12:07:29 +0000 UTC", photo.TakenAt.String())
assert.Equal(t, "xmp", photo.TakenSrc)
}
})*/
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 MiB

View file

@ -0,0 +1,25 @@
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:exif="http://ns.adobe.com/exif/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
<exif:GPSLongitude>13.369367199999999</exif:GPSLongitude>
<exif:GPSLongitudeRef>E</exif:GPSLongitudeRef>
<exif:GPSHPositioningError>1</exif:GPSHPositioningError>
<exif:GPSLatitude>52.5250816</exif:GPSLatitude>
<exif:GPSLatitudeRef>N</exif:GPSLatitudeRef>
<exif:GPSTimeStamp>2021-03-26T09:18:59Z</exif:GPSTimeStamp>
<dc:title>Botanischer Garten</dc:title>
<dc:description>Tulpen am See</dc:description>
<dc:subject>
<rdf:Seq>
<rdf:li>Krokus</rdf:li>
<rdf:li>Blume</rdf:li>
<rdf:li>Schöne Wiese</rdf:li>
</rdf:Seq>
</dc:subject>
<photoshop:DateCreated>2021-03-24T13:07:29+01:00</photoshop:DateCreated>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>