48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import sys
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
|
|
from datetime import datetime
|
|
from models.episode import Episode
|
|
from models.distilled import Distilled, TYPE_FACT, STATUS_PENDING, STATUS_VALIDATED
|
|
|
|
def test_episode_to_dict_from_dict():
|
|
ep = Episode.create(content='test content', source='test', entities=['entity1'], facts=['fact1'])
|
|
d = ep.to_dict()
|
|
assert d['content'] == 'test content'
|
|
assert d['source'] == 'test'
|
|
ep2 = Episode.from_dict(d)
|
|
assert ep2.content == ep.content
|
|
assert ep2.id == ep.id
|
|
|
|
def test_episode_create():
|
|
ep = Episode.create(content='hello')
|
|
assert ep.id is not None
|
|
assert ep.content == 'hello'
|
|
assert ep.source == 'hermes'
|
|
assert isinstance(ep.timestamp, datetime)
|
|
|
|
def test_distilled_to_dict_from_dict():
|
|
ep = Episode.create(content='test')
|
|
d = Distilled(
|
|
id='d1', episode_id=ep.id, type=TYPE_FACT,
|
|
summary='a summary', confidence=0.8, status=STATUS_PENDING
|
|
)
|
|
dd = d.to_dict()
|
|
assert dd['type'] == TYPE_FACT
|
|
assert dd['confidence'] == 0.8
|
|
d2 = Distilled.from_dict(dd)
|
|
assert d2.id == d.id
|
|
assert d2.type == d.type
|
|
|
|
def test_distilled_defaults():
|
|
d = Distilled(id='d1', episode_id='e1', type=TYPE_FACT, summary='s')
|
|
assert d.status == STATUS_PENDING
|
|
assert d.confidence == 0.5
|
|
assert d.importance == 0
|
|
|
|
if __name__ == '__main__':
|
|
test_episode_to_dict_from_dict()
|
|
test_episode_create()
|
|
test_distilled_to_dict_from_dict()
|
|
test_distilled_defaults()
|
|
print('All model tests passed!') |