| 1 |
# Copyright 2008, 2011 Canonical Ltd. |
| 2 |
|
| 3 |
# This file is part of launchpadlib. |
| 4 |
# |
| 5 |
# launchpadlib is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as |
| 7 |
# published by the Free Software Foundation, either version 3 of the |
| 8 |
# License, or (at your option) any later version. |
| 9 |
# |
| 10 |
# launchpadlib is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public |
| 16 |
# License along with launchpadlib. If not, see |
| 17 |
# <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
"""Resources for use in unit tests with the C{testresources} module.""" |
| 20 |
|
| •21 |
# Using the backport of importlib.resources for Python 3.8 |
| 22 |
try: |
| 23 |
from importlib.resources import files |
| 24 |
except ImportError: |
| 25 |
from importlib_resources import files |
| 26 |
|
| 27 |
from testresources import TestResource |
| 28 |
|
| 29 |
from wadllib.application import Application |
| 30 |
|
| 31 |
from launchpadlib.testing.launchpad import FakeLaunchpad |
| 32 |
|
| 33 |
|
| 34 |
launchpad_testing_application = None |
| 35 |
|
| 36 |
|
| 37 |
def get_application(): |
| 38 |
"""Get or create a WADL application for testing Launchpad. |
| 39 |
|
| 40 |
Note that this uses the Launchpad v1.0 WADL bundled with launchpadlib for |
| 41 |
testing purposes. For your own application, you might want to construct |
| 42 |
an L{Application} object directly, giving it your own WADL. |
| 43 |
""" |
| 44 |
global launchpad_testing_application |
| 45 |
if launchpad_testing_application is None: |
| 46 |
markup_url = "https://api.launchpad.net/1.0/" |
| •47 |
markup = ( |
| 48 |
files("launchpadlib.testing") |
| 49 |
.joinpath("launchpad-wadl.xml") |
| 50 |
.read_bytes() |
| 51 |
) |
| 52 |
launchpad_testing_application = Application(markup_url, markup) |
| 53 |
return launchpad_testing_application |
| 54 |
|
| 55 |
|
| 56 |
class FakeLaunchpadResource(TestResource): |
| 57 |
def make(self, dependency_resources): |
| 58 |
return FakeLaunchpad( |
| 59 |
application=Application( |
| 60 |
"https://api.example.com/testing/", |
| •61 |
files("launchpadlib.testing") |
| 62 |
.joinpath("testing-wadl.xml") |
| 63 |
.read_bytes(), |
| 64 |
) |
| 65 |
) |