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).
8
from unittest import TestCase
10
from piston_mini_client import PistonAPI
11
from piston_mini_client.consts import DISABLE_SSL_VALIDATION_ENVVAR
14
class DentistAPI(PistonAPI):
15
default_service_root = 'http://localhost:12345'
16
def appointments(self):
17
self._get('/appointments')
20
class DisableSSLVerificationTestCase(TestCase):
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]
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
32
@patch('httplib2.Http')
33
def test_dont_disable(self, mock_http):
36
self.assertTrue('disable_ssl_certificate_validation' not in
37
mock_http.call_args[1])
39
@patch('httplib2.Http')
40
def test_disable_via_constructor(self, mock_http):
41
api = DentistAPI(disable_ssl_validation=True)
43
self.assertTrue('disable_ssl_certificate_validation' in
44
mock_http.call_args[1])
46
@patch('httplib2.Http')
47
def test_disable_via_envvar(self, mock_http):
48
os.environ[DISABLE_SSL_VALIDATION_ENVVAR] = '1'
51
self.assertTrue('disable_ssl_certificate_validation' in
52
mock_http.call_args[1])