def test_cli_import_reference_019(snippy): """Try to import reference which uuid collides. The uuid must be unique and this causes a database integrity error. """ content = {'data': [Reference.GITLOG]} file_content = Content.get_file_content(Content.MKDN, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run(['snippy', 'import', '--scat', 'reference']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./references.mkdn', 'r') content_uuid = {'data': [Content.deepcopy(Reference.REGEXP)]} content_uuid['data'][0]['uuid'] = content['data'][0]['uuid'] file_content = Content.get_file_content(Content.MKDN, content_uuid) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run(['snippy', 'import', '--scat', 'reference']) assert cause == 'NOK: content uuid already exist with digest 5c2071094dbfaa33' Content.assert_storage(content) mock_file.assert_called_once_with('./references.mkdn', 'r')
def test_cli_import_reference_017(snippy): """Import references defaults. Try to import reference defaults again. The second import must fail with error because resoureces already exist. The error text must be the same for all content categories. Because of random order dictionary in the code, the reported digest can vary when there are multiple failures to import each content. Because there is unique constraint violation for ``data`` and ``uuid`` attributes and PostgreSQL and Sqlite throw the error from different attributes, both attributes must be checked. """ content = {'data': [Reference.GITLOG, Reference.REGEXP]} file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run( ['snippy', 'import', '--scat', 'reference', '--defaults']) assert cause in ( 'NOK: content data already exist with digest 5c2071094dbfaa33', 'NOK: content uuid already exist with digest 5c2071094dbfaa33', 'NOK: content data already exist with digest cb9225a81eab8ced', 'NOK: content uuid already exist with digest cb9225a81eab8ced') Content.assert_storage(content) defaults_references = pkg_resources.resource_filename( 'snippy', 'data/defaults/references.yaml') mock_file.assert_called_once_with(defaults_references, 'r')
def test_cli_import_reference_016(snippy): """Import references defaults. Import reference defaults. All references should be imported from predefined file location under tool data folder from yaml format. """ content = { 'data': [ Reference.PYTEST, Reference.GITLOG, ] } file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run( ['snippy', 'import', '--scat', 'reference', '--defaults']) assert cause == Cause.ALL_OK Content.assert_storage(content) defaults_references = pkg_resources.resource_filename( 'snippy', 'data/defaults/references.yaml') mock_file.assert_called_once_with(defaults_references, 'r')
def test_cli_import_reference_011(snippy): """Import reference based on message digest. Import defined reference based on message digest without specifying the content category explicitly. One line in the reference data was updated. The updated content is timestamped with regexp content time. """ content = {'data': [Content.deepcopy(Reference.GITLOG)]} content['data'][0]['links'] = ('https://updated-link.html', ) content['data'][0]['updated'] = Content.PYTEST_TIME content['data'][0][ 'digest'] = 'fafd46eca7ca239bcbff8f1ba3e8cf806cadfbc9e267cdf6ccd3e23e356f9f8d' file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run([ 'snippy', 'import', '-d', '5c2071094dbfaa33', '-f', 'one-reference.yaml' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('one-reference.yaml', 'r')
def test_cli_import_reference_010(snippy): """Import reference based on message digest. Import defined reference based on message digest. File name is defined from command line as YAML file which contain one reference. Links in the reference was updated. Content updated field must be updated with a new timestamp. """ content = {'data': [Content.deepcopy(Reference.GITLOG)]} content['data'][0]['links'] = ('https://updated-link.html', ) content['data'][0]['updated'] = Content.PYTEST_TIME content['data'][0][ 'digest'] = 'fafd46eca7ca239bcbff8f1ba3e8cf806cadfbc9e267cdf6ccd3e23e356f9f8d' file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run([ 'snippy', 'import', '--scat', 'reference', '-d', '5c2071094dbfaa33', '-f', 'one-reference.yaml' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('one-reference.yaml', 'r')
def test_cli_import_snippet_018(snippy): """Import snippets already existing. Import snippets from yaml file that is defined from command line. In this case two out of three imported snippets are already stored into the database. Because existing content is not considered as an error, the third snippet is imported successfully with success cause. The UUID is modified to avoid the UUID collision which produces error. The test verifies that user modified resource attributes do not stop importing multiple resources. """ content = { 'data': [ Content.deepcopy(Snippet.REMOVE), Content.deepcopy(Snippet.FORCED), Snippet.NETCAT ] } content['data'][0]['uuid'] = Content.UUID1 content['data'][1]['uuid'] = Content.UUID2 file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run(['snippy', 'import', '-f', './snippets.yaml']) assert cause == Cause.ALL_OK content['data'][0]['uuid'] = Snippet.REMOVE_UUID content['data'][1]['uuid'] = Snippet.FORCED_UUID Content.assert_storage(content) mock_file.assert_called_once_with('./snippets.yaml', 'r')
def test_cli_import_solution_026(snippy): """Import solutions defaults. Try to import solution defaults again. The second import should fail with an error because the content already exist. The error text must be the same for all content categories. Because of random order dictionary in the code, the reported digest can vary when there are multiple failures to import each content. Because there is unique constraint violation for ``data`` and ``uuid`` attributes and PostgreSQL and Sqlite throw the error from different attributes, both attributes must be checked. """ content = {'data': [Solution.BEATS, Solution.NGINX]} file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run( ['snippy', 'import', '--scat', 'solution', '--defaults']) assert cause in ( 'NOK: content data already exist with digest 6cfe47a8880a8f81', 'NOK: content uuid already exist with digest 6cfe47a8880a8f81', 'NOK: content data already exist with digest 4346ba4c79247430', 'NOK: content uuid already exist with digest 4346ba4c79247430') Content.assert_storage(content) defaults_solutions = pkg_resources.resource_filename( 'snippy', 'data/defaults/solutions.yaml') mock_file.assert_called_once_with(defaults_solutions, 'r')
def test_cli_import_solution_010(snippy): """Import all solutions. Import solutions from yaml file when all but one of the solutions in the file is already stored. Because one solution was stored successfully, the return cause is OK. The UUID is modified to avoid the UUID collision which produces error. The test verifies that user modified resource attributes do not stop importing multiple resources. """ content = {'data': [Solution.KAFKA, Content.deepcopy(Solution.BEATS)]} content['data'][1]['uuid'] = Content.UUID1 file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run([ 'snippy', 'import', '--scat', 'solution', '--file', './all-solutions.yaml' ]) assert cause == Cause.ALL_OK content['data'][1]['uuid'] = Solution.BEATS_UUID Content.assert_storage(content) mock_file.assert_called_once_with('./all-solutions.yaml', 'r')
def test_cli_import_solution_014(snippy): """Import solution based on message digest. Import defined solution based on message digest without specifying the content category explicitly. One line in the solution data was updated. """ content = {'data': [Content.deepcopy(Solution.NGINX)]} content['data'][0]['data'] = content['data'][0]['data'][:4] + ( ' # Changed.', ) + content['data'][0]['data'][5:] content['data'][0]['updated'] = Content.KAFKA_TIME content['data'][0][ 'digest'] = 'c64d9cd40c15d5ce9905b282bf26c53c2ffdc32c1a7f268d6cf31364ef889a8a' file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run([ 'snippy', 'import', '-d', '6cfe47a8880a8f81', '-f', 'one-solution.yaml' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('one-solution.yaml', 'r')
def test_cli_import_solution_006(snippy): """Import all solutions. Import all solutions from txt file. File name and format are extracted from command line option ``-f|--file``. File extension is '*.txt' in this case. 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 = { 'data': [ Content.deepcopy(Solution.BEATS), Content.deepcopy(Solution.NGINX) ] } content['data'][0]['uuid'] = Content.UUID1 content['data'][1]['uuid'] = Content.UUID2 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', '-f', './all-solutions.txt' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-solutions.txt', 'r')
def test_cli_import_reference_022(snippy): """Try to import references wihtout UUID. Try to import two references without UUID. When the UUID is missing, it must be automatically allocated """ content = { 'data': [ Content.deepcopy(Reference.GITLOG), Content.deepcopy(Reference.REGEXP) ] } content['data'][0]['uuid'] = '' content['data'][1]['uuid'] = '' file_content = Content.get_file_content(Content.MKDN, content) content['data'][0]['uuid'] = 'a1cd5827-b6ef-4067-b5ac-3ceac07dde9f' content['data'][1]['uuid'] = 'a2cd5827-b6ef-4067-b5ac-3ceac07dde9f' with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run(['snippy', 'import', '--scat', 'reference']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./references.mkdn', 'r')
def test_cli_import_solution_017(snippy): """Import solution based on message digest. Import defined solution based on message digest. File name is defined from command line as text file which contain one solution. One line in the content data was updated. The file extension is '*.text' in this case. """ content = {'data': [Content.deepcopy(Solution.NGINX)]} content['data'][0]['data'] = content['data'][0]['data'][:4] + ( ' # Changed.', ) + content['data'][0]['data'][5:] content['data'][0]['description'] = 'Changed.' content['data'][0]['updated'] = Content.KAFKA_TIME content['data'][0][ 'digest'] = 'ce3f7a0ab75dc74f7bbea68ae323c29b2361965975c0c8d34897551149d29118' 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', '6cfe47a8880a8f81', '-f', 'one-solution.text' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('one-solution.text', 'r')
def test_cli_export_solution_019(snippy): """Export defined solution with digest. Export defined solution based on message digest. Content file name is not defined in resource ``filename`` attribute or with command line option ``-f|--file``. The exported filename uses the default Markdown format and 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' ]) assert cause == Cause.ALL_OK Content.assert_mkdn(mock_file, './solutions.mkdn', content)
def test_cli_import_snippet_016(snippy): """Import snippet defaults. Try to import snippet defaults again. The second import should fail with an error because the content already exist. The error text must be the same for all content categories. Because of random order dictionary in the code, the reported digest can vary when there are multiple failures to import each content. Because there is unique constraint violation for ``data`` and ``uuid`` attributes and PostgreSQL and Sqlite throw the error from different attributes, both attributes must be checked. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run(['snippy', 'import', '--defaults']) assert cause in ( 'NOK: content data already exist with digest 53908d68425c61dc', 'NOK: content uuid already exist with digest 53908d68425c61dc', 'NOK: content data already exist with digest 54e41e9b52a02b63', 'NOK: content uuid already exist with digest 54e41e9b52a02b63') Content.assert_storage(content) defaults_snippets = pkg_resources.resource_filename( 'snippy', 'data/defaults/snippets.yaml') mock_file.assert_called_once_with(defaults_snippets, 'r')
def test_cli_import_solution_029(snippy): """Import all content defaults. Import snippet, solution and reference defaults. """ content = {'data': [Snippet.REMOVE, Solution.NGINX, Reference.GITLOG]} file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run( ['snippy', 'import', '--scat', 'all', '--defaults']) assert cause == Cause.ALL_OK Content.assert_storage(content) defaults = [] defaults.append( mock.call( pkg_resources.resource_filename( 'snippy', 'data/defaults/snippets.yaml'), 'r')) defaults.append( mock.call( pkg_resources.resource_filename( 'snippy', 'data/defaults/solutions.yaml'), 'r')) defaults.append( mock.call( pkg_resources.resource_filename( 'snippy', 'data/defaults/references.yaml'), 'r')) mock_file.assert_has_calls(defaults, any_order=True)
def test_cli_import_solution_018(snippy): """Import solution based on message digest. Import solution based on a message digest. In this case the content category is accidentally specified as 'snippet'. This should still import the content in solution category. """ content = {'data': [Content.deepcopy(Solution.NGINX)]} print(content['data'][0]['data']) #sys-exit() content['data'][0]['data'] = content['data'][0]['data'][:4] + ( ' # Changed.', ) + content['data'][0]['data'][5:] content['data'][0]['description'] = 'Changed.' content['data'][0]['updated'] = Content.KAFKA_TIME content['data'][0][ 'digest'] = 'ce3f7a0ab75dc74f7bbea68ae323c29b2361965975c0c8d34897551149d29118' 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', 'snippet', '-d', '6cfe47a8880a8f81', '-f', 'one-solution.text' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('one-solution.text', 'r')
def test_cli_import_solution_019(snippy): """Import solution based on message digest. Try to import defined solution with message digest that cannot be found. In this case there is one solution already stored. """ content = {'data': [Solution.NGINX]} updates = {'data': [Content.deepcopy(Solution.NGINX)]} updates['data'][0]['data'] = content['data'][0]['data'][:4] + ( ' # Changed.', ) + content['data'][0]['data'][5:] updates['data'][0]['description'] = 'Changed.' updates['data'][0]['updated'] = Content.KAFKA_TIME updates['data'][0][ 'digest'] = 'ce3f7a0ab75dc74f7bbea68ae323c29b2361965975c0c8d34897551149d29118' file_content = Content.get_file_content(Content.TEXT, updates) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run([ 'snippy', 'import', '--scat', 'solution', '-d', '123456789abcdef0', '-f', 'one-solution.text' ]) assert cause == 'NOK: cannot find content with message digest: 123456789abcdef0' Content.assert_storage(content) mock_file.assert_not_called()
def test_cli_import_snippet_005(snippy): """Import all snippets. Import all snippets from text file. File name and format are extracted from command line option -f|--file. File extension is '*.text' in this case. """ content = { 'data': [ Content.deepcopy(Snippet.REMOVE), Content.deepcopy(Snippet.FORCED) ] } content['data'][0]['uuid'] = Content.UUID1 content['data'][1]['uuid'] = Content.UUID2 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', './all-snippets.text']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-snippets.text', 'r')
def test_cli_import_solution_015(snippy): """Import solution based on message digest. Import defined solution based on message digest. File name is defined from command line as json file which contain one solution. One line in the content data was updated. """ content = {'data': [Content.deepcopy(Solution.NGINX)]} content['data'][0]['data'] = content['data'][0]['data'][:4] + ( ' # Changed.', ) + content['data'][0]['data'][5:] content['data'][0]['updated'] = Content.KAFKA_TIME content['data'][0][ 'digest'] = 'c64d9cd40c15d5ce9905b282bf26c53c2ffdc32c1a7f268d6cf31364ef889a8a' file_content = Content.get_file_content(Content.JSON, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: json.load.return_value = file_content cause = snippy.run([ 'snippy', 'import', '--scat', 'solution', '-d', '6cfe47a8880a8f81', '-f', 'one-solution.json' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('one-solution.json', 'r')
def test_cli_import_solution_009(snippy): """Import all solutions. Import all solutions from txt file without specifying the solution category. File name and format are extracted from command line option -f|--file. File extension is '*.text' in this case. """ content = { 'data': [ Content.deepcopy(Solution.BEATS), Content.deepcopy(Solution.NGINX) ] } content['data'][0]['uuid'] = Content.UUID1 content['data'][1]['uuid'] = Content.UUID2 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', './all-solutions.text']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-solutions.text', 'r')
def create_defaults(snippy): """Add default snippets for testing purposes.""" file_content = Content.get_file_content(Content.TEXT, {'data': [Snippet.REMOVE]}) with mock.patch('snippy.content.migrate.open', file_content, create=True): cause = snippy.run(['snippy', 'import', '-f', 'remove.txt'] + Content.db_cli_params()) assert cause == Cause.ALL_OK file_content = Content.get_file_content(Content.TEXT, {'data': [Snippet.FORCED]}) with mock.patch('snippy.content.migrate.open', file_content, create=True): cause = snippy.run(['snippy', 'import', '-f', 'forced.txt'] + Content.db_cli_params()) assert cause == Cause.ALL_OK file_content = Content.get_file_content(Content.TEXT, {'data': [Solution.BEATS]}) with mock.patch('snippy.content.migrate.open', file_content, create=True): cause = snippy.run(['snippy', 'import', '-f', 'beats.txt'] + Content.db_cli_params()) assert cause == Cause.ALL_OK file_content = Content.get_file_content(Content.TEXT, {'data': [Solution.NGINX]}) with mock.patch('snippy.content.migrate.open', file_content, create=True): cause = snippy.run(['snippy', 'import', '-f', 'nginx.txt'] + Content.db_cli_params()) assert cause == Cause.ALL_OK
def test_cli_import_snippet_020(snippy): """Import all snippets. Import all snippets from Markdown formatted file. """ content = {'data': [Snippet.REMOVE, Snippet.NETCAT]} file_content = Content.get_file_content(Content.MKDN, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run(['snippy', 'import', '-f', './all-snippets.md']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-snippets.md', 'r')
def test_cli_import_snippet_008(snippy): """Import all snippets. Try to import snippet from text file that is empty. """ content = {'data': []} 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', './all-snippets.txt']) assert cause == 'NOK: could not identify content category - please keep template tags in place' Content.assert_storage(None) mock_file.assert_called_once_with('./all-snippets.txt', 'r')
def test_cli_import_snippet_001(snippy): """Import all snippets. Import all snippets. File name is not defined in command line. This must result tool internal default file name and format being used. """ content = {'data': [Snippet.REMOVE, Snippet.NETCAT]} file_content = Content.get_file_content(Content.MKDN, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run(['snippy', 'import']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./snippets.mkdn', 'r')
def test_cli_import_solution_001(snippy): """Import all solutions. Import all solutions. File name is not defined in command line. This should result tool internal default file name and format being used. """ content = {'data': [Solution.KAFKA, Solution.BEATS]} file_content = Content.get_file_content(Content.MKDN, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run(['snippy', 'import', '--scat', 'solution']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./solutions.mkdn', 'r')
def test_cli_import_solution_023(snippy): """Import solution. Import new solution from text file without specifying the content category explicitly. In this case the file extension is '*.txt'. """ content = {'data': [Content.deepcopy(Solution.NGINX)]} content['data'][0]['uuid'] = Content.UUID1 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', 'one-solution.txt']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('one-solution.txt', 'r')
def test_cli_import_reference_020(snippy): """Import all references. Import all references from Markdown formatted file. """ content = {'data': [Reference.GITLOG, Reference.REGEXP]} file_content = Content.get_file_content(Content.MKDN, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run([ 'snippy', 'import', '--scat', 'reference', '-f', './all-references.mkdn' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-references.mkdn', 'r')
def test_cli_import_solution_031(snippy): """Import all solutions. Import all solutions from Markdown formatted file. """ content = {'data': [Solution.KAFKA, Solution.BEATS]} file_content = Content.get_file_content(Content.MKDN, content) with mock.patch('snippy.content.migrate.open', file_content, create=True) as mock_file: cause = snippy.run([ 'snippy', 'import', '--scat', 'solution', '-f', './all-solutions.md' ]) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-solutions.md', 'r')
def test_cli_import_snippet_003(snippy): """Import all snippets. Import all snippets from json file. File name and format are extracted from command line option -f|--file. """ content = {'data': [Snippet.REMOVE, Snippet.NETCAT]} file_content = Content.get_file_content(Content.JSON, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: json.load.return_value = file_content cause = snippy.run( ['snippy', 'import', '-f', './all-snippets.json']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-snippets.json', 'r')
def test_cli_import_solution_003(snippy): """Import all solutions. Import all solutions from yaml file without specifying the solution category. File name and format are extracted from command line option -f|--file. """ content = {'data': [Solution.KAFKA, Solution.BEATS]} file_content = Content.get_file_content(Content.YAML, content) with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file: yaml.safe_load.return_value = file_content cause = snippy.run( ['snippy', 'import', '-f', './all-solutions.yaml']) assert cause == Cause.ALL_OK Content.assert_storage(content) mock_file.assert_called_once_with('./all-solutions.yaml', 'r')