2
# Copyright (C) 2015 Canonical
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.
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.
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/>.
18
"""Full-stack functional tests for the web application."""
21
from testtools.matchers import Equals
23
import adt_request_proxy
26
class FunctionalWebAppTests(testtools.TestCase):
28
"""A suite of functional tests for the web app.
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.
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
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()
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):
52
self.expectThat(resp.status_code, Equals(405))
54
self.fail("Unknown method %s" % method)
56
def test_v1_test_endpoint_is_POST_only(self):
57
self.assertEndpointDisallowsMethods(
59
['GET', 'PATCH', 'DELETE']
62
# TODO: add more tests here ;)