~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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright 2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Tests for webservice features across Launchpad."""

__metaclass__ = type


from lazr.restful.interfaces import IFieldHTMLRenderer
from lazr.restful.utils import get_current_web_service_request
from zope.component import getMultiAdapter

from canonical.launchpad.testing.pages import LaunchpadWebServiceCaller
from canonical.testing.layers import DatabaseFunctionalLayer
from lp.app.browser.tales import format_link
from lp.registry.interfaces.product import IProduct
from lp.testing import TestCaseWithFactory


class TestXHTMLRepresentations(TestCaseWithFactory):

    layer = DatabaseFunctionalLayer

    def test_person(self):
        # Test the XHTML representation of a person.
        eric = self.factory.makePerson()
        # We need something that has an IPersonChoice, a project will do.
        product = self.factory.makeProduct(owner=eric)
        field = IProduct['owner']
        request = get_current_web_service_request()
        renderer = getMultiAdapter(
            (product, field, request), IFieldHTMLRenderer)
        # The representation of a person is the same as a tales
        # PersonFormatter.
        self.assertEqual(format_link(eric), renderer(eric))

    def test_text(self):
        # Test the XHTML representation of a text field.
        text = u'\N{SNOWMAN} snowman@example.com bug 1'
        # We need something that has an IPersonChoice, a project will do.
        product = self.factory.makeProduct()
        field = IProduct['description']
        request = get_current_web_service_request()
        renderer = getMultiAdapter(
            (product, field, request), IFieldHTMLRenderer)
        # The representation is linkified html.
        self.assertEqual(
            u'<p>\N{SNOWMAN} snowman@example.com '
            '<a href="/bugs/1" class="bug-link">bug 1</a></p>',
            renderer(text))


class BaseMissingObjectWebService:
    """Base test of NotFound errors for top-level webservice objects."""

    layer = DatabaseFunctionalLayer
    object_type = None

    def test_object_not_found(self):
        """Missing top-level objects generate 404s but not OOPS."""
        webservice = LaunchpadWebServiceCaller(
            'launchpad-library', 'salgado-change-anything')
        response = webservice.get('/%s/123456789' % self.object_type)
        self.assertEqual(response.status, 404)
        self.assertEqual(response.getheader('x-lazr-oopsid'), None)


class TestMissingBranches(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice branches requests."""

    object_type = 'branches'


class TestMissingBugTrackers(
    BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice bug_trackers requests."""

    object_type = 'bug_trackers'


class TestMissingBugs(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice bugs requests."""

    object_type = 'bugs'


class TestMissingBuilders(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice builders requests."""

    object_type = 'builders'


class TestMissingCountries(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice countries requests."""

    object_type = 'countries'


class TestMissingCves(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice cves requests."""

    object_type = 'cves'


class TestMissingDistributions(
    BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice distributions requests."""

    object_type = 'distributions'


class TestMissingLanguages(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice launguages requests."""

    object_type = 'languages'


class TestMissingPackagesets(
    BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice packagesets requests."""

    object_type = 'packagesets'


class TestMissingPeople(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice branches requests."""

    object_type = 'people'


class TestMissingProjectGroups(
    BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice project_groups requests."""

    object_type = 'project_groups'


class TestMissingProjects(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice projects requests."""

    object_type = 'projects'


class TestMissingQuestions(BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice questions requests."""

    object_type = 'questions'


class TestMissingTemporaryBlobs(
    BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice temporary_blobs requests."""

    object_type = 'temporary_blobs'


class TestMissingTranslationGroups(
    BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice translation_groups requests."""

    object_type = 'translation_groups'


class TestMissingTranslationImportQueueEntries(
    BaseMissingObjectWebService, TestCaseWithFactory):
    """Test NotFound for webservice translation_import_queue_entries requests.
    """

    object_type = 'translation_import_queue_entries'