~launchpad-pqm/launchpad/devel

8687.15.13 by Karl Fogel
Add the copyright header block to files under lib/lp/archiveuploader/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
3
7864.3.3 by Celso Providelo
Spliting, re-writing and testing procedure for parsing upload paths.
4
"""Runs the doctests for archiveuploader module."""
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
5
6
__metaclass__ = type
7
7864.3.3 by Celso Providelo
Spliting, re-writing and testing procedure for parsing upload paths.
8
import os
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
9
import unittest
10
11
from zope.component import getUtility
12
8426.7.2 by Julian Edwards
migrate archiveuploader to the lp tree.
13
from lp.archiveuploader.nascentupload import NascentUpload
14
from lp.archiveuploader.tests import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
15
    datadir,
16
    getPolicy,
17
    )
11426.1.4 by Guilherme Salgado
Replace the can_upload_* attributes of AbstractUploadPolicy with a single enum.
18
from lp.archiveuploader.uploadpolicy import ArchiveUploadType
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
19
from lp.registry.interfaces.distribution import IDistributionSet
14578.2.1 by William Grant
Move librarian stuff from canonical.launchpad to lp.services.librarian. canonical.librarian remains untouched.
20
from lp.services.librarian.model import LibraryFileAlias
12070.1.37 by Tim Penhey
Remove mock_logger and mock_logger_quiet.
21
from lp.services.log.logger import DevNullLogger
14455.2.4 by William Grant
Drop imports from canonical.launchpad.ftests.
22
from lp.soyuz.interfaces.component import IComponentSet
11869.8.3 by Jonathan Lange
Fix failing imports from most of the tests. Also clean up flakes.
23
from lp.soyuz.model.component import ComponentSelection
14612.2.1 by William Grant
format-imports on lib/. So many imports.
24
from lp.testing import (
25
    login,
26
    logout,
27
    )
14455.2.4 by William Grant
Drop imports from canonical.launchpad.ftests.
28
from lp.testing.gpgkeys import import_public_test_keys
14612.2.1 by William Grant
format-imports on lib/. So many imports.
29
from lp.testing.layers import LaunchpadZopelessLayer
14578.4.4 by William Grant
format-imports.
30
from lp.testing.systemdocs import (
31
    LayeredDocFileSuite,
32
    setGlobs,
33
    )
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
34
35
4359.1.11 by Celso Providelo
consolidating NascentUpload helper functions for doctests.
36
def getUploadForSource(upload_path):
7961.3.1 by Julian Edwards
Give karma for uploads in Soyuz.
37
    """Return a NascentUpload object for a source."""
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
38
    policy = getPolicy(name='sync', distro='ubuntu', distroseries='hoary')
11204.5.14 by William Grant
Remove conditional from NascentUpload.__init__. NU.from_changesfile_path should now be used if the ChangesFile must be created too.
39
    return NascentUpload.from_changesfile_path(
12070.1.37 by Tim Penhey
Remove mock_logger and mock_logger_quiet.
40
        datadir(upload_path), policy, DevNullLogger())
11204.5.14 by William Grant
Remove conditional from NascentUpload.__init__. NU.from_changesfile_path should now be used if the ChangesFile must be created too.
41
4359.1.11 by Celso Providelo
consolidating NascentUpload helper functions for doctests.
42
7961.3.1 by Julian Edwards
Give karma for uploads in Soyuz.
43
def getPPAUploadForSource(upload_path, ppa):
44
    """Return a NascentUpload object for a PPA source."""
45
    policy = getPolicy(name='insecure', distro='ubuntu', distroseries='hoary')
46
    policy.archive = ppa
11204.5.14 by William Grant
Remove conditional from NascentUpload.__init__. NU.from_changesfile_path should now be used if the ChangesFile must be created too.
47
    return NascentUpload.from_changesfile_path(
12070.1.37 by Tim Penhey
Remove mock_logger and mock_logger_quiet.
48
        datadir(upload_path), policy, DevNullLogger())
11204.5.14 by William Grant
Remove conditional from NascentUpload.__init__. NU.from_changesfile_path should now be used if the ChangesFile must be created too.
49
4359.1.12 by Celso Providelo
style and typo fixes.
50
4359.1.11 by Celso Providelo
consolidating NascentUpload helper functions for doctests.
51
def getUploadForBinary(upload_path):
8213.5.1 by Celso Providelo
First take for supporting DDEBs uploads in Soyuz. Bug #285205.
52
    """Return a NascentUpload object for binaries."""
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
53
    policy = getPolicy(name='sync', distro='ubuntu', distroseries='hoary')
11426.1.4 by Guilherme Salgado
Replace the can_upload_* attributes of AbstractUploadPolicy with a single enum.
54
    policy.accepted_type = ArchiveUploadType.BINARY_ONLY
11204.5.14 by William Grant
Remove conditional from NascentUpload.__init__. NU.from_changesfile_path should now be used if the ChangesFile must be created too.
55
    return NascentUpload.from_changesfile_path(
12070.1.37 by Tim Penhey
Remove mock_logger and mock_logger_quiet.
56
        datadir(upload_path), policy, DevNullLogger())
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
57
4359.1.12 by Celso Providelo
style and typo fixes.
58
4359.1.10 by Celso Providelo
clear test loader setup, specially dealing with test globals (r=flacoste).
59
def testGlobalsSetup(test):
60
    """Inject useful helper functions in tests globals.
61
62
    We can use the getUpload* without unnecessary imports.
63
    """
7961.3.1 by Julian Edwards
Give karma for uploads in Soyuz.
64
    import_public_test_keys()
5788.1.2 by James Henstridge
Fix up modules that were importing testing infrastructure from
65
    setGlobs(test)
4359.1.11 by Celso Providelo
consolidating NascentUpload helper functions for doctests.
66
    test.globs['getUploadForSource'] = getUploadForSource
67
    test.globs['getUploadForBinary'] = getUploadForBinary
7961.3.1 by Julian Edwards
Give karma for uploads in Soyuz.
68
    test.globs['getPPAUploadForSource'] = getPPAUploadForSource
4359.1.10 by Celso Providelo
clear test loader setup, specially dealing with test globals (r=flacoste).
69
4359.1.12 by Celso Providelo
style and typo fixes.
70
4359.1.10 by Celso Providelo
clear test loader setup, specially dealing with test globals (r=flacoste).
71
def prepareHoaryForUploads(test):
72
    """Prepare ubuntu/hoary to receive uploads.
73
6892.4.1 by Celso Providelo
Fixing bug #108104 (Better message for conflicting uploaded files). Also fixing lint issues in archiveuploader doctests.
74
    Ensure ubuntu/hoary is ready to receive and build new uploads in
75
    the RELEASE pocket (they are auto-overridden to the 'universe'
76
    component).
4359.1.10 by Celso Providelo
clear test loader setup, specially dealing with test globals (r=flacoste).
77
    """
78
    ubuntu = getUtility(IDistributionSet)['ubuntu']
79
    hoary = ubuntu['hoary']
6892.4.1 by Celso Providelo
Fixing bug #108104 (Better message for conflicting uploaded files). Also fixing lint issues in archiveuploader doctests.
80
81
    # Allow uploads to the universe component.
5584.3.5 by Julian Edwards
Add universe as a component to hoary where tests need it.
82
    universe = getUtility(IComponentSet)['universe']
83
    ComponentSelection(distroseries=hoary, component=universe)
6892.4.1 by Celso Providelo
Fixing bug #108104 (Better message for conflicting uploaded files). Also fixing lint issues in archiveuploader doctests.
84
6269.10.12 by Celso Providelo
Fixing test failures.
85
    # Create a fake hoary/i386 chroot.
86
    fake_chroot = LibraryFileAlias.get(1)
87
    hoary['i386'].addOrUpdateChroot(fake_chroot)
88
5584.3.5 by Julian Edwards
Add universe as a component to hoary where tests need it.
89
    LaunchpadZopelessLayer.txn.commit()
4359.1.10 by Celso Providelo
clear test loader setup, specially dealing with test globals (r=flacoste).
90
4359.1.12 by Celso Providelo
style and typo fixes.
91
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
92
def setUp(test):
93
    """Setup a typical nascentupload test environment.
94
95
    Use 'uploader' datebase user in a LaunchpadZopelessLayer transaction.
96
    Log in as a Launchpad admin (foo.bar@canonical.com).
4359.1.10 by Celso Providelo
clear test loader setup, specially dealing with test globals (r=flacoste).
97
    Setup test globals and prepare hoary for uploads
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
98
    """
99
    login('foo.bar@canonical.com')
4359.1.10 by Celso Providelo
clear test loader setup, specially dealing with test globals (r=flacoste).
100
    testGlobalsSetup(test)
101
    prepareHoaryForUploads(test)
5584.3.5 by Julian Edwards
Add universe as a component to hoary where tests need it.
102
    LaunchpadZopelessLayer.switchDbUser('uploader')
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
103
4359.1.12 by Celso Providelo
style and typo fixes.
104
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
105
def tearDown(test):
106
    logout()
107
4359.1.12 by Celso Providelo
style and typo fixes.
108
4359.1.9 by Celso Providelo
more review comments (r=flacoste).
109
def test_suite():
7864.3.3 by Celso Providelo
Spliting, re-writing and testing procedure for parsing upload paths.
110
    suite = unittest.TestSuite()
111
    tests_dir = os.path.dirname(os.path.realpath(__file__))
112
113
    filenames = [
114
        filename
115
        for filename in os.listdir(tests_dir)
116
        if filename.lower().endswith('.txt')
117
        ]
118
119
    for filename in sorted(filenames):
120
        test = LayeredDocFileSuite(
121
            filename, setUp=setUp, tearDown=tearDown,
122
            layer=LaunchpadZopelessLayer)
123
        suite.addTest(test)
124
125
    return suite