~hadware/magicicada-server/trusty-support

« back to all changes in this revision

Viewing changes to src/backends/filesync/utilities/make_test_data.py

  • Committer: Facundo Batista
  • Date: 2015-08-05 13:10:02 UTC
  • Revision ID: facundo@taniquetil.com.ar-20150805131002-he7b7k704d8o7js6
First released version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright 2008-2015 Canonical
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Affero General Public License as
 
7
# published by the Free Software Foundation, either version 3 of the
 
8
# License, or (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU Affero General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU Affero General Public License
 
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
17
#
 
18
# For further info, check  http://launchpad.net/filesync-server
 
19
 
 
20
"""Create test data for shard data migration testing."""
 
21
 
 
22
import warnings
 
23
warnings.simplefilter("ignore")
 
24
 
 
25
import random
 
26
import uuid
 
27
 
 
28
import _pythonpath  # NOQA
 
29
 
 
30
from backends.filesync.data import services, downloadservices
 
31
from backends.filesync.data.testing.testdata import get_fake_hash
 
32
from backends.filesync.data.dbmanager import get_storage_store
 
33
from backends.filesync.data.tests.test_music_metadata import TEST_MUSIC_DATA
 
34
 
 
35
user_names = [u'hola', u'crazyhacker', u'chico', u'active.user']
 
36
 
 
37
 
 
38
def make_user_data(user):
 
39
    """Make some user data."""
 
40
    u = services.get_storage_user(username=user_names[random.randint(0, 4)])
 
41
    s = user.root.share(u.id, u"%s to %s" % (user.username, u.username))
 
42
    u.get_share(s.id).accept()
 
43
    for i in range(10):
 
44
        d = user.root.make_subdirectory(u"%s dir%s" % (user.username, i))
 
45
        for f in range(10):
 
46
            f = d.make_file(u"%s file%s.txt" % (user.username, f))
 
47
            uj = f.make_uploadjob(
 
48
                f.content_hash, get_fake_hash(str(random.random())),
 
49
                random.randint(1, 100), random.randint(100, 1000000),
 
50
                random.randint(100, 1000000))
 
51
            uj.commit_content(f.content_hash, uuid.uuid4(), None)
 
52
            services.add_music_metadata(
 
53
                uj.file.content_hash, TEST_MUSIC_DATA, user.shard_id)
 
54
    for i in range(10):
 
55
        user.make_musicstore_download(
 
56
            random.randint(100, 1000000),
 
57
            random.randint(1, 100), u"https://fake.com/%s/%s" % (user.id, i),
 
58
            u"%s" % user.username, u"%s Greatest Hits" % user.username,
 
59
            u"Track %s" % i, "US")
 
60
    for i in range(10):
 
61
        downloadservices.get_or_make_download(
 
62
            user.id, user.root_volume_id,
 
63
            u"https://fake.com/%s/%s" % (user.id, i),
 
64
            u"/a/b", u"%s%s" % (user.id, i))
 
65
 
 
66
 
 
67
for username in user_names:
 
68
    user = services.get_storage_user(username=username)
 
69
    make_user_data(user)
 
70
    store = get_storage_store()
 
71
    store.commit()