Add tests for mediafile
This commit is contained in:
parent
f85b7904a3
commit
61b5bb028c
1 changed files with 162 additions and 13 deletions
|
@ -1,6 +1,8 @@
|
|||
package photoprism
|
||||
|
||||
import (
|
||||
"github.com/photoprism/photoprism/internal/util"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
|
@ -10,29 +12,57 @@ import (
|
|||
func TestMediaFile_RelatedFiles(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/canon_eos_6d.dng")
|
||||
t.Run("canon_eos_6d.dng", func(t *testing.T) {
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/canon_eos_6d.dng")
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, err)
|
||||
|
||||
expectedBaseFilename := conf.ExamplesPath() + "/canon_eos_6d"
|
||||
expectedBaseFilename := conf.ExamplesPath() + "/canon_eos_6d"
|
||||
|
||||
related, _, err := mediaFile.RelatedFiles()
|
||||
related, _, err := mediaFile.RelatedFiles()
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Len(t, related, 3)
|
||||
assert.Len(t, related, 3)
|
||||
|
||||
for _, result := range related {
|
||||
t.Logf("Filename: %s", result.Filename())
|
||||
for _, result := range related {
|
||||
t.Logf("Filename: %s", result.Filename())
|
||||
|
||||
filename := result.Filename()
|
||||
filename := result.Filename()
|
||||
|
||||
extension := result.Extension()
|
||||
extension := result.Extension()
|
||||
|
||||
baseFilename := filename[0 : len(filename)-len(extension)]
|
||||
baseFilename := filename[0 : len(filename)-len(extension)]
|
||||
|
||||
assert.Equal(t, expectedBaseFilename, baseFilename)
|
||||
}
|
||||
assert.Equal(t, expectedBaseFilename, baseFilename)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("iphone_7.heic", func(t *testing.T) {
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/iphone_7.heic")
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
expectedBaseFilename := conf.ExamplesPath() + "/iphone_7"
|
||||
|
||||
related, _, err := mediaFile.RelatedFiles()
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Len(t, related, 3)
|
||||
|
||||
for _, result := range related {
|
||||
t.Logf("Filename: %s", result.Filename())
|
||||
|
||||
filename := result.Filename()
|
||||
|
||||
extension := result.Extension()
|
||||
|
||||
baseFilename := filename[0 : len(filename)-len(extension)]
|
||||
|
||||
assert.Equal(t, expectedBaseFilename, baseFilename)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestMediaFile_RelatedFiles_Ordering(t *testing.T) {
|
||||
|
@ -157,3 +187,122 @@ func TestMediaFile_Exists(t *testing.T) {
|
|||
assert.NotNil(t, err)
|
||||
assert.Nil(t, mediaFile)
|
||||
}
|
||||
|
||||
func TestMediaFileCanonicalName(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/beach_wood.jpg")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "20180111_130938_EB4B2A989C20", mediaFile.CanonicalName())
|
||||
}
|
||||
|
||||
func TestMediaFileCanonicalNameFromFile(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/beach_wood.jpg")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "beach_wood", mediaFile.CanonicalNameFromFile())
|
||||
}
|
||||
|
||||
func TestMediaFile_CanonicalNameFromFileWithDirectory(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/beach_wood.jpg")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, conf.ExamplesPath()+"/beach_wood", mediaFile.CanonicalNameFromFileWithDirectory())
|
||||
}
|
||||
|
||||
func TestMediaFile_SetFilename(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/turtle_brown_blue.jpg")
|
||||
assert.Nil(t, err)
|
||||
mediaFile.SetFilename("newFilename")
|
||||
assert.Equal(t, "newFilename", mediaFile.filename)
|
||||
mediaFile.SetFilename("turtle_brown_blue")
|
||||
assert.Equal(t, "turtle_brown_blue", mediaFile.filename)
|
||||
}
|
||||
|
||||
func TestMediaFile_Copy(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
thumbsPath := conf.CachePath() + "/_tmp"
|
||||
|
||||
os.MkdirAll(thumbsPath, os.ModePerm)
|
||||
|
||||
defer os.RemoveAll(thumbsPath)
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/table_white.jpg")
|
||||
assert.Nil(t, err)
|
||||
mediaFile.Copy(thumbsPath + "table_whitecopy.jpg")
|
||||
assert.True(t, util.Exists(thumbsPath+"table_whitecopy.jpg"))
|
||||
|
||||
}
|
||||
|
||||
func TestMediaFile_DateCreated(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
t.Run("iphone_7.heic", func(t *testing.T) {
|
||||
if mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/iphone_7.heic"); err == nil {
|
||||
|
||||
info := mediaFile.CanonicalName()
|
||||
|
||||
t.Log(info)
|
||||
|
||||
exifinfo, err := mediaFile.Exif()
|
||||
|
||||
t.Log(exifinfo.TakenAt)
|
||||
|
||||
assert.Empty(t, err)
|
||||
} else {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
t.Run("clock_purple.jpg", func(t *testing.T) {
|
||||
if mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/clock_purple.jpg"); err == nil {
|
||||
|
||||
info := mediaFile.CanonicalName()
|
||||
|
||||
t.Log(info)
|
||||
exifinfo, err := mediaFile.Exif()
|
||||
|
||||
t.Log(exifinfo.TakenAt)
|
||||
|
||||
assert.Empty(t, err)
|
||||
} else {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
t.Run("canon_eos_6d.dng", func(t *testing.T) {
|
||||
if mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/canon_eos_6d.dng"); err == nil {
|
||||
|
||||
info := mediaFile.DateCreated().UTC()
|
||||
|
||||
exifinfo, err := mediaFile.Exif()
|
||||
|
||||
t.Log(info)
|
||||
|
||||
t.Log(exifinfo.TakenAt)
|
||||
|
||||
assert.Empty(t, err)
|
||||
} else {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
t.Run("elephants.jpg", func(t *testing.T) {
|
||||
if mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/elephants.jpg"); err == nil {
|
||||
|
||||
info := mediaFile.DateCreated().UTC()
|
||||
|
||||
exifinfo, err := mediaFile.Exif()
|
||||
|
||||
t.Log(info)
|
||||
|
||||
t.Log(exifinfo.TakenAt)
|
||||
|
||||
assert.Empty(t, err)
|
||||
} else {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue