~ubuntu-branches/ubuntu/trusty/piston-mini-client/trusty-proposed

« back to all changes in this revision

Viewing changes to piston_mini_client/tests/test_auth.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-08-11 17:26:42 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20110811172642-pwbja8hb8u0lvy16
Tags: 0.5+bzr41-0ubuntu1
new bzr snapshot that supports overriding the httplib2
signature checks

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
3
# GNU Lesser General Public License version 3 (see the file LICENSE).
 
4
 
 
5
from piston_mini_client.auth import OAuthAuthorizer, BasicAuthorizer
 
6
from unittest import TestCase
 
7
 
 
8
class BasicAuthorizerTestCase(TestCase):
 
9
    def test_sign_request(self):
 
10
        auth = BasicAuthorizer(username='foo', password='bar')
 
11
        url = 'http://example.com/api'
 
12
        method = 'GET'
 
13
        body = ''
 
14
        headers = {}
 
15
        auth.sign_request(url=url, method='GET', body='', headers=headers)
 
16
        self.assertTrue('Authorization' in headers)
 
17
        self.assertTrue(headers['Authorization'].startswith('Basic '))
 
18
 
 
19
class OAuthAuthorizerTestCase(TestCase):
 
20
    def test_sign_request(self):
 
21
        auth = OAuthAuthorizer('tkey', 'tsecret', 'ckey', 'csecret')
 
22
        url = 'http://example.com/api'
 
23
        method = 'GET'
 
24
        body = ''
 
25
        headers = {}
 
26
        auth.sign_request(url=url, method='GET', body='', headers=headers)
 
27
        self.assertTrue('Authorization' in headers)
 
28
        self.assertTrue(headers['Authorization'].startswith('OAuth '))