~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/tests/test_distributionsourcepackage.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-21 14:28:02 UTC
  • mfrom: (14006 devel)
  • mto: This revision was merged to the branch mainline in revision 14010.
  • Revision ID: jelmer@canonical.com-20110921142802-7ggkc204igsy532w
MergeĀ lp:launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from zope.component import getUtility
10
10
from zope.security.proxy import removeSecurityProxy
11
11
 
 
12
from canonical.launchpad.interfaces.lpstorm import IStore
12
13
from canonical.testing.layers import (
13
14
    DatabaseFunctionalLayer,
14
15
    LaunchpadZopelessLayer,
15
16
    )
16
17
from lp.registry.interfaces.distribution import IDistributionSet
 
18
from lp.registry.model.distributionsourcepackage import (
 
19
    DistributionSourcePackage,
 
20
    DistributionSourcePackageInDatabase,
 
21
    )
17
22
from lp.registry.model.karma import KarmaTotalCache
18
23
from lp.soyuz.enums import PackagePublishingStatus
19
24
from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
37
42
        dsp = naked_distribution.getSourcePackage(name='pmount')
38
43
        self.assertEqual(None, dsp.summary)
39
44
 
 
45
    def test_ensure_spph_creates_a_dsp_in_db(self):
 
46
        # The DSP.ensure() class method creates a persistent instance
 
47
        # if one does not exist.
 
48
        spph = self.factory.makeSourcePackagePublishingHistory()
 
49
        spph_dsp = spph.sourcepackagerelease.distrosourcepackage
 
50
        DistributionSourcePackage.ensure(spph)
 
51
        new_dsp = DistributionSourcePackage._get(
 
52
            spph_dsp.distribution, spph_dsp.sourcepackagename)
 
53
        self.assertIsNot(None, new_dsp)
 
54
        self.assertIsNot(spph_dsp, new_dsp)
 
55
        self.assertEqual(spph_dsp.distribution, new_dsp.distribution)
 
56
        self.assertEqual(
 
57
            spph_dsp.sourcepackagename, new_dsp.sourcepackagename)
 
58
 
 
59
    def test_ensure_spph_dsp_in_db_exists(self):
 
60
        # The DSP.ensure() class method does not create duplicate
 
61
        # persistent instances; it skips the query to create the DSP.
 
62
        store = IStore(DistributionSourcePackageInDatabase)
 
63
        start_count = store.find(DistributionSourcePackageInDatabase).count()
 
64
        spph = self.factory.makeSourcePackagePublishingHistory()
 
65
        DistributionSourcePackage.ensure(spph)
 
66
        new_count = store.find(DistributionSourcePackageInDatabase).count()
 
67
        self.assertEqual(start_count + 1, new_count)
 
68
        final_count = store.find(DistributionSourcePackageInDatabase).count()
 
69
        self.assertEqual(new_count, final_count)
 
70
 
 
71
    def test_ensure_spph_does_not_create_dsp_in_db_non_primary_archive(self):
 
72
        # The DSP.ensure() class method creates a persistent instance
 
73
        # if one does not exist.
 
74
        archive = self.factory.makeArchive()
 
75
        spph = self.factory.makeSourcePackagePublishingHistory(
 
76
            archive=archive)
 
77
        spph_dsp = spph.sourcepackagerelease.distrosourcepackage
 
78
        DistributionSourcePackage.ensure(spph)
 
79
        new_dsp = DistributionSourcePackage._get(
 
80
            spph_dsp.distribution, spph_dsp.sourcepackagename)
 
81
        self.assertIs(None, new_dsp)
 
82
 
 
83
    def test_ensure_suitesourcepackage_creates_a_dsp_in_db(self):
 
84
        # The DSP.ensure() class method creates a persistent instance
 
85
        # if one does not exist.
 
86
        sourcepackage = self.factory.makeSourcePackage()
 
87
        DistributionSourcePackage.ensure(sourcepackage=sourcepackage)
 
88
        new_dsp = DistributionSourcePackage._get(
 
89
            sourcepackage.distribution, sourcepackage.sourcepackagename)
 
90
        self.assertIsNot(None, new_dsp)
 
91
        self.assertEqual(sourcepackage.distribution, new_dsp.distribution)
 
92
        self.assertEqual(
 
93
            sourcepackage.sourcepackagename, new_dsp.sourcepackagename)
 
94
 
 
95
    def test_delete_without_dsp_in_db(self):
 
96
        # Calling delete() on a DSP without persistence returns False.
 
97
        dsp = self.factory.makeDistributionSourcePackage()
 
98
        self.assertFalse(dsp.delete())
 
99
 
 
100
    def test_delete_with_dsp_in_db_with_history(self):
 
101
        # Calling delete() on a persistent DSP with SPPH returns False.
 
102
        # Once a package is uploaded, it cannot be deleted.
 
103
        spph = self.factory.makeSourcePackagePublishingHistory()
 
104
        dsp = spph.sourcepackagerelease.distrosourcepackage
 
105
        DistributionSourcePackage.ensure(spph=spph)
 
106
        transaction.commit()
 
107
        self.assertFalse(dsp.delete())
 
108
 
 
109
    def test_delete_with_dsp_in_db_without_history(self):
 
110
        # Calling delete() on a persistent DSP without SPPH returns True.
 
111
        # A package without history was a mistake.
 
112
        sp = self.factory.makeSourcePackage()
 
113
        DistributionSourcePackage.ensure(sourcepackage=sp)
 
114
        transaction.commit()
 
115
        dsp = sp.distribution_sourcepackage
 
116
        self.assertTrue(dsp.delete())
 
117
 
40
118
 
41
119
class TestDistributionSourcePackageFindRelatedArchives(TestCaseWithFactory):
42
120