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
|
# Copyright 2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for answers's custom publications."""
__metaclass__ = type
import StringIO
from canonical.config import config
from lp.layers import WebServiceLayer
from canonical.testing.layers import FunctionalLayer
from lp.answers.publisher import (
AnswersBrowserRequest,
AnswersLayer,
)
from lp.testing import TestCase
from lp.testing.publication import get_request_and_publication
class TestRegistration(TestCase):
"""Answers' publication customizations are installed correctly."""
layer = FunctionalLayer
def test_answers_request_provides_answers_layer(self):
# The request constructed for requests to the answers hostname
# provides AnswersLayer.
request, publication = get_request_and_publication(
host=config.vhost.answers.hostname)
self.assertProvides(request, AnswersLayer)
def test_answers_host_has_api(self):
# Requests to /api on the answers domain are treated as web service
# requests.
request, publication = get_request_and_publication(
host=config.vhost.answers.hostname,
extra_environment={'PATH_INFO': '/api/1.0'})
# XXX MichaelHudson, 2010-07-20, bug=607664: WebServiceLayer only
# actually provides WebServiceLayer in the sense of verifyObject after
# traversal has started.
self.assertTrue(WebServiceLayer.providedBy(request))
def test_response_should_vary_based_on_language(self):
# Responses to requests to answers pages have the 'Vary' header set to
# include Accept-Language.
request = AnswersBrowserRequest(StringIO.StringIO(''), {})
self.assertEquals(
request.response.getHeader('Vary'),
'Cookie, Authorization, Accept-Language')
|