~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
# Copyright 2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Tests for registry errors."""


__metaclass__ = type


from httplib import (
    BAD_REQUEST,
    CONFLICT,
    FORBIDDEN,
    UNAUTHORIZED,
    )

from lp.registry.errors import (
    CannotTransitionToCountryMirror,
    DeleteSubscriptionError,
    DistroSeriesDifferenceError,
    JoinNotAllowed,
    NameAlreadyTaken,
    OpenTeamLinkageError,
    PPACreationError,
    PrivatePersonLinkageError,
    TeamMembershipTransitionError,
    TeamSubscriptionPolicyError,
    UserCannotChangeMembershipSilently,
    UserCannotSubscribePerson,
    )
from lp.testing import TestCase
from lp.testing.layers import FunctionalLayer
from lp.testing.views import create_webservice_error_view


class TestWebServiceErrors(TestCase):
    """ Test that errors are correctly mapped to HTTP status codes."""

    layer = FunctionalLayer

    def test_OpenTeamLinkageError_forbidden(self):
        error_view = create_webservice_error_view(OpenTeamLinkageError())
        self.assertEqual(FORBIDDEN, error_view.status)

    def test_PersonLinkageError_forbidden(self):
        error_view = create_webservice_error_view(PrivatePersonLinkageError())
        self.assertEqual(FORBIDDEN, error_view.status)

    def test_PPACreationError_bad_request(self):
        error_view = create_webservice_error_view(PPACreationError())
        self.assertEqual(BAD_REQUEST, error_view.status)

    def test_JoinNotAllowed_bad_request(self):
        error_view = create_webservice_error_view(JoinNotAllowed())
        self.assertEqual(BAD_REQUEST, error_view.status)

    def test_TeamSubscriptionPolicyError_bad_request(self):
        error_view = create_webservice_error_view(
            TeamSubscriptionPolicyError())
        self.assertEqual(BAD_REQUEST, error_view.status)

    def test_TeamMembershipTransitionError_bad_request(self):
        error_view = create_webservice_error_view(
            TeamMembershipTransitionError())
        self.assertEqual(BAD_REQUEST, error_view.status)

    def test_DistroSeriesDifferenceError_bad_request(self):
        error_view = create_webservice_error_view(
            DistroSeriesDifferenceError())
        self.assertEqual(BAD_REQUEST, error_view.status)

    def test_DeleteSubscriptionError_bad_request(self):
        error_view = create_webservice_error_view(DeleteSubscriptionError())
        self.assertEqual(BAD_REQUEST, error_view.status)

    def test_UserCannotSubscribePerson_bad_request(self):
        error_view = create_webservice_error_view(UserCannotSubscribePerson())
        self.assertEqual(UNAUTHORIZED, error_view.status)

    def test_CannotTransitionToCountryMirror_bad_request(self):
        error_view = create_webservice_error_view(
            CannotTransitionToCountryMirror())
        self.assertEqual(BAD_REQUEST, error_view.status)

    def test_UserCannotChangeMembershipSilently_bad_request(self):
        error_view = create_webservice_error_view(
            UserCannotChangeMembershipSilently())
        self.assertEqual(UNAUTHORIZED, error_view.status)

    def test_NameAlreadyTaken_bad_request(self):
        error_view = create_webservice_error_view(NameAlreadyTaken())
        self.assertEqual(CONFLICT, error_view.status)