"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/utest_note.py $
$Id: utest_note.py 29832 2007-05-29 19:19:08Z dbinger $
"""
from dulcinea.user import DulcineaUser
from dulcinea.note import Note, Notable
from qp.lib.spec import Specified
from qp.pub.common import site_now
from sancho.utest import UTest

class TestNotable (Specified, Notable):
    pass

class Test (UTest):

    def _pre(self):
        self.note = Note()
        self.notable = TestNotable()
        self.user = DulcineaUser("joe")

    def check_note(self):
        assert Note('bar').get_text() == 'bar'
        assert self.note.is_empty()
        assert self.note.get_timestamp() is None
        time = site_now()
        self.note.set_timestamp(time)
        assert self.note.get_timestamp() is time
        assert self.note.get_user() is None
        self.note.set_user(self.user)
        assert self.note.get_user() is self.user
        assert self.note.get_text() is None
        assert self.note.is_empty()
        self.note.set_text('foo')
        assert self.note.get_text() == 'foo'
        assert not self.note.is_empty()

    def check_notable(self):
        assert self.notable.get_note() is None
        self.notable.set_note(self.note)
        assert self.notable.get_note() is self.note
        assert TestNotable(Note('foo')).get_note().get_text() == 'foo'

if __name__ == "__main__":
    Test()
