#!/www/python/bin/python
"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/test_item.py $
$Id: test_item.py 23142 2003-11-11 21:18:02Z dbinger $
"""

from mx.DateTime import DateTime
from sancho.unittest import TestScenario, parse_args, run_scenarios
from dulcinea.item import Item, ItemFolder

class MyItem(Item):
    approved = True

tested_modules = [ "dulcinea.item" ]

class TestItem(TestScenario):
    def setup(self):
        self.item1 = MyItem(timestamp=DateTime(2000))
        self.item1a = MyItem(timestamp=DateTime(2000))
        self.item2 = MyItem(timestamp=DateTime(2002))
        self.item3 = MyItem(timestamp=DateTime(2003))
        self.folder = ItemFolder()

    def check_basic(self):
        self.test_stmt('self.folder.add_item(self.item1)')
        self.test_stmt('self.folder.add_item(self.item2)')
        self.test_set('self.folder.get_items()', [self.item1, self.item2])
        self.test_seq('self.folder.get_recent_items(2)',
                      [self.item2, self.item1])
        self.test_stmt('self.folder.add_item(self.item3)')
        self.test_seq('self.folder.get_recent_items(2)',
                      [self.item3, self.item2])
        self.test_seq('self.folder.get_recent_items(3)',
                      [self.item3, self.item2, self.item1])
        self.test_seq('self.folder.get_recent_items(None)',
                      [self.item3, self.item2, self.item1])
        self.test_stmt('self.folder.add_item(self.item1a)')
        self.test_seq('self.folder.get_recent_items(2)',
                      [self.item3, self.item2])

    def check_delete(self):
        self.test_stmt('self.folder.add_item(self.item1)')
        self.test_stmt('self.folder.add_item(self.item1a)')
        item = MyItem() # auto timestamp
        self.test_stmt('self.folder.add_item(item)')
        self.test_set('self.folder.get_items()',
                      [self.item1, self.item1a, item])
        self.test_stmt('self.folder.delete_item(self.item1a)')
        self.test_set('self.folder.get_items()', [self.item1, item])
 

if __name__ == "__main__":
    (scenarios, options) = parse_args()
    run_scenarios (scenarios, options)
