new --extra-heartbeats argument

This commit is contained in:
Alan Hamlett 2016-04-21 00:30:44 +02:00
parent 984a8ab62a
commit 67a2403070
5 changed files with 107 additions and 45 deletions

View file

@ -4,7 +4,7 @@ usage: wakatime [-h] [--entity FILE] [--key KEY] [--write] [--plugin PLUGIN]
[--alternate-project ALTERNATE_PROJECT]
[--alternate-language ALTERNATE_LANGUAGE]
[--hostname HOSTNAME] [--disableoffline] [--hidefilenames]
[--exclude EXCLUDE] [--include INCLUDE] [--logfile LOGFILE]
[--apiurl API_URL] [--timeout TIMEOUT] [--config CONFIG]
[--verbose] [--version]
[--exclude EXCLUDE] [--include INCLUDE] [--extra-heartbeats]
[--logfile LOGFILE] [--apiurl API_URL] [--timeout TIMEOUT]
[--config CONFIG] [--verbose] [--version]
wakatime: error: argument --timeout: invalid int value: 'abc'

View file

@ -4,9 +4,9 @@ usage: wakatime [-h] [--entity FILE] [--key KEY] [--write] [--plugin PLUGIN]
[--alternate-project ALTERNATE_PROJECT]
[--alternate-language ALTERNATE_LANGUAGE]
[--hostname HOSTNAME] [--disableoffline] [--hidefilenames]
[--exclude EXCLUDE] [--include INCLUDE] [--logfile LOGFILE]
[--apiurl API_URL] [--timeout TIMEOUT] [--config CONFIG]
[--verbose] [--version]
[--exclude EXCLUDE] [--include INCLUDE] [--extra-heartbeats]
[--logfile LOGFILE] [--apiurl API_URL] [--timeout TIMEOUT]
[--config CONFIG] [--verbose] [--version]
Common interface for the WakaTime api.
@ -46,6 +46,8 @@ optional arguments:
--include INCLUDE filename patterns to log; when used in combination
with --exclude, files matching include will still be
logged; POSIX regex syntax; can be used more than once
--extra-heartbeats reads extra heartbeats from STDIN as a JSON array
until EOF
--logfile LOGFILE defaults to ~/.wakatime.log
--apiurl API_URL heartbeats api url; for debugging with a local server
--timeout TIMEOUT number of seconds to wait when sending heartbeats to

View file

@ -4,7 +4,7 @@ usage: wakatime [-h] [--entity FILE] [--key KEY] [--write] [--plugin PLUGIN]
[--alternate-project ALTERNATE_PROJECT]
[--alternate-language ALTERNATE_LANGUAGE]
[--hostname HOSTNAME] [--disableoffline] [--hidefilenames]
[--exclude EXCLUDE] [--include INCLUDE] [--logfile LOGFILE]
[--apiurl API_URL] [--timeout TIMEOUT] [--config CONFIG]
[--verbose] [--version]
[--exclude EXCLUDE] [--include INCLUDE] [--extra-heartbeats]
[--logfile LOGFILE] [--apiurl API_URL] [--timeout TIMEOUT]
[--config CONFIG] [--verbose] [--version]
wakatime: error: Missing api key

View file

@ -23,9 +23,9 @@ try:
except (ImportError, SyntaxError):
import json
try:
from mock import ANY
from mock import ANY, call
except ImportError:
from unittest.mock import ANY
from unittest.mock import ANY, call
from wakatime.packages import tzlocal
@ -647,3 +647,35 @@ class BaseTestCase(utils.TestCase):
timezone = tzlocal.get_localzone()
headers = self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].call_args[0][0].headers
self.assertEquals(headers.get('TimeZone'), u(timezone.zone).encode('utf-8') if is_py3 else timezone.zone)
def test_extra_heartbeats_argument(self):
response = Response()
response.status_code = 201
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
entity = 'tests/samples/codefiles/emptyfile.txt'
config = 'tests/samples/configs/good_config.cfg'
args = ['--file', entity, '--config', config, '--extra-heartbeats']
with utils.mock.patch('wakatime.main.sys.stdin') as mock_stdin:
now = int(time.time())
heartbeats = json.dumps([{
'timestamp': now,
'entity': entity,
'entity_type': 'file',
'is_write': True,
}])
mock_stdin.read.return_value = heartbeats
retval = execute(args)
self.assertEquals(retval, SUCCESS)
self.assertEquals(sys.stdout.getvalue(), '')
self.assertEquals(sys.stderr.getvalue(), '')
self.patched['wakatime.session_cache.SessionCache.get'].assert_has_calls([call(), call()])
self.patched['wakatime.session_cache.SessionCache.delete'].assert_not_called()
self.patched['wakatime.session_cache.SessionCache.save'].assert_has_calls([call(ANY), call(ANY)])
self.patched['wakatime.offlinequeue.Queue.push'].assert_not_called()
self.patched['wakatime.offlinequeue.Queue.pop'].assert_has_calls([call(), call()])