Ejemplo n.º 1
0
def test_store_and_read():
    today = datetime.now()
    expected_date = datetime(year=today.year, month=today.month, day=today.day, hour=12)
    items = zfood.parse(u'@12; 1 leipä, 2 kalaa, 33cl olutta, 1plo viiniä')

    zfood.store(items, filename='zfood_test.csv', mode='w')
    items = zfood.read(filename='zfood_test.csv') 

    assert len(items) == 4, 'invalid item count expected 4 got %d' % (len(items),)
    assert items[0].item == u'leipä', 'invalid first item %s' % (items[0].item,)
    assert items[1].item == u'kalaa', 'invalid second item'
    assert items[2].item == u'olutta', 'invalid second item'
    assert items[3].item == u'viiniä', 'invalid second item'
    for item in items:
        assert item.at == expected_date
Ejemplo n.º 2
0
def test_store_and_remove():
    items = zfood.parse(u'leipä, olut, goji-marjat')
    for item in items: 
        assert item.id == 0, 'invalid id, expected 0 got %d' % (item.id,)

    zfood.store( items, filename='zfood_test.csv', mode='w')
    assert items[0].id == 1, 'invalid id'
    assert items[1].id == 2, 'invalid id'
    assert items[2].id == 3, 'invalid id'

    zfood.remove(items[1].id, filename='zfood_test.csv')
    items = zfood.read( filename='zfood_test.csv' )

    assert len(items) == 2
    assert items[0].item == u'leipä'
    assert items[1].item == u'goji-marjat'