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

« back to all changes in this revision

Viewing changes to piston_mini_client/tests/test_disable_ssl_check.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
import os
 
6
 
 
7
from mock import patch
 
8
from unittest import TestCase
 
9
 
 
10
from piston_mini_client import PistonAPI
 
11
from piston_mini_client.consts import DISABLE_SSL_VALIDATION_ENVVAR
 
12
 
 
13
 
 
14
class DentistAPI(PistonAPI):
 
15
    default_service_root = 'http://localhost:12345'
 
16
    def appointments(self):
 
17
        self._get('/appointments')
 
18
 
 
19
 
 
20
class DisableSSLVerificationTestCase(TestCase):
 
21
    def setUp(self):
 
22
        if DISABLE_SSL_VALIDATION_ENVVAR in os.environ:
 
23
            self.orig_disable_ssl = os.environ[DISABLE_SSL_VALIDATION_ENVVAR]
 
24
            del os.environ[DISABLE_SSL_VALIDATION_ENVVAR]
 
25
 
 
26
    def tearDown(self):
 
27
        if DISABLE_SSL_VALIDATION_ENVVAR in os.environ:
 
28
            del os.environ[DISABLE_SSL_VALIDATION_ENVVAR]
 
29
        if hasattr(self, 'orig_disable_ssl'):
 
30
            os.environ[DISABLE_SSL_VALIDATION_ENVVAR] = self.orig_disable_ssl
 
31
            
 
32
    @patch('httplib2.Http')
 
33
    def test_dont_disable(self, mock_http):
 
34
        api = DentistAPI()
 
35
 
 
36
        self.assertTrue('disable_ssl_certificate_validation' not in
 
37
            mock_http.call_args[1])
 
38
 
 
39
    @patch('httplib2.Http')
 
40
    def test_disable_via_constructor(self, mock_http):
 
41
        api = DentistAPI(disable_ssl_validation=True)
 
42
        
 
43
        self.assertTrue('disable_ssl_certificate_validation' in
 
44
            mock_http.call_args[1])
 
45
 
 
46
    @patch('httplib2.Http')
 
47
    def test_disable_via_envvar(self, mock_http):
 
48
        os.environ[DISABLE_SSL_VALIDATION_ENVVAR] = '1'
 
49
        api = DentistAPI()
 
50
        
 
51
        self.assertTrue('disable_ssl_certificate_validation' in
 
52
            mock_http.call_args[1])