~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to tests/api/test_restclient.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mto: This revision was merged to the branch mainline in revision 67.
  • Revision ID: james.westby@ubuntu.com-20110211161811-n18dj9lde7dxqjzr
Tags: upstream-1.5.4
ImportĀ upstreamĀ versionĀ 1.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2010 Canonical Ltd.
2
 
#
3
 
# This program is free software: you can redistribute it and/or modify it
4
 
# under the terms of the GNU General Public License version 3, as published
5
 
# by the Free Software Foundation.
6
 
#
7
 
# This program is distributed in the hope that it will be useful, but
8
 
# WITHOUT ANY WARRANTY; without even the implied warranties of
9
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
10
 
# PURPOSE.  See the GNU General Public License for more details.
11
 
#
12
 
# You should have received a copy of the GNU General Public License along
13
 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 
 
15
 
import urllib2
16
 
from twisted.trial.unittest import TestCase
17
 
from ubuntuone.api.restclient import RestClient
18
 
from oauth import oauth
19
 
 
20
 
class FakedResponse(object):
21
 
    """A fake response."""
22
 
 
23
 
    def __init__(self, *args, **kwargs):
24
 
        self.args = args
25
 
        self.kwargs = kwargs
26
 
        self.read = lambda: '{"field": "value"}'
27
 
 
28
 
def return_a_fake_response(*args, **kwargs):
29
 
    """Create a fake urllib2 response."""
30
 
    return FakedResponse(*args, **kwargs)
31
 
 
32
 
class RestClientTest(TestCase):
33
 
    """Test the RestClient object."""
34
 
 
35
 
    def test_call(self):
36
 
        """Tests calling a REST API method."""
37
 
        self.patch(urllib2, 'urlopen', return_a_fake_response)
38
 
 
39
 
        url = 'https://one.ubuntu.com/api'
40
 
        rest_client = RestClient(url)
41
 
        result = rest_client.call(url, "https",
42
 
                                  oauth.OAuthConsumer('ubuntuone', 'hammertime'),
43
 
                                  oauth.OAuthToken.from_string('oauth_token_secret=12345678ABC&oauth_token=12345678ABC'))
44
 
        self.assertTrue(result.has_key('field'))
45
 
        self.assertTrue(result['field'] == 'value')