def test_hook_is_yet_installed_upgrade_is_set___hook_is_installed( self, orig_content, new_content, url_front, file_name, hook_name): assume(new_content != orig_content) url = 'http://' + url_front + '/' + file_name with FakeRepoDir(): with open( os.path.join(repo.hook_type_directory(hook_name), file_name), 'w') as f: f.write(orig_content) responses.add( responses.GET, url, body=new_content, status=200, ) sys.argv = ['foo', 'install', hook_name, url, '--upgrade', '-y'] cmd.Hooks().run() with open( os.path.join(repo.hook_type_directory(hook_name), file_name)) as f: self.assertEqual(new_content, f.read())
def test_setup_config_is_given___all_hooks_from_setup_config_are_installed(self, setup_configs): self.set_missing_search_response() setup_config = ConfigParser() hook_type_setting = {} for hook_type, hooks in setup_configs.items(): hook_type_setting.setdefault(hook_type, '') for hook in hooks: url = 'http://' + hook['front'] + '/' + hook['filename'] hook_type_setting[hook_type] += url + '\n' responses.add( responses.GET, url, body=hook['content'], status=200, ) setup_config.add_section('git-hooks.install') for hook_type, value in hook_type_setting.items(): setup_config.set('git-hooks.install', hook_type, value) with FakeRepoDir() as dir: with open(os.path.join(str(dir), 'setup.cfg'), 'w') as f: setup_config.write(f) sys.argv = ['foo', 'install'] cmd.Hooks().run() for hook_type, hooks in setup_configs.items(): for hook in hooks: self.assertTrue(os.path.exists(os.path.join(repo.hook_type_directory(hook_type), hook['filename'])))
def test_config_is_given___all_hooks_from_config_are_installed( self, hook_configs, setup_configs): with FakeRepoDir() as dir: config = ConfigParser() hook_type_setting = {} for hook_type, hooks in hook_configs.items(): hook_type_setting.setdefault(hook_type, '') for hook in hooks: url = 'http://' + hook['front'] + '/' + hook['filename'] hook_type_setting[hook_type] += url + '\n' responses.add( responses.GET, url, body=hook['content'], status=200, ) config.add_section('install') for hook_type, value in hook_type_setting.items(): config.set('install', hook_type, value) with open(os.path.join(str(dir), 'git-hooks.cfg'), 'w') as f: config.write(f) setup_config = ConfigParser() hook_type_setting = {} for hook_type, hooks in setup_configs.items(): hook_type_setting.setdefault(hook_type, '') for hook in hooks: url = 'http://' + hook['front'] + '/' + hook['filename'] hook_type_setting[hook_type] += url + '\n' responses.add( responses.GET, url, body=hook['content'], status=200, ) setup_config.add_section('git-hooks.install') for hook_type, value in hook_type_setting.items(): setup_config.set('git-hooks.install', hook_type, value) with open(os.path.join(str(dir), 'setup.cfg'), 'w') as f: setup_config.write(f) sys.argv = ['foo', 'install', '-y'] cmd.Hooks().run() for hook_type, hooks in hook_configs.items(): for hook in hooks: self.assertTrue( os.path.exists( os.path.join(repo.hook_type_directory(hook_type), hook['filename'])))
def test_hook_is_found_and_checksum_fails___hook_is_not_saved(self, name, content, hook_type): self.set_existing_search_response(name, content, hook_type, response_content=content + 'tamper') responses.start() with FakeRepoDir(): sys.argv = ['foo', 'install', hook_type, name] cmd.Hooks().run() self.assertFalse(os.path.exists(os.path.join(repo.hook_type_directory(hook_type), name)))
def test_hook_is_found_and_checksum_passes___hook_is_saved(self, name, content, hook_type): self.set_existing_search_response(name, content, hook_type) responses.start() with FakeRepoDir(): sys.argv = ['foo', 'install', hook_type, name] cmd.Hooks().run() with open(os.path.join(repo.hook_type_directory(hook_type), name)) as f: self.assertEqual(content, f.read())
def test_hook_exists_in___hook_is_deleted(self, name, hook_type): with FakeRepoDir(): hook_path = os.path.join(repo.hook_type_directory(hook_type), name) with open(hook_path, 'w') as f: f.write('content') sys.argv = ['foo', 'uninstall', hook_type, name] cmd.Hooks().run() self.assertFalse(os.path.exists(hook_path))
def test_hook_is_yet_installed_upgrade_is_set___hook_is_installed(self, orig_content, new_content, url_front, file_name, hook_name): assume(new_content != orig_content) self.set_missing_search_response() url = 'http://' + url_front + '/' + file_name with FakeRepoDir(): with open(os.path.join(repo.hook_type_directory(hook_name), file_name), 'w') as f: f.write(orig_content) responses.add( responses.GET, url, body=new_content, status=200, ) sys.argv = ['foo', 'install', hook_name, url, '--upgrade'] cmd.Hooks().run() with open(os.path.join(repo.hook_type_directory(hook_name), file_name)) as f: self.assertEqual(new_content, f.read())
def test_hook_is_not_yet_installed___hook_is_installed(self, content, url_front, file_name, hook_name): self.set_missing_search_response() url = 'http://' + url_front + '/' + file_name with FakeRepoDir(): responses.add( responses.GET, url, body=content, status=200, ) sys.argv = ['foo', 'install', hook_name, url] cmd.Hooks().run() with open(os.path.join(repo.hook_type_directory(hook_name), file_name)) as f: self.assertEqual(content, f.read())
def test_hook_is_not_yet_installed___hook_is_installed( self, content, url_front, file_name, hook_name): url = 'http://' + url_front + '/' + file_name with FakeRepoDir(): responses.add( responses.GET, url, body=content, status=200, ) sys.argv = ['foo', 'install', hook_name, url, '-y'] cmd.Hooks().run() with open( os.path.join(repo.hook_type_directory(hook_name), file_name)) as f: self.assertEqual(content, f.read())