correctly mock packaged requests library

This commit is contained in:
Alan Hamlett 2015-08-11 12:15:35 -07:00
parent 8e8c0154d6
commit d36592e1c5

View file

@ -3,6 +3,7 @@
import logging
import unittest
from wakatime.packages.requests.models import Response
try:
from mock import patch
@ -12,20 +13,23 @@ except:
from wakatime.base import main
@patch('requests.post')
@patch('wakatime.packages.requests.adapters.HTTPAdapter.send')
class BaseTestCase(unittest.TestCase):
def setUp(self):
# disable logging while testing
logging.disable(logging.CRITICAL)
def test_help_contents(self, mock_post):
def test_help_contents(self, mock_requests):
with self.assertRaises(SystemExit):
args = ['', '--help']
retval = main(args)
self.assertEquals(retval, 0)
def test_argument_parsing(self, mock_post):
def test_argument_parsing(self, mock_requests):
response = Response()
response.status_code = 201
mock_requests.return_value = response
args = ['', '--file', 'tests/samples/emptyfile.txt', '--key', '123']
retval = main(args)
self.assertEquals(retval, 0)