Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
    def test_cli_export_snippet_029(snippy):
        """Export all snippets.

        Export snippets in Markdown format. This case verified that there are
        two spaces at the end of lists like links, data and metadata. This
        forces newlines in exported Markdown format.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Snippet.EXITED]}
        markdown = (
            '# Remove all exited containers and dangling images @docker', '',
            '> ', '',
            '> [1] https://docs.docker.com/engine/reference/commandline/images/  ',
            '[2] https://docs.docker.com/engine/reference/commandline/rm/  ',
            '[3] https://docs.docker.com/engine/reference/commandline/rmi/',
            '', '`$ docker rm $(docker ps --all -q -f status=exited)`  ',
            '`$ docker images -q --filter dangling=true | xargs docker rmi`',
            '', '## Meta', '', '> category : snippet  ',
            'created  : 2017-10-20T07:08:45.000001+00:00  ',
            'digest   : 49d6916b6711f13d67960905c4698236d8a66b38922b04753b99d42a310bcf73  ',
            'filename :  ', 'name     :  ', 'source   :  ',
            'tags     : cleanup,container,docker,docker-ce,image,moby  ',
            'updated  : 2017-10-20T07:08:45.000001+00:00  ',
            'uuid     : 13cd5827-b6ef-4067-b5ac-3ceac07dde9f  ',
            'versions :  ', '')
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '-f', './snippets.mkdn'])
            assert cause == Cause.ALL_OK
            assert mock_file.return_value.__enter__.return_value.write.mock_calls[
                0][1][0] == '\n'.join(markdown)
            Content.assert_mkdn(mock_file, './snippets.mkdn', content)
    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_reference_020(snippy):
        """Export defaults with ``scat`` option.

        Export snippet, solution and reference defaults with category
        set to ``all`` and so that the defauls will be updated. This must
        store the content from each category to own file that stores the
        default content.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Snippet.REMOVE, Solution.BEATS, Reference.GITLOG]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(
                ['snippy', 'export', '--defaults', '--scat', 'all'])
            assert cause == Cause.ALL_OK
            defaults_snippets = pkg_resources.resource_filename(
                'snippy', 'data/defaults/snippets.yaml')
            defaults_solutions = pkg_resources.resource_filename(
                'snippy', 'data/defaults/solutions.yaml')
            defaults_references = pkg_resources.resource_filename(
                'snippy', 'data/defaults/references.yaml')
            Content.assert_yaml(
                yaml, mock_file,
                [defaults_snippets, defaults_solutions, defaults_references],
                content)
    def test_cli_export_reference_016(snippy):
        """Export defined reference with content data.

        Export defined reference based on content data. File name is defined in
        command line as yaml file.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Reference.GITLOG]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '-c', 'https://chris.beams.io/posts/git-commit/', '-f', 'defined-reference.yaml', '--scat', 'reference'])  # pylint: disable=line-too-long
            assert cause == Cause.ALL_OK
            Content.assert_yaml(yaml, mock_file, 'defined-reference.yaml',
                                content)
Exemple #8
0
    def test_cli_export_snippet_006(snippy):
        """Export defined snippets.

        Export defined snippet based on message digest. File name is not
        defined in command line -f|--file option. This should result usage
        of default file name and format
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Snippet.FORCED]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '-d', '53908d68425c61dc'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './snippets.mkdn', content)
Exemple #9
0
    def test_cli_export_snippet_011(snippy):
        """Export defined snippets.

        Export defined snippet based on search keyword. File name is not
        defined in command line -f|--file option. This should result usage
        of default file name and format snippet.text.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Snippet.FORCED]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '--sall', 'force'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './snippets.mkdn', content)
Exemple #10
0
    def test_cli_export_snippet_020(snippy):
        """Export defined snippet with content data.

        Export defined snippet based on content data. File name is defined in
        command line as json file.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [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.json'])  # pylint: disable=line-too-long
            assert cause == Cause.ALL_OK
            Content.assert_json(json, mock_file, 'defined-snippet.json',
                                content)
    def test_cli_export_reference_004(snippy):
        """Export all references.

        Export defined reference based on message digest. File name is not
        defined in command line -f|--file option. This should result usage
        of default file name and format even when the content category is
        not explicitly defined from command line.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Reference.REGEXP]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '-d', 'cb9225a81eab8ced'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './references.mkdn', content)
    def test_cli_export_reference_009(snippy):
        """Export all references.

        Export defined reference based on uuid.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Reference.REGEXP]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run([
                'snippy', 'export', '-u',
                '32cd5827-b6ef-4067-b5ac-3ceac07dde9f'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './references.mkdn', content)
Exemple #13
0
    def test_cli_export_snippet_027(snippy):
        """Export all snippets.

        Export all snippets in Markdown format.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Snippet.REMOVE, Snippet.FORCED]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '-f', './snippets.mkdn'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './snippets.mkdn', content)
Exemple #14
0
    def test_cli_export_solution_033(snippy):
        """Export all solutions.

        Export content only from solution and reference categories.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Solution.BEATS, Solution.NGINX, Reference.GITLOG]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(
                ['snippy', 'export', '--scat', 'solution,reference'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './content.mkdn', content)
    def test_cli_export_snippet_003(snippy):
        """Export all snippets.

        Export all snippets into yaml file defined from command line.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [
                Snippet.REMOVE,
                Snippet.FORCED
            ]
        }
        with mock.patch('snippy.content.migrate.open', mock.mock_open(), create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '-f', './defined-snippets.yaml'])
            assert cause == Cause.ALL_OK
            Content.assert_yaml(yaml, mock_file, './defined-snippets.yaml', 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_snippet_013(snippy):
        """Export defined snippets.

        Export defined snippet based on search keyword. File name is defined
        in command line as json file.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [
                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.json'])
            assert cause == Cause.ALL_OK
            Content.assert_json(json, mock_file, 'defined-snippet.json', 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)
Exemple #19
0
    def test_cli_export_solution_001(snippy):
        """Export all solutions.

        Export all solutions into file. File name or format are not defined
        in command line which must result tool default file and format.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Solution.BEATS, Solution.NGINX]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '--scat', 'solution'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './solutions.mkdn', content)
    def test_cli_export_reference_025(snippy):
        """Exporting defaults while using search category.

        Export default content by selecting single category with the --scat
        option.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Reference.GITLOG]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(
                ['snippy', 'export', '--scat', 'reference', '--default'])
            assert cause == Cause.ALL_OK
            defaults_references = pkg_resources.resource_filename(
                'snippy', 'data/defaults/references.yaml')
            Content.assert_yaml(yaml, mock_file, defaults_references, content)
Exemple #21
0
    def test_cli_export_solution_034(snippy):
        """Export all references.

        Export content only from reference category when the operation
        category is set to solution. In this case the search category must
        override the content category and only references are exported.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Reference.GITLOG]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run([
                'snippy', 'export', '--scat', 'solution', '--scat', 'reference'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './references.mkdn', content)
    def test_cli_export_reference_001(snippy):
        """Export all references.

        Export all references without defining target filename with ``--file``
        option. In this case the default filename and format are used.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Reference.GITLOG, Reference.REGEXP]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '--scat', 'reference'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './references.mkdn', content)
    def test_cli_export_reference_011(snippy):
        """Export defined reference with digest.

        Export defined reference based on search keyword. File name is not
        defined in command line -f|--file option. This should result usage
        of default file name and format.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Reference.REGEXP]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run([
                'snippy', 'export', '--sall', 'regexp', '--scat', 'reference'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './references.mkdn', content)
    def test_cli_export_snippet_008(snippy):
        """Export defined snippets.

        Export defined snippet based on message digest. File name is defined
        in command line as json file.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [
                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.json'])
            assert cause == Cause.ALL_OK
            Content.assert_json(json, mock_file, 'defined-snippet.json', content)
Exemple #25
0
    def test_cli_export_snippet_002(snippy):
        """Export all snippets.

        Export all snippets without defining target file name from command
        line. In this case the content category is defined explicitly.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Snippet.REMOVE, Snippet.FORCED]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '--scat', 'snippet'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './snippets.mkdn', content)
Exemple #26
0
    def test_cli_export_solution_013(snippy):
        """Export defined solution with digest.

        Export defined solution based on message digest to json file without
        specifying the content category explicitly.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [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.json'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_json(json, mock_file, './defined-solution.json',
                                content)
    def test_cli_export_reference_006(snippy):
        """Export all references.

        Export defined reference based on message digest. File name is defined
        in command line as json file.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [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.json'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_json(json, mock_file, 'defined-reference.json',
                                content)
Exemple #28
0
    def test_cli_export_snippet_026(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 default
        file since the -f|-file option is not used.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Snippet.REMOVE, Snippet.FORCED]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '--sall', 'docker'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './snippets.mkdn', content)
Exemple #29
0
    def test_cli_export_snippet_018(snippy):
        """Export defined snippet with content data.

        Export defined snippet based on content data. File name is not defined
        in command line -f|--file option. This should result usage of default
        file name and format snippet.text.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Snippet.REMOVE]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run([
                'snippy', 'export', '--content',
                'docker rm --volumes $(docker ps --all --quiet)'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './snippets.mkdn', content)
Exemple #30
0
    def test_cli_export_snippet_024(snippy):
        """Export snippet defaults.

        Export snippet defaults. All snippets should be exported into
        predefined file location under tool data folder in yaml format.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Snippet.REMOVE, Snippet.FORCED]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run(['snippy', 'export', '--defaults'])
            assert cause == Cause.ALL_OK
            defaults_snippets = pkg_resources.resource_filename(
                'snippy', 'data/defaults/snippets.yaml')
            Content.assert_yaml(yaml, mock_file, defaults_snippets, content)