def test_500_response_without_offline_logging(self, logs): logging.disable(logging.NOTSET) response = Response() response.status_code = 500 response._content = 'fake content' if is_py3: response._content = 'fake content'.encode('utf8') self.patched[ 'wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with utils.TemporaryDirectory() as tempdir: entity = 'tests/samples/codefiles/twolinefile.txt' shutil.copy(entity, os.path.join(tempdir, 'twolinefile.txt')) entity = os.path.realpath(os.path.join(tempdir, 'twolinefile.txt')) now = u(int(time.time())) key = str(uuid.uuid4()) heartbeat = { 'language': 'Text only', 'lines': 2, 'entity': entity, 'project': None, 'time': float(now), 'type': 'file', 'is_write': False, 'user_agent': ANY, 'dependencies': [], } args = [ '--file', entity, '--key', key, '--disable-offline', '--config', 'tests/samples/configs/good_config.cfg', '--time', now ] retval = execute(args) self.assertEquals(retval, API_ERROR) self.assertNothingPrinted() actual = self.getLogOutput(logs) expected = "WakaTime ERROR {'response_code': 500, 'response_content': u'fake content'}" if actual[-2] == '0': expected = "WakaTime ERROR {'response_content': u'fake content', 'response_code': 500}" if is_py3: expected = "WakaTime ERROR {'response_code': 500, 'response_content': 'fake content'}" if actual[-2] == '0': expected = "WakaTime ERROR {'response_content': 'fake content', 'response_code': 500}" self.assertEquals(expected, actual) self.assertHeartbeatSent(heartbeat) self.assertHeartbeatNotSavedOffline() self.assertOfflineHeartbeatsNotSynced() self.assertSessionCacheDeleted()
def test_500_response_without_offline_logging(self, logs): logging.disable(logging.NOTSET) response = Response() response.status_code = 500 response._content = 'fake content' if is_py3: response._content = 'fake content'.encode('utf8') self.patched[ 'wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with utils.TemporaryDirectory() as tempdir: entity = 'tests/samples/codefiles/twolinefile.txt' shutil.copy(entity, os.path.join(tempdir, 'twolinefile.txt')) entity = os.path.realpath(os.path.join(tempdir, 'twolinefile.txt')) now = u(int(time.time())) key = str(uuid.uuid4()) args = [ '--file', entity, '--key', key, '--disableoffline', '--config', 'tests/samples/configs/good_config.cfg', '--time', now ] retval = execute(args) self.assertEquals(retval, API_ERROR) self.assertEquals(sys.stdout.getvalue(), '') self.assertEquals(sys.stderr.getvalue(), '') log_output = u("\n").join([u(' ').join(x) for x in logs.actual()]) expected = "WakaTime ERROR {'response_code': 500, 'response_content': u'fake content'}" if log_output[-2] == '0': expected = "WakaTime ERROR {'response_content': u'fake content', 'response_code': 500}" if is_py3: expected = "WakaTime ERROR {'response_code': 500, 'response_content': 'fake content'}" if log_output[-2] == '0': expected = "WakaTime ERROR {'response_content': 'fake content', 'response_code': 500}" self.assertEquals(expected, log_output) self.patched[ 'wakatime.session_cache.SessionCache.delete'].assert_called_once_with( ) self.patched[ 'wakatime.session_cache.SessionCache.get'].assert_called_once_with( ) self.patched[ 'wakatime.session_cache.SessionCache.save'].assert_not_called( ) self.patched['wakatime.offlinequeue.Queue.push'].assert_not_called( ) self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
def test_500_response_without_offline_logging(self, logs): logging.disable(logging.NOTSET) response = Response() response.status_code = 500 response._content = 'fake content' if is_py3: response._content = 'fake content'.encode('utf8') self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response with utils.TemporaryDirectory() as tempdir: entity = 'tests/samples/codefiles/twolinefile.txt' shutil.copy(entity, os.path.join(tempdir, 'twolinefile.txt')) entity = os.path.realpath(os.path.join(tempdir, 'twolinefile.txt')) now = u(int(time.time())) key = str(uuid.uuid4()) heartbeat = { 'language': 'Text only', 'lines': 2, 'entity': entity, 'project': None, 'time': float(now), 'type': 'file', 'is_write': False, 'user_agent': ANY, 'dependencies': [], } args = ['--file', entity, '--key', key, '--disable-offline', '--config', 'tests/samples/configs/good_config.cfg', '--time', now] retval = execute(args) self.assertEquals(retval, API_ERROR) self.assertNothingPrinted() actual = self.getLogOutput(logs) expected = "WakaTime ERROR {'response_code': 500, 'response_content': u'fake content'}" if actual[-2] == '0': expected = "WakaTime ERROR {'response_content': u'fake content', 'response_code': 500}" if is_py3: expected = "WakaTime ERROR {'response_code': 500, 'response_content': 'fake content'}" if actual[-2] == '0': expected = "WakaTime ERROR {'response_content': 'fake content', 'response_code': 500}" self.assertEquals(expected, actual) self.assertHeartbeatSent(heartbeat) self.assertHeartbeatNotSavedOffline() self.assertOfflineHeartbeatsNotSynced() self.assertSessionCacheDeleted()