Example #1
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)
Example #2
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)
Example #3
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)
Example #4
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)
    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)
Example #6
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)
    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)
Example #8
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)
Example #9
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_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)
Example #11
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)
Example #12
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_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)
Example #14
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)
Example #15
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)
Example #16
0
    def test_cli_export_solution_032(snippy):
        """Export all solutions.

        Export all content by defining the content category to --scat option.
        """

        content = {
            'meta':
            Content.get_cli_meta(),
            'data':
            [Snippet.REMOVE, 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', 'snippet,reference,solution'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './content.mkdn', content)
Example #17
0
    def test_cli_export_solution_036(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 default
        file since the -f|-file option is not used.
        """

        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', '--sall', 'howto'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './solutions.mkdn', content)
Example #18
0
    def test_cli_export_solution_037(snippy):
        """Export all solutions.

        Export all snippets in Markdown 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', '-f',
                './all-solutions.md'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './all-solutions.md', content)
    def test_cli_export_reference_029(snippy):
        """Export all references.

        Export all references in Markdown format.
        """

        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', '--file',
                'references.mkdn'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, 'references.mkdn', content)
    def test_cli_export_reference_023(snippy):
        """Export content with search keyword.

        Export content from one category when search category is set to
        search from two categories. In this case -f|--file option is not
        used and the content must be stored into a single file defined
        by the searched category.
        """

        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,snippet', '--sall',
                'git'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './references.mkdn', content)
    def test_cli_export_reference_021(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 default
        file since the -f|-file option is not 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', '--sall', 'howto', '--scat', 'reference'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './references.mkdn', content)
Example #22
0
    def test_cli_export_solution_041(snippy):
        """Export defined solution with digest.

        Export text native content when the ``filename`` attribute defines the
        default file as text file. In this case the ``--format`` option defines
        that the exported file must be Markdown file. Command line option must
        always override other configuration.
        """

        content = {'meta': Content.get_cli_meta(), 'data': [Solution.KAFKA]}
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run([
                'snippy', 'export', '-d', 'ee3f2ab7c63d6965', '--format',
                'mkdn'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file,
                                'kubernetes-docker-log-driver-kafka.mkdn',
                                content)
    def test_cli_export_reference_022(snippy):
        """Export content with search keyword.

        Export content from two categories with search keyword. In this case
        -f|--file option is not used and the content must be stored into a
        single default file and format.
        """

        content = {
            'meta': Content.get_cli_meta(),
            'data': [Reference.GITLOG, Snippet.REMOVE]
        }
        with mock.patch('snippy.content.migrate.open',
                        mock.mock_open(),
                        create=True) as mock_file:
            cause = snippy.run([
                'snippy', 'export', '--scat', 'reference,snippet', '--sall',
                'volumes,git'
            ])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file, './content.mkdn', content)
Example #24
0
    def test_cli_export_solution_038(snippy):
        """Export defined solution with digest.

        Export Markdown native solution. The solution data must not be
        surrounded with additional Markdown code blocks that are added for
        text content. The exported file name must be based on content
        metadata because the file name is not defined from command line.
        """

        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'])
            assert cause == Cause.ALL_OK
            Content.assert_mkdn(mock_file,
                                'kubernetes-docker-log-driver-kafka.mkdn',
                                content)