3
# Copyright 2008-2015 Canonical
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.
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.
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/>.
18
# For further info, check http://launchpad.net/filesync-server
20
"""Create test data for shard data migration testing."""
23
warnings.simplefilter("ignore")
28
import _pythonpath # NOQA
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
35
user_names = [u'hola', u'crazyhacker', u'chico', u'active.user']
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()
44
d = user.root.make_subdirectory(u"%s dir%s" % (user.username, i))
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)
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")
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))
67
for username in user_names:
68
user = services.get_storage_user(username=username)
70
store = get_storage_store()