|
11381
by Benji York
re-apply check-in-wadl branch |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Tests for the checked-in WADL."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
import os.path |
|
9 |
import pkg_resources |
|
10 |
import unittest |
|
11 |
||
12 |
from zope.component import getUtility |
|
13 |
||
14 |
from canonical.launchpad.rest.wadl import generate_wadl, generate_html |
|
15 |
from canonical.launchpad.systemhomes import WebServiceApplication |
|
16 |
from canonical.testing import LaunchpadFunctionalLayer |
|
17 |
from lazr.restful.interfaces import IWebServiceConfiguration |
|
18 |
||
19 |
||
20 |
class TestCheckedInWadlAndDocs(unittest.TestCase): |
|
|
11382
by Benji York
remove devel versions, ignore them, and make tests not inspect them |
21 |
"""As an optimization and safety net we check in some web service files
|
|
11381
by Benji York
re-apply check-in-wadl branch |
22 |
|
|
11382
by Benji York
remove devel versions, ignore them, and make tests not inspect them |
23 |
The optimization is that it takes less time to build because the non-devel
|
|
11383
by Benji York
fix typo |
24 |
WADL files and HTML documentation don't have to be regenerated. It is a
|
|
11382
by Benji York
remove devel versions, ignore them, and make tests not inspect them |
25 |
safety net because it is our policy (as of the time of this writing) that
|
26 |
the non-devel APIs should not change (even in backward-compatible ways),
|
|
27 |
therefore the WADL files describing the APIs -- and generated from
|
|
28 |
descriptions of the APIs -- should not change either.
|
|
|
11381
by Benji York
re-apply check-in-wadl branch |
29 |
|
30 |
If these tests are failing and you just changed the web service, you
|
|
|
11382
by Benji York
remove devel versions, ignore them, and make tests not inspect them |
31 |
probably need to add version specifiers to your changes to limit their scope.
|
32 |
||
33 |
If you fixed a bug in a non-devel version of the web service API, then you
|
|
34 |
will need to regenerate the WADL and check it in. At the time of this
|
|
|
11381
by Benji York
re-apply check-in-wadl branch |
35 |
writing, this is the command to regenerate the files (copy pastable):
|
36 |
||
37 |
LPCONFIG=development bin/py ./utilities/create-lp-wadl-and-apidoc.py \
|
|
38 |
"lib/canonical/launchpad/apidoc/wadl-development-%(version)s.xml" --force
|
|
39 |
||
|
11382
by Benji York
remove devel versions, ignore them, and make tests not inspect them |
40 |
You could also delete the offending files and re-run make.
|
|
11381
by Benji York
re-apply check-in-wadl branch |
41 |
"""
|
42 |
||
43 |
layer = LaunchpadFunctionalLayer |
|
44 |
||
45 |
def test_wadl(self): |
|
46 |
# Verify that the generated WADL matches that which is checked in.
|
|
47 |
config = getUtility(IWebServiceConfiguration) |
|
48 |
for version in config.active_versions: |
|
|
11382
by Benji York
remove devel versions, ignore them, and make tests not inspect them |
49 |
if version == 'devel': |
50 |
continue
|
|
|
11381
by Benji York
re-apply check-in-wadl branch |
51 |
wadl_filename = WebServiceApplication.cachedWADLPath( |
52 |
'development', version) |
|
53 |
wadl_on_disk = open(wadl_filename).read() |
|
54 |
generated_wadl = generate_wadl(version) |
|
55 |
self.assertEqual(wadl_on_disk, generated_wadl) |
|
56 |
||
57 |
def test_html(self): |
|
58 |
# Verify that the generated HTML matches that which is checked in.
|
|
59 |
config = getUtility(IWebServiceConfiguration) |
|
60 |
stylesheet = pkg_resources.resource_filename( |
|
61 |
'launchpadlib', 'wadl-to-refhtml.xsl') |
|
62 |
for version in config.active_versions: |
|
|
11382
by Benji York
remove devel versions, ignore them, and make tests not inspect them |
63 |
# only non-devel versions are frozen
|
64 |
if version == 'devel': |
|
65 |
continue
|
|
|
11381
by Benji York
re-apply check-in-wadl branch |
66 |
wadl_filename = WebServiceApplication.cachedWADLPath( |
67 |
'development', version) |
|
68 |
html_filename = os.path.join( |
|
69 |
os.path.dirname(wadl_filename), version + '.html') |
|
70 |
html_on_disk = open(html_filename).read() |
|
71 |
generated_html = generate_html(wadl_filename) |
|
72 |
||
73 |
assert generated_html, 'no HTML was generated' |
|
74 |
self.assertEqual(html_on_disk, generated_html) |