mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Merge pull request #351 from untitaker/hypothesis-tests
More hypothesis tests
This commit is contained in:
commit
54fa46ffae
1 changed files with 25 additions and 11 deletions
|
|
@ -2,19 +2,33 @@
|
||||||
|
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import pytest
|
from hypothesis import given, settings
|
||||||
|
import hypothesis.strategies as st
|
||||||
|
|
||||||
from vdirsyncer.repair import repair_storage
|
from vdirsyncer.repair import repair_storage
|
||||||
from vdirsyncer.storage.memory import MemoryStorage
|
from vdirsyncer.storage.memory import MemoryStorage
|
||||||
from vdirsyncer.utils import href_safe
|
from vdirsyncer.utils import href_safe
|
||||||
from vdirsyncer.utils.vobject import Item
|
from vdirsyncer.utils.vobject import Item
|
||||||
|
|
||||||
|
uid_strategy = st.text(st.characters(blacklist_categories=(
|
||||||
|
'Zs', 'Zl', 'Zp',
|
||||||
|
'Cc'
|
||||||
|
)))
|
||||||
|
|
||||||
def test_repair_uids():
|
|
||||||
|
@given(uid=uid_strategy)
|
||||||
|
@settings(perform_health_check=False) # Using the random module for UIDs
|
||||||
|
def test_repair_uids(uid):
|
||||||
s = MemoryStorage()
|
s = MemoryStorage()
|
||||||
s.items = {
|
s.items = {
|
||||||
'one': ('asdf', Item(u'BEGIN:VCARD\nFN:Hans\nUID:asdf\nEND:VCARD')),
|
'one': (
|
||||||
'two': ('asdf', Item(u'BEGIN:VCARD\nFN:Peppi\nUID:asdf\nEND:VCARD'))
|
'asdf',
|
||||||
|
Item(u'BEGIN:VCARD\nFN:Hans\nUID:{}\nEND:VCARD'.format(uid))
|
||||||
|
),
|
||||||
|
'two': (
|
||||||
|
'asdf',
|
||||||
|
Item(u'BEGIN:VCARD\nFN:Peppi\nUID:{}\nEND:VCARD'.format(uid))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
|
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
|
||||||
|
|
@ -26,16 +40,16 @@ def test_repair_uids():
|
||||||
assert uid1 != uid2
|
assert uid1 != uid2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('uid', [
|
@given(uid=uid_strategy)
|
||||||
u'äää',
|
@settings(perform_health_check=False) # Using the random module for UIDs
|
||||||
u'test@foo',
|
|
||||||
u'test foo',
|
|
||||||
])
|
|
||||||
def test_repair_unsafe_uids(uid):
|
def test_repair_unsafe_uids(uid):
|
||||||
assert not href_safe(uid)
|
if href_safe(uid):
|
||||||
|
return
|
||||||
|
|
||||||
s = MemoryStorage()
|
s = MemoryStorage()
|
||||||
href, etag = s.upload(Item(u'BEGIN:VCARD\nUID:{}\nEND:VCARD'.format(uid)))
|
item = Item(u'BEGIN:VCARD\nUID:{}\nEND:VCARD'.format(uid))
|
||||||
|
print(repr(item.raw))
|
||||||
|
href, etag = s.upload(item)
|
||||||
assert s.get(href)[0].uid == uid
|
assert s.get(href)[0].uid == uid
|
||||||
|
|
||||||
repair_storage(s)
|
repair_storage(s)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue