3
# Copyright 2010 Canonical Ltd. This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
6
"""Perform simple librarian operations to verify the current configuration.
9
from cStringIO import StringIO
13
from zope.component import getUtility
17
from canonical.launchpad.interfaces.librarian import ILibraryFileAliasSet
21
FILE_DATA = 'x' * FILE_SIZE
22
FILE_LIFETIME = datetime.timedelta(hours=1)
25
def store_file(client):
26
file_id = client.addFile(
27
'smoke-test-file', FILE_SIZE, StringIO(FILE_DATA), 'text/plain',
28
expires=datetime.datetime.now(pytz.UTC)+FILE_LIFETIME)
29
# To be able to retrieve the file, we must commit the current transaction.
31
alias = getUtility(ILibraryFileAliasSet)[file_id]
37
data = urllib.urlopen(url).read()
38
except (MemoryError, KeyboardInterrupt, SystemExit):
39
# Re-raise catastrophic errors.
42
# An error is represented by returning None, which won't match when
43
# comapred against FILE_DATA.
49
def main(restricted_client, regular_client):
50
print 'adding a private file to the librarian...'
51
private_url = store_file(restricted_client)
52
print 'retrieving private file from', private_url
53
if read_file(private_url) != FILE_DATA:
54
print 'ERROR: data fetched does not match data written'
57
print 'adding a public file to the librarian...'
58
public_url = store_file(regular_client)
59
print 'retrieving public file from', public_url
60
if read_file(public_url) != FILE_DATA:
61
print 'ERROR: data fetched does not match data written'