summaryrefslogtreecommitdiff
path: root/testing/tests/perf/test_sync.py
blob: 45af9a9176b914f9eeb2601602f8ffcaf3357354 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pytest

from twisted.internet.defer import gatherResults

from leap.soledad.common.couch import CouchDatabase
from leap.soledad.common.document import ServerDocument


content = ' ' * 10000


@pytest.inlineCallbacks
def test_upload(soledad_client, request):
    # create a bunch of local documents
    uploads = request.config.option.num_docs
    deferreds = []
    for i in xrange(uploads):
        d = soledad_client.create_doc({'upload': True, 'content': content})
        deferreds.append(d)
    yield gatherResults(deferreds)

    # synchronize
    yield soledad_client.sync()

    # check that documents reached the remote database
    url = request.config.getoption('--couch-url')
    remote = CouchDatabase(url, 'user-0')
    remote_count, _ = remote.get_all_docs()
    assert remote_count == uploads


@pytest.inlineCallbacks
def test_download(soledad_client, request):
    # create a bunch of remote documents
    downloads = request.config.option.num_docs
    url = request.config.getoption('--couch-url')
    remote = CouchDatabase(url, 'user-0')
    for i in xrange(downloads):
        doc = ServerDocument('doc-%d' % i, 'replica:1')
        doc.content = {'download': True, 'content': content}
        remote.save_document(None, doc, i)

    # synchronize
    yield soledad_client.sync()

    # check that documents reached the local database
    local_count, docs = yield soledad_client.get_all_docs()
    assert local_count == downloads