~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Copyright 2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Test the code test helpers found in helpers.py."""

__metaclass__ = type

from datetime import datetime, timedelta
import pytz

from zope.component import getUtility

from canonical.testing.layers import DatabaseFunctionalLayer

from lp.code.interfaces.branchcollection import IAllBranches
from lp.code.tests.helpers import make_project_cloud_data
from lp.registry.interfaces.product import IProductSet
from lp.testing import TestCaseWithFactory


class TestMakeProjectCloudData(TestCaseWithFactory):
    # Make sure that make_project_cloud_data works.

    layer = DatabaseFunctionalLayer

    def test_single_project(self):
        # Make a single project with one commit from one person.
        now = datetime.now(pytz.UTC)
        commit_time = now - timedelta(days=2)
        make_project_cloud_data(self.factory, [
                ('fooix', 1, 1, commit_time),
                ])
        # Make sure we have a new project called fooix.
        fooix = getUtility(IProductSet).getByName('fooix')
        self.assertIsNot(None, fooix)
        # There should be one branch with one commit.
        [branch] = list(
            getUtility(IAllBranches).inProduct(fooix).getBranches(
                eager_load=False))
        self.assertEqual(1, branch.revision_count)
        self.assertEqual(commit_time, branch.getTipRevision().revision_date)