~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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Webservice unit tests related to Launchpad Bugs."""

__metaclass__ = type

from canonical.launchpad.testing.pages import LaunchpadWebServiceCaller
from canonical.testing.layers import DatabaseFunctionalLayer
from lp.testing import (
    person_logged_in,
    TestCaseWithFactory,
    )


class TestOmitTargetedParameter(TestCaseWithFactory):
    """Test all values for the omit_targeted search parameter."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestOmitTargetedParameter, self).setUp()
        self.owner = self.factory.makePerson()
        with person_logged_in(self.owner):
            self.distro = self.factory.makeDistribution(name='mebuntu')
        self.release = self.factory.makeDistroRelease(
            name='inkanyamba', distribution=self.distro)
        self.bug = self.factory.makeBugTask(target=self.release)
        self.webservice = LaunchpadWebServiceCaller(
            'launchpad-library', 'salgado-change-anything')

    def test_omit_targeted_old_default_true(self):
        response = self.webservice.named_get('/mebuntu/inkanyamba',
            'searchTasks', api_version='1.0').jsonBody()
        self.assertEqual(response['total_size'], 0)

    def test_omit_targeted_new_default_false(self):
        response = self.webservice.named_get('/mebuntu/inkanyamba',
            'searchTasks', api_version='devel').jsonBody()
        self.assertEqual(response['total_size'], 1)


class TestLinkedBlueprintsParameter(TestCaseWithFactory):
    """Tests for the linked_blueprints parameter."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestLinkedBlueprintsParameter, self).setUp()
        self.owner = self.factory.makePerson()
        with person_logged_in(self.owner):
            self.product = self.factory.makeProduct()
        self.bug = self.factory.makeBugTask(target=self.product)
        self.webservice = LaunchpadWebServiceCaller(
            'launchpad-library', 'salgado-change-anything')

    def search(self, api_version, **kwargs):
        return self.webservice.named_get(
            '/%s' % self.product.name, 'searchTasks',
            api_version=api_version, **kwargs).jsonBody()

    def test_linked_blueprints_in_devel(self):
        # Searching for linked Blueprints works in the devel API.
        self.search("devel", linked_blueprints="Show all bugs")

    def test_linked_blueprints_in_devel_2(self):
        # The linked_blueprints is considered. An error is returned if its
        # value is not a member of BugBlueprintSearch.
        self.assertRaises(
            ValueError, self.search, "devel",
            linked_blueprints="Teabags!")

    def test_linked_blueprints_not_in_1_0(self):
        # Searching for linked Blueprints does not work in the 1.0 API. No
        # validation is performed for the linked_blueprints parameter, and
        # thus no error is returned when we pass rubbish.
        self.search("1.0", linked_blueprints="Teabags!")

    def test_linked_blueprints_not_in_beta(self):
        # Searching for linked Blueprints does not work in the beta API. No
        # validation is performed for the linked_blueprints parameter, and
        # thus no error is returned when we pass rubbish.
        self.search("beta", linked_blueprints="Teabags!")