~canonical-ci-engineering/adt-request-proxy/trunk

« back to all changes in this revision

Viewing changes to adt_request_proxy/tests/test_functional.py

  • Committer: Thomi Richards
  • Date: 2015-03-10 20:41:29 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: thomi.richards@canonical.com-20150310204129-18r5snvzgfe0p7do
Feedback from code review.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# adt-request-proxy
 
2
# Copyright (C) 2015 Canonical
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation, either version 3 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
 
 
18
"""Full-stack functional tests for the web application."""
 
19
 
 
20
import testtools
 
21
from testtools.matchers import Equals
 
22
 
 
23
import adt_request_proxy
 
24
 
 
25
 
 
26
class FunctionalWebAppTests(testtools.TestCase):
 
27
 
 
28
    """A suite of functional tests for the web app.
 
29
 
 
30
    Tests are reasonably simple to write: 'self.client' is a
 
31
    'werkzeug.test.Client', and can make get/post etc calls. Query response
 
32
    objects to make sure you got what you expected.
 
33
 
 
34
    A few things still need to be done however: for testing, we want to tweak
 
35
    the queues requests end up on, since we (probably) want these tests to
 
36
    run on production deployments without the adt-cloud-worker picking up our
 
37
    test requests.
 
38
 
 
39
    """
 
40
 
 
41
    def setUp(self):
 
42
        super().setUp()
 
43
        self.server_app = adt_request_proxy.create_flask_app()
 
44
        self.server_app.config['TESTING'] = True
 
45
        self.client = self.server_app.test_client()
 
46
 
 
47
    def assertEndpointDisallowsMethods(self, endpoint, methods):
 
48
        for method in methods:
 
49
            fn = getattr(self.client, method.lower(), None)
 
50
            if fn and callable(fn):
 
51
                resp = fn(endpoint)
 
52
                self.expectThat(resp.status_code, Equals(405))
 
53
            else:
 
54
                self.fail("Unknown method %s" % method)
 
55
 
 
56
    def test_v1_test_endpoint_is_POST_only(self):
 
57
        self.assertEndpointDisallowsMethods(
 
58
            '/v1/test',
 
59
            ['GET', 'PATCH', 'DELETE']
 
60
        )
 
61
 
 
62
    # TODO: add more tests here ;)