def test_writes_crontab(self, mock_crontab, mock_rootdir, mock_metadata): args = self.parse_args(mock_rootdir) with mock_metadata(remote_files=(metadata_factory( repo='[email protected]:yelp/detect-secrets', json=True, ), ), local_files=(metadata_factory( repo='examples', json=True, ), )): install_mapper(args) assert mock_crontab.content == textwrap.dedent(""" 0 0 * * * detect-secrets-server scan [email protected]:yelp/detect-secrets --root-dir {} 0 0 * * * detect-secrets-server scan examples --local --root-dir {} """).format(mock_rootdir, mock_rootdir)[1:-1] mock_crontab.write_to_user.assert_called_with(user=True)
def test_crontab_writes_with_output_hook( self, mock_crontab, mock_rootdir, mock_metadata, ): args = self.parse_args(mock_rootdir, '--output-hook examples/standalone_hook.py') with mock_metadata(remote_files=(metadata_factory( repo='[email protected]:yelp/detect-secrets', crontab='1 2 3 4 5', json=True, ), ), ): install_mapper(args) assert mock_crontab.content == ( '1 2 3 4 5 detect-secrets-server scan [email protected]:yelp/detect-secrets' ' --output-hook examples/standalone_hook.py') mock_crontab.write_to_user.assert_called_with(user=True)
def test_does_not_override_existing_crontab( self, mock_crontab, mock_rootdir, mock_metadata, ): mock_crontab.old_content = textwrap.dedent(""" * * * * * detect-secrets-server scan old_config_will_be_deleted --local * * * * * some_content_here """)[1:] args = self.parse_args(mock_rootdir) with mock_metadata(local_files=(metadata_factory( repo='examples', crontab='1 2 3 4 5', json=True, ), ), ): install_mapper(args) assert mock_crontab.content == textwrap.dedent(""" * * * * * some_content_here 1 2 3 4 5 detect-secrets-server scan examples --local --root-dir {} """).format(mock_rootdir)[1:-1]