test caching offline heartbeat with null project
This commit is contained in:
parent
859017daef
commit
f53044fd23
1 changed files with 23 additions and 4 deletions
|
@ -6,6 +6,7 @@ from wakatime.offlinequeue import Queue
|
||||||
from wakatime.packages import requests
|
from wakatime.packages import requests
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
import time
|
import time
|
||||||
from wakatime.compat import u
|
from wakatime.compat import u
|
||||||
from wakatime.packages.requests.models import Response
|
from wakatime.packages.requests.models import Response
|
||||||
|
@ -29,12 +30,12 @@ class OfflineQueueTestCase(utils.TestCase):
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--alternate-project', 'xyz', '--config', config, '--time', now]
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
execute(args)
|
execute(args)
|
||||||
|
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
saved_heartbeat = queue.pop()
|
saved_heartbeat = queue.pop()
|
||||||
self.assertEquals(os.path.abspath(entity), saved_heartbeat['entity'])
|
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity'])
|
||||||
|
|
||||||
def test_heartbeat_discarded_from_400_response(self):
|
def test_heartbeat_discarded_from_400_response(self):
|
||||||
response = Response()
|
response = Response()
|
||||||
|
@ -45,7 +46,7 @@ class OfflineQueueTestCase(utils.TestCase):
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--alternate-project', 'xyz', '--config', config, '--time', now]
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
execute(args)
|
execute(args)
|
||||||
|
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
|
@ -61,7 +62,7 @@ class OfflineQueueTestCase(utils.TestCase):
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--alternate-project', 'xyz', '--config', config, '--time', now]
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
execute(args)
|
execute(args)
|
||||||
|
|
||||||
response.status_code = 201
|
response.status_code = 201
|
||||||
|
@ -70,3 +71,21 @@ class OfflineQueueTestCase(utils.TestCase):
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
saved_heartbeat = queue.pop()
|
saved_heartbeat = queue.pop()
|
||||||
self.assertEquals(None, saved_heartbeat)
|
self.assertEquals(None, saved_heartbeat)
|
||||||
|
|
||||||
|
def test_empty_project_can_be_saved(self):
|
||||||
|
response = Response()
|
||||||
|
response.status_code = 500
|
||||||
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile() as fh:
|
||||||
|
|
||||||
|
now = u(int(time.time()))
|
||||||
|
entity = fh.name
|
||||||
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
execute(args)
|
||||||
|
|
||||||
|
queue = Queue()
|
||||||
|
saved_heartbeat = queue.pop()
|
||||||
|
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity'])
|
||||||
|
|
Loading…
Reference in a new issue