mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-07-20 21:48:49 -04:00
store: Add methods to store media info in the store.
This commit is contained in:
parent
99a1bccbc8
commit
d25989cfd7
3 changed files with 130 additions and 2 deletions
|
@ -3,11 +3,12 @@ import pdb
|
|||
import pprint
|
||||
import pytest
|
||||
|
||||
from nio import RoomMessage
|
||||
from nio import RoomMessage, RoomEncryptedMedia
|
||||
|
||||
from urllib.parse import urlparse
|
||||
from conftest import faker
|
||||
from pantalaimon.index import INDEXING_ENABLED
|
||||
from pantalaimon.store import FetchTask
|
||||
from pantalaimon.store import FetchTask, MediaInfo
|
||||
|
||||
TEST_ROOM = "!SVkFJHzfwvuaIEawgC:localhost"
|
||||
TEST_ROOM2 = "!testroom:localhost"
|
||||
|
@ -46,6 +47,36 @@ class TestClass(object):
|
|||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def encrypted_media_event(self):
|
||||
return RoomEncryptedMedia.from_dict({
|
||||
"room_id": "!testroom:localhost",
|
||||
"event_id": "$15163622445EBvZK:localhost",
|
||||
"origin_server_ts": 1516362244030,
|
||||
"sender": "@example2:localhost",
|
||||
"type": "m.room.message",
|
||||
"content": {
|
||||
"body": "orange_cat.jpg",
|
||||
"msgtype": "m.image",
|
||||
"file": {
|
||||
"v": "v2",
|
||||
"key": {
|
||||
"alg": "A256CTR",
|
||||
"ext": True,
|
||||
"k": "yx0QvkgYlasdWEsdalkejaHBzCkKEBAp3tB7dGtWgrs",
|
||||
"key_ops": ["encrypt", "decrypt"],
|
||||
"kty": "oct"
|
||||
},
|
||||
"iv": "0pglXX7fspIBBBBAEERLFd",
|
||||
"hashes": {
|
||||
"sha256": "eXRDFvh+aXsQRj8a+5ZVVWUQ9Y6u9DYiz4tq1NvbLu8"
|
||||
},
|
||||
"url": "mxc://localhost/maDtasSiPFjROFMnlwxIhhyW",
|
||||
"mimetype": "image/jpeg"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
def test_account_loading(self, panstore):
|
||||
accounts = panstore.load_all_users()
|
||||
# pdb.set_trace()
|
||||
|
@ -119,3 +150,30 @@ class TestClass(object):
|
|||
assert result["results"][0]["result"] == self.test_event.source
|
||||
assert (result["results"][0]["context"]["events_after"][0]
|
||||
== self.another_event.source)
|
||||
|
||||
def test_media_storage(self, panstore):
|
||||
server_name = "test"
|
||||
media_cache = panstore.load_media(server_name)
|
||||
assert not media_cache
|
||||
|
||||
event = self.encrypted_media_event
|
||||
|
||||
mxc = urlparse(event.url)
|
||||
|
||||
assert mxc
|
||||
|
||||
mxc_server = mxc.netloc
|
||||
mxc_path = mxc.path
|
||||
|
||||
assert not panstore.load_media(server_name, mxc_server, mxc_path)
|
||||
|
||||
media = MediaInfo(mxc_server, mxc_path, event.key, event.iv, event.hashes)
|
||||
|
||||
panstore.save_media(server_name, media)
|
||||
|
||||
media_cache = panstore.load_media(server_name)
|
||||
|
||||
assert (mxc_server, mxc_path) in media_cache
|
||||
media_info = media_cache[(mxc_server, mxc_path)]
|
||||
assert media_info == media
|
||||
assert media_info == panstore.load_media(server_name, mxc_server, mxc_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue