~launchpad-pqm/launchpad/devel

11435.5.6 by Tim Penhey
A test for the helper, and fix the helper.
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Test the code test helpers found in helpers.py."""
5
6
__metaclass__ = type
7
8
from datetime import datetime, timedelta
9
import pytz
10
11
from zope.component import getUtility
12
11666.3.5 by Curtis Hovey
Import layers from canonical.testing.layers.
13
from canonical.testing.layers import DatabaseFunctionalLayer
11435.5.6 by Tim Penhey
A test for the helper, and fix the helper.
14
15
from lp.code.interfaces.branchcollection import IAllBranches
16
from lp.code.tests.helpers import make_project_cloud_data
17
from lp.registry.interfaces.product import IProductSet
18
from lp.testing import TestCaseWithFactory
19
20
21
class TestMakeProjectCloudData(TestCaseWithFactory):
22
    # Make sure that make_project_cloud_data works.
23
24
    layer = DatabaseFunctionalLayer
25
26
    def test_single_project(self):
27
        # Make a single project with one commit from one person.
28
        now = datetime.now(pytz.UTC)
29
        commit_time = now - timedelta(days=2)
30
        make_project_cloud_data(self.factory, [
31
                ('fooix', 1, 1, commit_time),
32
                ])
33
        # Make sure we have a new project called fooix.
34
        fooix = getUtility(IProductSet).getByName('fooix')
35
        self.assertIsNot(None, fooix)
36
        # There should be one branch with one commit.
37
        [branch] = list(
12504.1.3 by Robert Collins
Reject reversion of this branch on trunk.
38
            getUtility(IAllBranches).inProduct(fooix).getBranches(
39
                eager_load=False))
11435.5.6 by Tim Penhey
A test for the helper, and fix the helper.
40
        self.assertEqual(1, branch.revision_count)
41
        self.assertEqual(commit_time, branch.getTipRevision().revision_date)