def test_cli_export_reference_014(snippy): """Export references with search keyword. Export references based on search keyword. In this case the search keyword matchies to two references that must be exported to file defined in command line. """ content = { 'meta': Content.get_cli_meta(), 'data': [ Content.deepcopy(Reference.GITLOG), Content.deepcopy(Reference.REGEXP) ] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--sall', 'howto', '-f', 'defined-reference.text', '--scat', 'reference' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'defined-reference.text', content)
def test_cli_export_snippet_016(snippy): """Export snippets with search keyword. Export snippets based on search keyword. In this case the search keyword matches to two snippets that must be exported to file defined in command line. """ content = { 'meta': Content.get_cli_meta(), 'data': [ Content.deepcopy(Snippet.REMOVE), Content.deepcopy(Snippet.FORCED) ] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--sall', 'docker', '-f', 'defined-snippet.text' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'defined-snippet.text', content)
def test_cli_export_solution_026(snippy): """Export solutions with search keyword. Export solutions based on search keyword. In this case the search keyword matchies to two solutions that must be exported to file defined in command line. """ content = { 'meta': Content.get_cli_meta(), 'data': [ Content.deepcopy(Solution.BEATS), Content.deepcopy(Solution.NGINX) ] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--scat', 'solution', '--sall', 'howto', '-f', './defined-solutions.txt' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, './defined-solutions.txt', content)
def test_cli_export_snippet_010(snippy): """Export defined snippets. Try to export defined snippet based on message digest that cannot be found. """ with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run(['snippy', 'export', '-d', '123456789abcdef0', '-f', 'defined-snippet.txt']) assert cause == 'NOK: cannot find content with message digest: 123456789abcdef0' Content.assert_text(mock_file, None, None)
def test_cli_export_snippet_021(snippy): """Export defined snippet with content data. Export defined snippet based on content data. File name is defined in command line as text file with *.txt file extension. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Snippet.REMOVE)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run(['snippy', 'export', '-c', 'docker rm --volumes $(docker ps --all --quiet)', '-f', 'defined-snippet.txt']) # pylint: disable=line-too-long assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'defined-snippet.txt', content)
def test_cli_export_snippet_009(snippy): """Export defined snippets. Export defined snippet based on message digest. Filename and format are defined with command line option ``--file``. """ content = { 'meta': Content.get_cli_meta(), 'data': [ Content.deepcopy(Snippet.FORCED) ] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run(['snippy', 'export', '-d', '53908d68425c61dc', '-f', 'defined-snippet.txt']) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'defined-snippet.txt', content)
def test_cli_export_snippet_015(snippy): """Export defined snippets. Export defined snippet based on search keyword. File name is defined in command line as text file with *.text file extension. """ content = { 'meta': Content.get_cli_meta(), 'data': [ Content.deepcopy(Snippet.FORCED) ] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run(['snippy', 'export', '--sall', 'force', '-f', 'defined-snippet.text']) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'defined-snippet.text', content)
def test_cli_export_solution_008(snippy): """Export defined solution with digest. Export defined solution based on message digest. File name is defined in solution metadata but not by command line -f|--file option. In this case the content category is not specified explicitly from command line. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Solution.BEATS)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run(['snippy', 'export', '-d', '4346ba4c79247430']) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'howto-debug-elastic-beats.txt', content)
def test_cli_export_solution_022(snippy): """Export solution with search keyword. Export defined solution based on search keyword. File name is defined in solution metadata but not by command line -f|--file option. Content filename fields is used because the search result is a single content. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Solution.BEATS)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run( ['snippy', 'export', '--scat', 'solution', '--sall', 'beats']) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'howto-debug-elastic-beats.txt', content)
def test_cli_export_reference_013(snippy): """Export defined reference with search keyword. Export defined reference based on search keyword. File name is defined in command line as text file with *.text file extension. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Reference.REGEXP)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--sall', 'regexp', '-f', 'defined-reference.text', '--scat', 'reference' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'defined-reference.text', content)
def test_cli_export_solution_017(snippy): """Export defined solution with digest. Export defined solution based on message digest to text file without specifying the content category explicitly. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Solution.BEATS)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '-d', '4346ba4c79247430', '-f', './defined-solution.text' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, './defined-solution.text', content)
def test_cli_export_solution_007(snippy): """Export solution with ``--digest`` option. Export resource based on message digest. The File name is defined in solution ``filename`` attribute but not with ``--file``command line option. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Solution.BEATS)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--scat', 'solution', '-d', '4346ba4c79247430' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'howto-debug-elastic-beats.txt', content)
def test_cli_export_solution_025(snippy): """Export solutions with search keyword. Export defined solution based on search keyword. File name is defined in solution metadata and in command line -f|--file option. This should result the file name and format defined by the command line option. In this case the text format file extension is 'txt'. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Solution.BEATS)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--scat', 'solution', '--sall', 'beats', '-f', './defined-solution.txt' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, './defined-solution.txt', content)
def test_cli_export_solution_020(snippy): """Export defined solution with digest. Export defined solution based on message digest. File name is not defined from command line ``-f|--file`` option. In this case there are extra spaces around the ``filename`` attribute which does not prevent using the stored filename. Because the filename is available, the export filename must follow ``filename`` attribute and file format. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Solution.KAFKA)] } content['data'][0][ 'filename'] = ' kubernetes-docker-log-driver-kafka.txt ' content['data'][0][ 'digest'] = 'ee3f2ab7c63d6965ac2531003807f00caee178f6e1cbb870105c7df86e6d5be2' file_content = Content.get_file_content(Content.TEXT, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run(['snippy', 'import', '-f', './kafka.text']) assert cause == Cause.ALL_OK with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--scat', 'solution', '-d', 'ee3f2ab7c63d6965' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'kubernetes-docker-log-driver-kafka.txt', content)
def test_cli_export_solution_042(snippy): """Export defined solution with digest. Export Markdown native content when the ``filename`` attribute defines the default file as Markdown file. In this case the ``--format`` option defines that the exported file must be text file. Command line option must always override other configuration. """ content = { 'meta': Content.get_cli_meta(), 'data': [Solution.KAFKA_MKDN] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '-d', 'c54c8a896b94ea35', '--format', 'text' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'kubernetes-docker-log-driver-kafka.text', content)
def test_cli_export_solution_009(snippy): """Export defined solution with digest. Export solution based on a message digest. Content filename is not defined in resource ``filename`` attribute or with the command line option ``-f|--file``. In this case the ``--format`` option defines the file format as text which must create a text formatted file with the tool default filename. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Solution.KAFKA)] } content['data'][0]['filename'] = Const.EMPTY content['data'][0][ 'digest'] = '0a2b29d2fde6b900375d68be93ac6142c5adafb27fb5d6294fab465090d82504' file_content = Content.get_file_content(Content.TEXT, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run([ 'snippy', 'import', '--scat', 'solution', '-d', 'ee3f2ab7c63d6965', '-f', 'kafka.text' ]) assert cause == Cause.ALL_OK with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--scat', 'solution', '-d', '0a2b29d2fde6b900', '--format', 'text' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, './solutions.text', content)
def test_cli_export_reference_007(snippy): """Export defined reference with digest. Export defined reference based on message digest. Filename and format are defined with command line option ``--file``. Because text template does not have UUID, the UUID mock allocates a new UUID for the exported comparison. Because of this the imported resource UUID cannot be compared to exported text. """ content = { 'meta': Content.get_cli_meta(), 'data': [Content.deepcopy(Reference.REGEXP)] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '-d', 'cb9225a81eab8ced', '-f', 'defined-reference.txt' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, 'defined-reference.txt', content)
def test_cli_export_solution_005(snippy): """Export all solutions. Export all solutions into defined text file with file extension 'text'. File name and format are defined in command line. """ content = { 'meta': Content.get_cli_meta(), 'data': [ Content.deepcopy(Solution.BEATS), Content.deepcopy(Solution.NGINX) ] } with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: cause = snippy.run([ 'snippy', 'export', '--scat', 'solution', '-f', './all-solutions.text' ]) assert cause == Cause.ALL_OK Content.assert_text(mock_file, './all-solutions.text', content)