photoprism/mediafile_test.go

101 lines
2.5 KiB
Go
Raw Normal View History

2018-02-04 17:34:07 +01:00
package photoprism
import (
"github.com/stretchr/testify/assert"
2018-02-28 10:08:49 +01:00
"testing"
2018-02-04 17:34:07 +01:00
)
func TestMediaFile_FindRelatedImages(t *testing.T) {
conf := NewTestConfig()
2018-02-04 17:34:07 +01:00
conf.InitializeTestData(t)
2018-02-04 17:34:07 +01:00
mediaFile := NewMediaFile(conf.ImportPath + "/raw/20140717_154212_1EC48F8489.cr2")
2018-02-04 17:34:07 +01:00
expectedBaseFilename := conf.ImportPath + "/raw/20140717_154212_1EC48F8489"
2018-02-04 17:34:07 +01:00
related, _, err := mediaFile.GetRelatedFiles()
2018-02-04 17:34:07 +01:00
assert.Empty(t, err)
2018-02-04 17:34:07 +01:00
assert.Len(t, related, 3)
2018-02-04 17:34:07 +01:00
for _, result := range related {
filename := result.GetFilename()
2018-02-04 17:34:07 +01:00
extension := result.GetExtension()
2018-02-04 17:34:07 +01:00
2018-02-28 10:08:49 +01:00
baseFilename := filename[0 : len(filename)-len(extension)]
2018-02-04 17:34:07 +01:00
assert.Equal(t, expectedBaseFilename, baseFilename)
2018-02-04 17:34:07 +01:00
}
}
2018-09-11 23:43:03 +02:00
func TestMediaFile_GetEditedFilename(t *testing.T) {
mediaFile1 := NewMediaFile("/foo/bar/IMG_1234.jpg")
assert.Equal(t, "/foo/bar/IMG_E1234.jpg", mediaFile1.GetEditedFilename())
mediaFile2 := NewMediaFile("/foo/bar/IMG_E1234.jpg")
assert.Equal(t, "", mediaFile2.GetEditedFilename())
mediaFile3 := NewMediaFile("/foo/bar/BAZ_1234.jpg")
assert.Equal(t, "", mediaFile3.GetEditedFilename())
}
2018-02-04 17:34:07 +01:00
func TestMediaFile_GetPerceptiveHash(t *testing.T) {
conf := NewTestConfig()
conf.InitializeTestData(t)
mediaFile1 := NewMediaFile(conf.ImportPath + "/20130203_193332_0AE340D280.jpg")
hash1, _ := mediaFile1.GetPerceptualHash()
assert.Equal(t, "66debc383325d3bd", hash1)
mediaFile2 := NewMediaFile(conf.ImportPath + "/20130203_193332_0AE340D280_V2.jpg")
hash2, _ := mediaFile2.GetPerceptualHash()
2018-02-04 17:34:07 +01:00
assert.Equal(t, "e6debc393325c3b9", hash2)
2018-02-04 17:34:07 +01:00
distance, _ := mediaFile1.GetPerceptualDistance(hash2)
2018-02-04 17:34:07 +01:00
assert.Equal(t, 4, distance)
mediaFile3 := NewMediaFile(conf.ImportPath + "/iphone/IMG_6788.JPG")
hash3, _ := mediaFile3.GetPerceptualHash()
assert.Equal(t, "f1e2858b171d3e78", hash3)
distance, _ = mediaFile1.GetPerceptualDistance(hash3)
assert.Equal(t, 33, distance)
2018-02-04 17:34:07 +01:00
}
func TestMediaFile_GetMimeType(t *testing.T) {
conf := NewTestConfig()
conf.InitializeTestData(t)
image1 := NewMediaFile(conf.ImportPath + "/iphone/IMG_6788.JPG")
assert.Equal(t, "image/jpeg", image1.GetMimeType())
image2 := NewMediaFile(conf.ImportPath + "/raw/20140717_154212_1EC48F8489.cr2")
assert.Equal(t, "application/octet-stream", image2.GetMimeType())
}
func TestMediaFile_Exists(t *testing.T) {
conf := NewTestConfig()
mediaFile := NewMediaFile(conf.ImportPath + "/iphone/IMG_6788.JPG")
2018-02-04 17:34:07 +01:00
assert.True(t, mediaFile.Exists())
2018-02-04 17:34:07 +01:00
mediaFile = NewMediaFile(conf.ImportPath + "/iphone/IMG_6788_XYZ.JPG")
2018-02-04 17:34:07 +01:00
assert.False(t, mediaFile.Exists())
2018-02-28 10:08:49 +01:00
}