2015-08-11 18:19:22 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import logging
|
2015-08-11 19:15:35 +00:00
|
|
|
from wakatime.packages.requests.models import Response
|
2015-08-11 18:19:22 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
from mock import patch
|
2015-08-11 21:53:35 +00:00
|
|
|
except ImportError:
|
2015-08-11 18:19:22 +00:00
|
|
|
from unittest.mock import patch
|
2015-08-11 21:53:35 +00:00
|
|
|
try:
|
|
|
|
# Python 2.6
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
# Python >= 2.7
|
|
|
|
import unittest
|
2015-08-11 18:19:22 +00:00
|
|
|
|
|
|
|
from wakatime.base import main
|
|
|
|
|
|
|
|
|
2015-08-11 19:15:35 +00:00
|
|
|
@patch('wakatime.packages.requests.adapters.HTTPAdapter.send')
|
2015-08-11 18:19:22 +00:00
|
|
|
class BaseTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
# disable logging while testing
|
|
|
|
logging.disable(logging.CRITICAL)
|
|
|
|
|
2015-08-11 19:15:35 +00:00
|
|
|
def test_help_contents(self, mock_requests):
|
2015-08-11 21:53:35 +00:00
|
|
|
args = ['', '--help']
|
2015-08-11 18:19:22 +00:00
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
retval = main(args)
|
|
|
|
self.assertEquals(retval, 0)
|
|
|
|
|
2015-08-11 19:15:35 +00:00
|
|
|
def test_argument_parsing(self, mock_requests):
|
|
|
|
response = Response()
|
|
|
|
response.status_code = 201
|
|
|
|
mock_requests.return_value = response
|
2015-08-11 18:56:24 +00:00
|
|
|
args = ['', '--file', 'tests/samples/emptyfile.txt', '--key', '123']
|
2015-08-11 18:19:22 +00:00
|
|
|
retval = main(args)
|
|
|
|
self.assertEquals(retval, 0)
|