Exemplo n.º 1
0
    def test_cli_update_solution_012(snippy, editor_data):
        """Update solution with editor.

        Update existing Markdown native solution. Editor must show existing
        Markdown native content as is. Updated content must be identified as
        Markdown native content. Editor must be used by default when the
        ``--editor`` option is not used.

        In this case the links must be empty when stored. The edited content
        did not have any links in the content data so they must be updated
        to stored content.
        """

        content = {'data': [Content.deepcopy(Solution.KAFKA_MKDN)]}
        edited = (
            '# Testing docker log drivers @docker', '',
            '> Investigate docker log drivers and the logs2kafka log plugin',
            '', '> [1] https://github.com/MickayG/moby-kafka-logdriver  ',
            '[2] https://github.com/garo/logs2kafka  ',
            '[3] https://groups.google.com/forum/#!topic/kubernetes-users/iLDsG85exRQ',
            '', '## Description', '', 'Investigate docker log drivers.', '',
            '## Solutions', '', '## Whiteboard', '', '## Meta', '',
            '> category  : solution  ',
            'created   : 2019-01-04T10:54:49.265512+00:00  ',
            'digest    : c54c8a896b94ea35edf6c798879957419d26268bd835328d74b19a6e9ce2324d  ',
            'filename  : kubernetes-docker-log-driver-kafka.mkdn  ',
            'languages :  ', 'name      :  ', 'source    :  ',
            'tags      : docker,driver,kafka,kubernetes,logging,logs2kafka,moby,plugin  ',
            'updated   : 2019-01-05T10:54:49.265512+00:00  ',
            'uuid      : 24cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions  :  ', '')
        updates = content
        updates['data'][0]['data'] = ('## Description', '',
                                      'Investigate docker log drivers.', '',
                                      '## Solutions', '', '## Whiteboard', '')
        updates['data'][0][
            'description'] = 'Investigate docker log drivers and the logs2kafka log plugin'
        updates['data'][0]['links'] = ()
        updates['data'][0]['updated'] = Content.BEATS_TIME
        updates['data'][0]['uuid'] = Solution.KAFKA_MKDN_UUID
        updates['data'][0][
            'digest'] = '7941851522a23d3651f223b6d69441f77649ccb7ae1e72c6709890f2caf6401a'
        editor_data.return_value = '\n'.join(edited)
        cause = snippy.run([
            'snippy', 'update', '-d', 'c54c8a896b94ea35', '--scat', 'solution'
        ])
        editor_data.assert_called_with(Content.dump_mkdn(Solution.KAFKA_MKDN))
        assert cause == Cause.ALL_OK
        Content.assert_storage(updates)
Exemplo n.º 2
0
    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)
    def test_cli_create_solution_006(snippy):
        """Create solution from editor.

        Create new solution by defining all values from editor.
        """

        content = {
            'data': [
                Content.deepcopy(Solution.BEATS)
            ]
        }
        content['data'][0]['uuid'] = Content.UUID_EDIT
        cause = snippy.run(['snippy', 'create', '--scat', 'solution', '--editor', '--format', 'text'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 4
0
    def test_cli_create_reference_010(snippy, editor_data):
        """Create reference with editor.

        Create a new reference by using the prefilled default Markdown template
        in editor. In this case the metadata section is not touched and there
        is the example content left. The example values for attributes must not
        be used when the content is created.
        """

        content = {'data': [Content.deepcopy(Reference.GITLOG)]}
        content['data'][0]['tags'] = ()
        content['data'][0]['uuid'] = Content.UUID1
        content['data'][0][
            'digest'] = '7093775e077941bad7a707295feb6a6630458f89e18a35994179e27fc4937b02'
        template = (
            '# Add brief title for content @groups', '',
            '> Add a description that defines the content in one chapter.', '',
            '> [1] https://www.example.com/add-links-here.html', '', '## Meta',
            '', '> category : reference  ',
            'created  : 2018-06-22T13:11:13.678729+00:00  ',
            'digest   : bb4c2540fab3a12b051b77b6902f426812ec95f8a1fa9e07ca1b7dc3cca0cc0d  ',
            'filename : example-content.md  ',
            'name     : example content handle  ',
            'source   : https://www.example.com/source.md  ',
            'tags     : example,tags  ',
            'updated  : 2018-06-22T13:11:13.678729+00:00  ',
            'uuid     : a1cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions : example=3.9.0,python>=3  ', '')
        edited = (
            '# How to write commit messages @git', '', '> ', '',
            '> [1] https://chris.beams.io/posts/git-commit/', '',
            '`$ docker rm --volumes $(docker ps --all --quiet)`', '',
            '## Meta', '', '> category : reference  ',
            'created  : 2018-06-22T13:11:13.678729+00:00  ',
            'digest   : 7093775e077941bad7a707295feb6a6630458f89e18a35994179e27fc4937b02  ',
            'filename : example-content.md  ',
            'name     : example content handle  ',
            'source   : https://www.example.com/source.md  ',
            'tags     : example,tags  ',
            'updated  : 2018-06-22T13:11:13.678729+00:00  ',
            'uuid     : a1cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions : example=3.9.0,python>=3  ', '')
        editor_data.return_value = Const.NEWLINE.join(edited)
        cause = snippy.run(
            ['snippy', 'create', '--scat', 'reference', '--editor'])
        assert cause == Cause.ALL_OK
        editor_data.assert_called_with(Const.NEWLINE.join(template))
        Content.assert_storage(content)
Exemplo n.º 5
0
    def test_cli_update_snippet_002(snippy, edited_remove):
        """Update snippet with ``--digest`` option.

        Update snippet based on very short message digest. This must match to
        a single snippet that must be updated.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE), Snippet.FORCED]}
        content['data'][0]['data'] = ('docker images', )
        content['data'][0][
            'digest'] = 'af8c89629dc1a5313fd15c95fa9c1199b2b99874426e0b2532a952f40dcf980d'
        edited_remove.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run(
            ['snippy', 'update', '-d', '54e41', '--format', 'text'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 6
0
    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_create_snippet_009(snippy, editor_data):
        """Create snippet with editor.

        Create a new snippet by using the prefilled default Markdown template
        in editor. The template presented in editor is manually defined in this
        test case on purpose. This tries to verity that the testing framework
        does not hide problems compared to situation where the template would
        be generated automatically by the testing framework.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE)]}
        content['data'][0]['uuid'] = Content.UUID1
        template = (
            '# Add brief title for content @groups', '',
            '> Add a description that defines the content in one chapter.', '',
            '> [1] https://www.example.com/add-links-here.html', '',
            '`$ Markdown commands are defined between backtics and prefixed by a dollar sign`',
            '', '## Meta', '', '> category  : snippet  ',
            'created   : 2017-10-14T19:56:31.000001+00:00  ',
            'digest    : 8d5193fea452d0334378a73ded829cfa27debea7ee87714d64b1b492d1a4601a  ',
            'filename  : example-content.md  ',
            'languages : example-language  ',
            'name      : example content handle  ',
            'source    : https://www.example.com/source.md  ',
            'tags      : example,tags  ',
            'updated   : 2017-10-14T19:56:31.000001+00:00  ',
            'uuid      : a1cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions  : example=3.9.0,python>=3  ', '')
        edited = (
            '# Remove all docker containers with volumes @docker', '', '> ',
            '',
            '> [1] https://docs.docker.com/engine/reference/commandline/rm/',
            '', '`$ docker rm --volumes $(docker ps --all --quiet)`', '',
            '## Meta', '', '> category  : snippet  ',
            'created   : 2017-10-14T19:56:31.000001+00:00  ',
            'digest    : 18473ec207798670c302fb711a40df6555e8973e26481e4cd6b2ed205f5e633c  ',
            'filename  :  ', 'languages :  ', 'name      :  ', 'source    :  ',
            'tags      : cleanup,container,docker,docker-ce,moby  ',
            'updated   : 2017-10-14T19:56:31.000001+00:00  ',
            'uuid      : a1cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions  :  ', '')
        editor_data.return_value = Const.NEWLINE.join(edited)
        cause = snippy.run(['snippy', 'create', '--editor'])
        assert cause == Cause.ALL_OK
        editor_data.assert_called_with(Const.NEWLINE.join(template))
        Content.assert_storage(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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    def test_cli_update_reference_011(snippy, edited_gitlog):
        """Update reference with ``content`` option.

        Try to update reference with empty content links. Nothing must be
        updated in this case because links are mandatory item in reference
        content.
        """

        content = {'data': [Reference.GITLOG, Reference.REGEXP]}
        updates = Content.deepcopy(Reference.GITLOG)
        updates['links'] = ()
        edited_gitlog.return_value = Content.dump_text(updates)
        cause = snippy.run([
            'snippy', 'update', '--scat', 'reference', '-d', '5c2071094dbfaa33'
        ])
        assert cause == 'NOK: content was not stored because mandatory content field links is empty'
        Content.assert_storage(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_create_snippet_001(snippy):
        """Create snippet from CLI.

        Create new snippet by defining all content parameters from command
        line.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE)]}
        content['data'][0]['uuid'] = Content.UUID1
        data = Const.DELIMITER_DATA.join(content['data'][0]['data'])
        brief = content['data'][0]['brief']
        groups = Const.DELIMITER_GROUPS.join(content['data'][0]['groups'])
        tags = Const.DELIMITER_TAGS.join(content['data'][0]['tags'])
        links = Const.DELIMITER_LINKS.join(content['data'][0]['links'])
        cause = snippy.run(['snippy', 'create', '--content', data, '--brief', brief, '--groups', groups, '--tags', tags, '--links', links])  # pylint: disable=line-too-long
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
    def test_cli_create_reference_005(snippy, editor_data):
        """Create reference with editor.

        Create a new reference by using the prefilled default Markdown template
        in editor. The template presented in editor is manually defined in this
        test case on purpose. This tries to verity that the testing framework
        does not hide problems compared to situation where the template would
        be generated automatically by the testing framework.
        """

        content = {'data': [Content.deepcopy(Reference.GITLOG)]}
        content['data'][0]['uuid'] = Content.UUID1
        template = (
            '# Add brief title for content @groups', '',
            '> Add a description that defines the content in one chapter.', '',
            '> [1] https://www.example.com/add-links-here.html', '', '## Meta',
            '', '> category  : reference  ',
            'created   : 2018-06-22T13:11:13.678729+00:00  ',
            'digest    : bb4c2540fab3a12b051b77b6902f426812ec95f8a1fa9e07ca1b7dc3cca0cc0d  ',
            'filename  : example-content.md  ',
            'languages : example-language  ',
            'name      : example content handle  ',
            'source    : https://www.example.com/source.md  ',
            'tags      : example,tags  ',
            'updated   : 2018-06-22T13:11:13.678729+00:00  ',
            'uuid      : a1cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions  : example=3.9.0,python>=3  ', '')
        edited = (
            '# How to write commit messages @git', '', '> ', '',
            '> [1] https://chris.beams.io/posts/git-commit/', '',
            '`$ docker rm --volumes $(docker ps --all --quiet)`', '',
            '## Meta', '', '> category  : reference  ',
            'created   : 2018-06-22T13:11:13.678729+00:00  ',
            'digest    : bb4c2540fab3a12b051b77b6902f426812ec95f8a1fa9e07ca1b7dc3cca0cc0d  ',
            'filename  :  ', 'languages :  ', 'name      :  ', 'source    :  ',
            'tags      : commit,git,howto  ',
            'updated   : 2018-06-22T13:11:13.678729+00:00  ',
            'uuid      : a1cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions  :  ', '')
        editor_data.return_value = Const.NEWLINE.join(edited)
        cause = snippy.run(
            ['snippy', 'create', '--scat', 'reference', '--editor'])
        assert cause == Cause.ALL_OK
        editor_data.assert_called_with(Const.NEWLINE.join(template))
        Content.assert_storage(content)
Exemplo n.º 14
0
    def test_cli_update_snippet_004(snippy, edited_remove):
        """Update snippet with ``--digest`` option.

        Update snippet based on message digest and explicitly define the
        content category.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE), Snippet.FORCED]}
        content['data'][0]['data'] = ('docker images', )
        content['data'][0][
            'digest'] = 'af8c89629dc1a5313fd15c95fa9c1199b2b99874426e0b2532a952f40dcf980d'
        edited_remove.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '--scat', 'snippet', '-d', '54e41e9b52a02b63',
            '--format', 'text'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 15
0
    def test_cli_update_snippet_009(snippy, edited_remove):
        """Update snippet with ``--content`` option.

        Update snippet based on content data.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE), Snippet.FORCED]}
        content['data'][0]['data'] = ('docker images', )
        content['data'][0][
            'digest'] = 'af8c89629dc1a5313fd15c95fa9c1199b2b99874426e0b2532a952f40dcf980d'
        edited_remove.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '-c',
            'docker rm --volumes $(docker ps --all --quiet)', '--format',
            'text', '--editor'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 16
0
    def test_cli_update_solution_003(snippy, edited_beats):
        """Update solution with ``--digest`` option.

        Update solution based on long message digest. Only the content data
        is updated.
        """

        content = {'data': [Content.deepcopy(Solution.BEATS), Solution.NGINX]}
        content['data'][0]['data'] = tuple([
            line.replace('## Description', '## updated desc')
            for line in content['data'][0]['data']
        ])
        content['data'][0]['description'] = ''
        content['data'][0][
            'digest'] = '23312e20cb961d46b3fb0ac5a63dacfbb16f13a220b48250019977940e9720f3'
        edited_beats.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run(['snippy', 'update', '--scat', 'solution', '-d', '4346ba4c792474308bc66bd16d747875bef9b431044824987e302b726c1d298e', '--format', 'text'])  # pylint: disable=line-too-long
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 17
0
    def test_cli_update_snippet_014(snippy, editor_data):
        """Update snippet from command line.

        Update existing snippet directly from command line. In this case,
        editor is not used because of '--no-editor' option which updates
        given content directly without user interaction.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE)]}
        content['data'][0]['brief'] = 'brief cli'
        content['data'][0]['groups'] = ('cli-group', )
        content['data'][0]['tags'] = ('cli-tag', )
        content['data'][0]['links'] = ('https://cli-link', )
        content['data'][0][
            'digest'] = '613e163028a17645a7dfabbe159f05d14db7588259229dd8d08e949cdc668373'
        cause = snippy.run(['snippy', 'update', '-d', '54e41e9b52a02b63', '-t', 'cli-tag', '-b', 'brief cli', '-g', 'cli-group', '-l', 'https://cli-link', '--no-editor'])  # pylint: disable=line-too-long
        assert cause == Cause.ALL_OK
        editor_data.assert_not_called()
        Content.assert_storage(content)
Exemplo n.º 18
0
    def test_cli_update_snippet_003(snippy, edited_remove):
        """Update snippet with ``--digest`` option.

        Update snippet based on long message digest. Only the content data is
        updated.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE), Snippet.FORCED]}
        content['data'][0]['data'] = ('docker images', )
        content['data'][0][
            'digest'] = 'af8c89629dc1a5313fd15c95fa9c1199b2b99874426e0b2532a952f40dcf980d'
        edited_remove.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '-d',
            '54e41e9b52a02b631b5c65a6a053fcbabc77ccd42b02c64fdfbc76efdb18e319',
            '--format', 'text'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
    def test_cli_create_snippet_002(snippy):
        """Create snippet from CLI.

        Create new snippet with all content parameters but only one tag.
        """

        content = {'data': [Content.deepcopy(Snippet.REMOVE)]}
        content['data'][0]['uuid'] = Content.UUID1
        content['data'][0]['tags'] = (content['data'][0]['tags'][0], )
        content['data'][0][
            'digest'] = 'f94cf88b1546a8fd5cb442d39f5d598cee6db666a0577de3c6e046782b339a59'
        data = Const.DELIMITER_DATA.join(content['data'][0]['data'])
        brief = content['data'][0]['brief']
        groups = Const.DELIMITER_GROUPS.join(content['data'][0]['groups'])
        tags = Const.DELIMITER_TAGS.join(content['data'][0]['tags'])
        links = Const.DELIMITER_LINKS.join(content['data'][0]['links'])
        cause = snippy.run(['snippy', 'create', '--content', data, '--brief', brief, '--groups', groups, '--tags', tags, '--links', links])  # pylint: disable=line-too-long
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 20
0
    def test_cli_update_reference_009(snippy, edited_gitlog):
        """Update reference with ``content`` option.

        Update reference based on content links.
        """

        content = {
            'data': [Content.deepcopy(Reference.GITLOG), Reference.REGEXP]
        }
        content['data'][0]['links'] = ('https://docs.docker.com', )
        content['data'][0][
            'digest'] = '1fc34e79a4d2bac51a039b7265da464ad787da41574c3d6651dc6a128d4c7c10'
        edited_gitlog.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '--scat', 'reference', '-l',
            'https://chris.beams.io/posts/git-commit/'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 21
0
    def test_cli_update_reference_002(snippy, edited_gitlog):
        """Update reference with ``digest`` option.

        Update reference based on very short message digest. This must match
        to a single reference that must be updated.
        """

        content = {
            'data': [Content.deepcopy(Reference.GITLOG), Reference.REGEXP]
        }
        content['data'][0]['links'] = ('https://docs.docker.com', )
        content['data'][0][
            'digest'] = '1fc34e79a4d2bac51a039b7265da464ad787da41574c3d6651dc6a128d4c7c10'
        edited_gitlog.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '--scat', 'reference', '--digest', '5c2071',
            '--format', 'text'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 22
0
    def test_cli_update_reference_012(snippy, edited_gitlog):
        """Update reference with editor.

        Update existing reference by defining all values from editor. In this
        case the reference is existing and previously stored data must be set
        into editor on top of the default template. In this case the regexp
        reference is edited to gitlog reference. The case verifies that editor
        shows the regexp reference and not an empty reference template.
        """

        content = {'data': [Content.deepcopy(Reference.GITLOG)]}
        content['data'][0]['uuid'] = Reference.REGEXP_UUID
        edited_gitlog.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '-d', 'cb9225a81eab8ced', '--scat',
            'reference', '--editor', '--format', 'text'
        ])
        edited_gitlog.assert_called_with(Content.dump_text(Reference.REGEXP))
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 23
0
    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)
Exemplo n.º 24
0
    def test_cli_update_reference_007(snippy, edited_gitlog):
        """Update reference with ``uuid`` option.

        Update reference based on uuid. The content must be updated so that
        only links get updated.
        """

        content = {
            'data': [Content.deepcopy(Reference.GITLOG), Reference.REGEXP]
        }
        content['data'][0]['links'] = ('https://docs.docker.com', )
        content['data'][0][
            'digest'] = '1fc34e79a4d2bac51a039b7265da464ad787da41574c3d6651dc6a128d4c7c10'
        edited_gitlog.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '--scat', 'reference', '-u',
            '31cd5827-b6ef-4067-b5ac-3ceac07dde9f', '--format', 'text'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 25
0
    def test_cli_update_reference_004(snippy, edited_gitlog):
        """Update reference with ``digest`` option.

        Update reference based on message digest and accidentally implicitly
        use snippet category by not using content category option that
        defaults to snippet category. In this case the reference is updated
        properly regardless of incorrect category.
        """

        content = {
            'data': [Content.deepcopy(Reference.GITLOG), Reference.REGEXP]
        }
        content['data'][0]['links'] = ('https://docs.docker.com', )
        content['data'][0][
            'digest'] = '1fc34e79a4d2bac51a039b7265da464ad787da41574c3d6651dc6a128d4c7c10'
        edited_gitlog.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run(
            ['snippy', 'update', '-d', '5c2071094dbfaa33', '--format', 'text'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Exemplo n.º 26
0
    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)
Exemplo n.º 27
0
    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)
Exemplo n.º 29
0
    def test_cli_import_reference_014(snippy):
        """Import reference based on uuid.

        Import defined reference based on uuid.
        """

        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', '-u', '31cd5827-b6ef-4067-b5ac-3ceac07dde9f', '-f', 'one-reference.yaml'])  # pylint: disable=line-too-long
            assert cause == Cause.ALL_OK
            Content.assert_storage(content)
            mock_file.assert_called_once_with('one-reference.yaml', 'r')
Exemplo n.º 30
0
    def test_cli_update_solution_011(snippy, edited_beats):
        """Update solution with editor.

        Update existing solution by defining all values from editor. In this
        case the solution is existing and previously stored data must be set
        into editor on top of the default template. In this case the ngingx
        solution is edited to beats solution. The case verifies that editor
        shows the ngingx solution and not an empty solution template.
        """

        content = {'data': [Content.deepcopy(Solution.BEATS)]}
        content['data'][0]['uuid'] = Solution.NGINX_UUID
        edited_beats.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run([
            'snippy', 'update', '-d', '6cfe47a8880a8f81', '--scat', 'solution',
            '--editor', '--format', 'text'
        ])
        edited_beats.assert_called_with(Content.dump_text(Solution.NGINX))
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)