Ejemplo n.º 1
0
def test_readonly():
    a = MemoryStorage()
    b = MemoryStorage(read_only=True)
    status = {}
    href_a, _ = a.upload(Item(u'UID:1'))
    href_b, _ = b.upload(Item(u'UID:2'))
    sync(a, b, status)
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status)
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
Ejemplo n.º 2
0
def test_readonly():
    a = MemoryStorage()
    b = MemoryStorage(read_only=True)
    status = {}
    href_a, _ = a.upload(Item(u'UID:1'))
    href_b, _ = b.upload(Item(u'UID:2'))
    sync(a, b, status)
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status)
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
Ejemplo n.º 3
0
def test_missing_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    item = Item(u'asdf')
    href_a, _ = a.upload(item)
    href_b, _ = b.upload(item)
    sync(a, b, status)
    assert len(status) == 1
    assert a.has(href_a)
    assert b.has(href_b)
Ejemplo n.º 4
0
def test_missing_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    item = Item(u'asdf')
    href_a, _ = a.upload(item)
    href_b, _ = b.upload(item)
    sync(a, b, status)
    assert len(status) == 1
    assert a.has(href_a)
    assert b.has(href_b)
Ejemplo n.º 5
0
def test_missing_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    item = Item(u'UID:1')
    a.upload(item)
    b.upload(item)
    sync(a, b, status)
    assert len(status) == 1
    assert a.has('1.txt')
    assert b.has('1.txt')
Ejemplo n.º 6
0
def test_readonly():
    a = MemoryStorage(instance_name='a')
    b = MemoryStorage(instance_name='b')
    status = {}
    href_a, _ = a.upload(Item(u'UID:1'))
    href_b, _ = b.upload(Item(u'UID:2'))
    b.read_only = True
    with pytest.raises(exceptions.ReadOnlyError):
        b.upload(Item(u'UID:3'))

    sync(a, b, status, partial_sync='revert')
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status, partial_sync='revert')
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
Ejemplo n.º 7
0
def test_readonly():
    a = MemoryStorage(instance_name="a")
    b = MemoryStorage(instance_name="b")
    status = {}
    href_a, _ = a.upload(Item(u"UID:1"))
    href_b, _ = b.upload(Item(u"UID:2"))
    b.read_only = True
    with pytest.raises(exceptions.ReadOnlyError):
        b.upload(Item(u"UID:3"))

    sync(a, b, status)
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status)
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
Ejemplo n.º 8
0
def test_already_synced():
    a = MemoryStorage(fileext=".a")
    b = MemoryStorage(fileext=".b")
    item = Item(u"UID:1")
    a.upload(item)
    b.upload(item)
    status = {"1": ({"href": "1.a", "etag": a.get("1.a")[1]}, {"href": "1.b", "etag": b.get("1.b")[1]})}
    old_status = dict(status)
    a.update = b.update = a.upload = b.upload = lambda *a, **kw: pytest.fail("Method shouldn't have been called.")

    for i in (1, 2):
        sync(a, b, status)
        assert status == old_status
        assert a.has("1.a") and b.has("1.b")
Ejemplo n.º 9
0
def test_readonly():
    a = MemoryStorage(instance_name='a')
    b = MemoryStorage(instance_name='b')
    status = {}
    href_a, _ = a.upload(Item(u'UID:1'))
    href_b, _ = b.upload(Item(u'UID:2'))
    b.read_only = True
    with pytest.raises(exceptions.ReadOnlyError):
        b.upload(Item(u'UID:3'))

    sync(a, b, status)
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status)
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
Ejemplo n.º 10
0
def test_already_synced():
    a = MemoryStorage()
    b = MemoryStorage()
    item = Item(u'UID:1')
    a.upload(item)
    b.upload(item)
    status = {'1': ('1', a.get('1')[1], '1', b.get('1')[1])}
    old_status = dict(status)
    a.update = b.update = a.upload = b.upload = \
        lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')

    for i in (1, 2):
        sync(a, b, status)
        assert status == old_status
        assert a.has('1') and b.has('1')
Ejemplo n.º 11
0
def test_already_synced():
    a = MemoryStorage()
    b = MemoryStorage()
    item = Item(u'UID:1')
    a.upload(item)
    b.upload(item)
    status = {
        '1': ('1.txt', a.get('1.txt')[1], '1.txt', b.get('1.txt')[1])
    }
    old_status = dict(status)
    a.update = b.update = a.upload = b.upload = \
        lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')

    for i in (1, 2):
        sync(a, b, status)
        assert status == old_status
        assert a.has('1.txt') and b.has('1.txt')
Ejemplo n.º 12
0
def test_already_synced():
    a = MemoryStorage(fileext='.a')
    b = MemoryStorage(fileext='.b')
    item = Item(u'UID:1')
    a.upload(item)
    b.upload(item)
    status = {
        '1': ({
            'href': '1.a',
            'etag': a.get('1.a')[1]
        }, {
            'href': '1.b',
            'etag': b.get('1.b')[1]
        })
    }
    old_status = dict(status)
    a.update = b.update = a.upload = b.upload = \
        lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')

    for i in (1, 2):
        sync(a, b, status)
        assert status == old_status
        assert a.has('1.a') and b.has('1.b')
Ejemplo n.º 13
0
def test_already_synced():
    a = MemoryStorage(fileext='.a')
    b = MemoryStorage(fileext='.b')
    item = Item(u'UID:1')
    a.upload(item)
    b.upload(item)
    status = {
        '1': ({
            'href': '1.a',
            'etag': a.get('1.a')[1]
        }, {
            'href': '1.b',
            'etag': b.get('1.b')[1]
        })
    }
    old_status = dict(status)
    a.update = b.update = a.upload = b.upload = \
        lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')

    for i in (1, 2):
        sync(a, b, status)
        assert status == old_status
        assert a.has('1.a') and b.has('1.b')
Ejemplo n.º 14
0
def test_deletion():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    item = Item(u'UID:1')
    a.upload(item)
    a.upload(Item(u'UID:2'))
    sync(a, b, status)
    b.delete('1.txt', b.get('1.txt')[1])
    sync(a, b, status)
    assert not a.has('1.txt') and not b.has('1.txt')

    a.upload(item)
    sync(a, b, status)
    assert a.has('1.txt') and b.has('1.txt')
    a.delete('1.txt', a.get('1.txt')[1])
    sync(a, b, status)
    assert not a.has('1.txt') and not b.has('1.txt')
Ejemplo n.º 15
0
def test_deletion():
    a = MemoryStorage(fileext=".a")
    b = MemoryStorage(fileext=".b")
    status = {}

    item = Item(u"UID:1")
    a.upload(item)
    a.upload(Item(u"UID:2"))
    sync(a, b, status)
    b.delete("1.b", b.get("1.b")[1])
    sync(a, b, status)
    assert not a.has("1.a") and not b.has("1.b")

    a.upload(item)
    sync(a, b, status)
    assert a.has("1.a") and b.has("1.b")
    a.delete("1.a", a.get("1.a")[1])
    sync(a, b, status)
    assert not a.has("1.a") and not b.has("1.b")
Ejemplo n.º 16
0
def test_deletion():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    item = Item(u'UID:1')
    a.upload(item)
    a.upload(Item(u'UID:2'))
    sync(a, b, status)
    b.delete('1', b.get('1')[1])
    sync(a, b, status)
    assert not a.has('1') and not b.has('1')

    a.upload(item)
    sync(a, b, status)
    assert a.has('1') and b.has('1')
    a.delete('1', a.get('1')[1])
    sync(a, b, status)
    assert not a.has('1') and not b.has('1')