Skip to content

Commit

Permalink
tests: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed May 16, 2024
1 parent a50e5a4 commit dcc5e67
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 6 deletions.
70 changes: 70 additions & 0 deletions services/graph/pkg/service/v0/driveitems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,76 @@ var _ = Describe("Driveitems", func() {
Expect(location.Latitude).To(Equal(libregraph.PtrFloat64(49.48675890884328)))
Expect(location.Longitude).To(Equal(libregraph.PtrFloat64(11.103870357204285)))
})

It("returns the image facet if metadata is available", func() {
gatewayClient.On("ListContainer", mock.Anything, mock.Anything).Return(&provider.ListContainerResponse{
Status: status.NewOK(ctx),
Infos: []*provider.ResourceInfo{
{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Id: &provider.ResourceId{StorageId: "storageid", SpaceId: "spaceid", OpaqueId: "opaqueid"},
Etag: "etag",
Mtime: utils.TimeToTS(mtime),
MimeType: "image/jpeg",
ArbitraryMetadata: &provider.ArbitraryMetadata{
Metadata: map[string]string{
"libre.graph.image.width": "1234",
"libre.graph.image.height": "987",
},
},
},
},
}, nil)

res := assertItemsList(1)
image := res.Value[0].Image

Expect(image).ToNot(BeNil())
Expect(image.Width).To(Equal(libregraph.PtrInt32(1234)))
Expect(image.Height).To(Equal(libregraph.PtrInt32(987)))
})

It("returns the photo facet if metadata is available", func() {
gatewayClient.On("ListContainer", mock.Anything, mock.Anything).Return(&provider.ListContainerResponse{
Status: status.NewOK(ctx),
Infos: []*provider.ResourceInfo{
{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Id: &provider.ResourceId{StorageId: "storageid", SpaceId: "spaceid", OpaqueId: "opaqueid"},
Etag: "etag",
Mtime: utils.TimeToTS(mtime),
MimeType: "image/jpeg",
ArbitraryMetadata: &provider.ArbitraryMetadata{
Metadata: map[string]string{
"libre.graph.photo.cameraMake": "Canon",
"libre.graph.photo.cameraModel": "Cannon EOS 5D Mark III",
"libre.graph.photo.exposureDenominator": "100",
"libre.graph.photo.exposureNumerator": "1",
"libre.graph.photo.fNumber": "1.8",
"libre.graph.photo.focalLength": "50",
"libre.graph.photo.iso": "400",
"libre.graph.photo.orientation": "1",
"libre.graph.photo.takenDateTime": "2018-01-01T12:34:56Z",
},
},
},
},
}, nil)

res := assertItemsList(1)
photo := res.Value[0].Photo

Expect(photo).ToNot(BeNil())
Expect(photo.CameraMake).To(Equal(libregraph.PtrString("Canon")))
Expect(photo.CameraModel).To(Equal(libregraph.PtrString("Cannon EOS 5D Mark III")))
Expect(photo.ExposureDenominator).To(Equal(libregraph.PtrFloat64(100)))
Expect(photo.ExposureNumerator).To(Equal(libregraph.PtrFloat64(1)))
Expect(photo.FNumber).To(Equal(libregraph.PtrFloat64(1.8)))
Expect(photo.FocalLength).To(Equal(libregraph.PtrFloat64(50)))
Expect(photo.Iso).To(Equal(libregraph.PtrInt32(400)))
Expect(photo.Orientation).To(Equal(libregraph.PtrInt32(1)))
Expect(photo.TakenDateTime).To(Equal(libregraph.PtrTime(time.Date(2018, 1, 1, 12, 34, 56, 0, time.UTC))))
})
})
})
})
13 changes: 8 additions & 5 deletions services/search/pkg/content/tika.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package content
import (
"context"
"fmt"
"math"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -214,11 +215,13 @@ func (t Tika) getPhoto(meta map[string][]string) *libregraph.Photo {
}
}

// TODO: no idea which keys to use for the next two values
// The denominator for the exposure time fraction from the camera. Read-only.
// ExposureDenominator *float64 `json:"exposureDenominator,omitempty"`
// The numerator for the exposure time fraction from the camera. Read-only.
// ExposureNumerator *float64 `json:"exposureNumerator,omitempty"`
if v, err := getFirstValue(meta, "exif:ExposureTime"); err == nil {
if i, err := strconv.ParseFloat(v, 64); err == nil {
initPhoto()
photo.SetExposureNumerator(1)
photo.SetExposureDenominator(math.Round(1 / i))
}
}

return photo
}
Expand Down
56 changes: 56 additions & 0 deletions services/search/pkg/content/tika_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,62 @@ var _ = Describe("Tika", func() {
Expect(location.Longitude).To(Equal(libregraph.PtrFloat64(11.103870357204285)))
})

It("adds image content", func() {
fullResponse = `[
{
"Content-Type": "image/png",
"width": "100",
"height": "100"
}
]`
doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Size: 1,
})
Expect(err).ToNot(HaveOccurred())

image := doc.Image
Expect(image).ToNot(BeNil())

Expect(image.Width).To(Equal(libregraph.PtrInt32(100)))
Expect(image.Height).To(Equal(libregraph.PtrInt32(100)))
})

It("adds photo content", func() {
fullResponse = `[
{
"Content-Type": "image/png",
"cameraMake": "Canon",
"cameraModel": "Canon EOS 5D",
"exposureNumerator": "1",
"exposureDenominator": "1000",
"fNumber": "1.8",
"focalLength": "50",
"iso": "100",
"orientation": "1",
"takenDateTime": "2019-02-19T13:42:40.000Z",
}
]`
doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Size: 1,
})
Expect(err).ToNot(HaveOccurred())

photo := doc.Photo
Expect(photo).ToNot(BeNil())

Expect(photo.CameraMake).To(Equal(libregraph.PtrString("Canon")))
Expect(photo.CameraModel).To(Equal(libregraph.PtrString("Canon EOS 5D")))
Expect(photo.ExposureNumerator).To(Equal(libregraph.PtrInt32(1)))
Expect(photo.ExposureDenominator).To(Equal(libregraph.PtrInt32(1000)))
Expect(photo.FNumber).To(Equal(libregraph.PtrFloat64(1.8)))
Expect(photo.FocalLength).To(Equal(libregraph.PtrFloat64(50)))
Expect(photo.Iso).To(Equal(libregraph.PtrInt32(100)))
Expect(photo.Orientation).To(Equal(libregraph.PtrInt32(1)))
Expect(photo.TakenDateTime).To(Equal(libregraph.PtrString("2019-02-19T13:42:40.000Z")))
})

It("removes stop words", func() {
body = "body to test stop words!!! against almost everyone"
language = "en"
Expand Down
3 changes: 2 additions & 1 deletion services/userlog/pkg/service/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *Converter) ConvertEvent(eventid string, event interface{}) (OC10Notific
switch ev := event.(type) {
default:
return OC10Notification{}, fmt.Errorf("unknown event type: %T", ev)
// file related
// file related
case events.PostprocessingStepFinished:
switch ev.FinishedStep {
case events.PPStepAntivirus:
Expand All @@ -95,6 +95,7 @@ func (c *Converter) ConvertEvent(eventid string, event interface{}) (OC10Notific
default:
return OC10Notification{}, fmt.Errorf("unknown postprocessing step: %s", ev.FinishedStep)
}

// space related
case events.SpaceDisabled:
return c.spaceMessage(eventid, SpaceDisabled, ev.Executant, ev.ID.GetOpaqueId(), ev.Timestamp)
Expand Down

0 comments on commit dcc5e67

Please sign in to comment.