Fix bug causing random project names when hide project names enabled

This commit is contained in:
Alan Hamlett 2019-01-05 14:00:37 +07:00
parent 60b696858a
commit 8afc6133cf
4 changed files with 40 additions and 1 deletions

View File

@ -497,6 +497,9 @@ class ConfigsTestCase(TestCase):
}
self.assertHeartbeatSent(heartbeat)
detected_proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read()
self.assertEquals(detected_proj, generated_proj)
self.assertHeartbeatNotSavedOffline()
self.assertOfflineHeartbeatsSynced()
self.assertSessionCacheSaved()

View File

@ -158,6 +158,13 @@ class ProjectTestCase(TestCase):
entity='projects/wakatime_project_file/emptyfile.txt',
)
def test_wakatime_project_file_used_even_when_project_names_hidden(self):
self.shared(
expected_project='waka-project-file',
entity='projects/wakatime_project_file/emptyfile.txt',
extra_args=['--hide-project-names'],
)
def test_git_project_detected(self):
tempdir = tempfile.mkdtemp()
shutil.copytree('tests/samples/projects/git', os.path.join(tempdir, 'git'))
@ -169,6 +176,33 @@ class ProjectTestCase(TestCase):
entity=os.path.join(tempdir, 'git', 'emptyfile.txt'),
)
def test_get_project_not_used_when_project_names_hidden(self):
response = Response()
response.status_code = 0
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
tempdir = tempfile.mkdtemp()
shutil.copytree('tests/samples/projects/git', os.path.join(tempdir, 'git'))
shutil.move(os.path.join(tempdir, 'git', 'dot_git'), os.path.join(tempdir, 'git', '.git'))
now = u(int(time.time()))
entity = os.path.join(tempdir, 'git', 'emptyfile.txt')
config = 'tests/samples/configs/good_config.cfg'
args = ['--hide-project-names', '--file', entity, '--config', config, '--time', now]
execute(args)
self.assertHeartbeatSavedOffline()
self.assertNotEquals('git', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
self.assertEquals(None, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['branch'])
proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read()
self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
execute(args)
self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
@log_capture()
def test_ioerror_when_reading_git_branch(self, logs):
logging.disable(logging.NOTSET)

View File

@ -335,7 +335,7 @@ def boolean_or_list(config_name, args, configs, alternative_names=[]):
"""Get a boolean or list of regexes from args and configs."""
# when argument flag present, set to wildcard regex
for key in alternative_names:
for key in alternative_names + [config_name]:
if hasattr(args, key) and getattr(args, key):
setattr(args, config_name, ['.*'])
return

View File

@ -69,6 +69,8 @@ def get_project_info(configs, heartbeat, data):
project_name = data.get('project') or heartbeat.args.project
hide_project = heartbeat.should_obfuscate_project()
if hide_project and project_name is not None:
return project_name, None
if project_name is None or branch_name is None: