OLD | NEW |
1 # Copyright: 2012 MoinMoin:CheerXiao | 1 # Copyright: 2012 MoinMoin:CheerXiao |
2 # Copyright: 2009 MoinMoin:ThomasWaldmann | 2 # Copyright: 2009 MoinMoin:ThomasWaldmann |
3 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. | 3 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. |
4 | 4 |
5 """ | 5 """ |
6 MoinMoin - MoinMoin.items Tests | 6 MoinMoin - MoinMoin.items Tests |
7 """ | 7 """ |
8 | 8 |
9 import pytest | 9 import pytest |
10 | 10 |
11 from werkzeug import escape | 11 from werkzeug import escape |
12 | 12 |
13 from MoinMoin._tests import become_trusted, update_item | 13 from MoinMoin._tests import become_trusted, update_item |
14 from MoinMoin.items import Item, NonExistent, IndexEntry, MixedIndexEntry | 14 from MoinMoin.items import Item, NonExistent, IndexEntry, MixedIndexEntry |
15 from MoinMoin.constants.keys import ITEMTYPE, CONTENTTYPE, NAME, NAME_OLD, COMME
NT, ACTION, ADDRESS | 15 from MoinMoin.constants.keys import ITEMTYPE, CONTENTTYPE, NAME, NAME_OLD, COMME
NT, ACTION, ADDRESS, TRASH, ITEMID |
16 from MoinMoin.constants.contenttypes import CONTENTTYPE_NONEXISTENT | 16 from MoinMoin.constants.contenttypes import CONTENTTYPE_NONEXISTENT |
17 from MoinMoin.constants.itemtypes import ITEMTYPE_NONEXISTENT | 17 from MoinMoin.constants.itemtypes import ITEMTYPE_NONEXISTENT |
18 | 18 |
19 | 19 |
20 def build_index(basename, relnames): | 20 def build_index(basename, relnames): |
21 """ | 21 """ |
22 Build a list of IndexEntry by hand, useful as a test helper. | 22 Build a list of IndexEntry by hand, useful as a test helper. |
23 """ | 23 """ |
24 return [(IndexEntry(relname, '/'.join((basename, relname)), Item.create('/'.
join((basename, relname))).meta)) | 24 return [(IndexEntry(relname, '/'.join((basename, relname)), Item.create('/'.
join((basename, relname))).meta)) |
25 for relname in relnames] | 25 for relname in relnames] |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 'none_test_key': None, | 365 'none_test_key': None, |
366 } | 366 } |
367 item.modify(another_meta, another_data, **update_meta) | 367 item.modify(another_meta, another_data, **update_meta) |
368 item = Item.create(name) | 368 item = Item.create(name) |
369 assert item.name == u'Test_Item' | 369 assert item.name == u'Test_Item' |
370 assert item.meta['test_key'] == another_meta['test_key'] | 370 assert item.meta['test_key'] == another_meta['test_key'] |
371 assert item.meta['another_test_key'] == update_meta['another_test_key'] | 371 assert item.meta['another_test_key'] == update_meta['another_test_key'] |
372 assert item.meta['new_test_key'] == update_meta['new_test_key'] | 372 assert item.meta['new_test_key'] == update_meta['new_test_key'] |
373 assert 'none_test_key' not in item.meta | 373 assert 'none_test_key' not in item.meta |
374 | 374 |
| 375 def test_trash(self): |
| 376 fqname = u'trash_item_test' |
| 377 contenttype = u'text/plain;charset=utf-8' |
| 378 data = 'test_data' |
| 379 meta = {CONTENTTYPE: contenttype} |
| 380 item = Item.create(fqname) |
| 381 # save rev 0 |
| 382 item._save(meta, data) |
| 383 item = Item.create(fqname) |
| 384 assert not item.meta.get(TRASH) |
| 385 |
| 386 meta = dict(item.meta) |
| 387 meta[NAME] = [] |
| 388 # save new rev with no names. |
| 389 item._save(meta, data) |
| 390 new_fqname = u'@itemid/' + item.meta[ITEMID] |
| 391 item = Item.create(new_fqname) |
| 392 assert item.meta[TRASH] |
| 393 |
| 394 new_meta = {NAME: [u'foobar', 'buz'], CONTENTTYPE: contenttype} |
| 395 item._save(new_meta, data) |
| 396 item = Item.create(u'foobar') |
| 397 |
| 398 item.delete(u'Deleting foobar.') |
| 399 item = Item.create(u'buz') |
| 400 assert not item.meta.get(TRASH) |
| 401 |
| 402 # Also delete the only name left. |
| 403 item.delete(u'Moving item to trash.') |
| 404 item = Item.create(new_fqname) |
| 405 assert item.meta[TRASH] |
| 406 |
375 | 407 |
376 coverage_modules = ['MoinMoin.items'] | 408 coverage_modules = ['MoinMoin.items'] |
OLD | NEW |