Debian Codegraph @

src/launchpadlib/testing/resources.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 from pkg_resources import resource_string
22
23 from testresources import TestResource
24
25 from wadllib.application import Application
26
27 from launchpadlib.testing.launchpad import FakeLaunchpad
28
29
30 launchpad_testing_application = None
31
32
33 def get_application():
34 """Get or create a WADL application for testing Launchpad.
35
36 Note that this uses the Launchpad v1.0 WADL bundled with launchpadlib for
37 testing purposes. For your own application, you might want to construct
38 an L{Application} object directly, giving it your own WADL.
39 """
40 global launchpad_testing_application
41 if launchpad_testing_application is None:
42 markup_url = "https://api.launchpad.net/1.0/"
43 markup = resource_string("launchpadlib.testing", "launchpad-wadl.xml")
44 launchpad_testing_application = Application(markup_url, markup)
45 return launchpad_testing_application
46
47
48 class FakeLaunchpadResource(TestResource):
49 def make(self, dependency_resources):
50 return FakeLaunchpad(
51 application=Application(
52 "https://api.example.com/testing/",
53 resource_string("launchpadlib.testing", "testing-wadl.xml"),
54 )
55 )