Beispiel #1
0
    def test_cli_update_solution_016(snippy, editor_data):
        """Update Markdown native solution with editor.

        Update existing text formatted solution first in text format, then
        in Markdown format and then again in text format without making any
        changes. The content must not change when updated between different
        formats.

        Each update must generate different timestamp in content ``updated``
        attribute.
        """

        content = {'data': [Content.deepcopy(Solution.KAFKA_MKDN)]}
        content['data'][0]['brief'] = 'Testing docker log drivers again'
        content['data'][0][
            'digest'] = 'b5e5242d971f561675558981b4f25d1e822db282145c4246e3bd50111146096c'
        template = Content.dump_text(content['data'][0])
        editor_data.return_value = template
        content['data'][0]['updated'] = '2017-10-20T06:16:27.000001+00:00'
        cause = snippy.run([
            'snippy', 'update', '-d', 'c54c8a896b94ea35e', '--format', 'text',
            '--brief', 'Testing docker log drivers again'
        ])
        editor_data.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)

        content['data'][0][
            'brief'] = 'Testing docker log drivers again in mkdn'
        content['data'][0][
            'digest'] = '243e51c8b99c80fb73c30b8d72618f8c3bc094df04184da8209f147138067083'
        template = Content.dump_mkdn(content['data'][0])
        editor_data.return_value = template
        content['data'][0]['updated'] = '2017-11-20T06:16:27.000001+00:00'
        cause = snippy.run(['snippy', 'update', '-d', 'b5e5242d971f5616', '--format', 'mkdn', '--brief', 'Testing docker log drivers again in mkdn'])  # pylint: disable=line-too-long
        editor_data.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)

        content['data'][0]['brief'] = 'Testing docker log drivers again'
        content['data'][0][
            'digest'] = 'b5e5242d971f561675558981b4f25d1e822db282145c4246e3bd50111146096c'
        template = Content.dump_text(content['data'][0])
        editor_data.return_value = template
        content['data'][0]['updated'] = '2017-12-20T06:16:27.000001+00:00'
        cause = snippy.run([
            'snippy', 'update', '-d', '243e51c8b99c80fb', '--format', 'text',
            '--brief', 'Testing docker log drivers again'
        ])
        editor_data.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Beispiel #2
0
    def test_cli_update_solution_015(snippy, editor_data):
        """Update text native solution with editor.

        Update existing text formatted solution first in text format, then
        in Markdown format and then again in text format without making any
        changes. The content must not change when updated between different
        formats.

        Each update must generate different timestamp in content ``updated``
        attribute.
        """

        content = {'data': [Content.deepcopy(Solution.KAFKA)]}
        content['data'][0]['brief'] = 'Testing docker log drivers again'
        content['data'][0][
            'digest'] = '1072f9a0ddb2ab15a7f6cca0acd9f7e48903faa576fb19eca4e0ec98dc20c041'
        template = Content.dump_text(content['data'][0])
        editor_data.return_value = template
        cause = snippy.run([
            'snippy', 'update', '-d', 'ee3f2ab7c63d6965', '--format', 'text',
            '--brief', 'Testing docker log drivers again'
        ])
        editor_data.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)

        content['data'][0][
            'brief'] = 'Testing docker log drivers again in mkdn'
        content['data'][0][
            'digest'] = '2887f455e73ad3a6040df7299e69548748db5eb208b9c7eb4717aa2527af4778'
        template = Content.dump_mkdn(content['data'][0])
        editor_data.return_value = template
        content['data'][0]['updated'] = '2017-11-20T06:16:27.000001+00:00'
        cause = snippy.run(['snippy', 'update', '-d', '1072f9a0ddb2ab15', '--format', 'mkdn', '--brief', 'Testing docker log drivers again in mkdn'])  # pylint: disable=line-too-long
        editor_data.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)

        content['data'][0]['brief'] = 'Testing docker log drivers again'
        content['data'][0][
            'digest'] = '1072f9a0ddb2ab15a7f6cca0acd9f7e48903faa576fb19eca4e0ec98dc20c041'
        template = Content.dump_text(content['data'][0])
        editor_data.return_value = template
        content['data'][0]['updated'] = '2017-12-20T06:16:27.000001+00:00'
        cause = snippy.run([
            'snippy', 'update', '-d', '2887f455e73ad3a6', '--format', 'text',
            '--brief', 'Testing docker log drivers again'
        ])
        editor_data.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Beispiel #3
0
    def test_cli_update_reference_016(snippy, edited_gitlog):
        """Update reference with editor.

        Update existing resource without doing any changes to the resource.
        The ``updated`` timestamp must not be changed because the resource
        was not changed.
        """

        content = {'data': [Reference.GITLOG]}
        edited_gitlog.return_value = Content.dump_text(content['data'][0])
        cause = snippy.run(
            ['snippy', 'update', '-d', '5c2071094dbfaa', '--format', 'text'])
        edited_gitlog.assert_called_with(Content.dump_text(Reference.GITLOG))
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Beispiel #4
0
    def test_cli_update_reference_015(snippy, edited_gitlog):
        """Update reference with editor.

        Update existing Mkdn formatted reference first in text format, then
        in Text format and then again in Markdown format without making any
        changes. The content must not change when updated between different
        formats.

        Each update must generate different timestamp in content ``updated``
        attribute. Also the last update must produce the same resource as
        the first update.

        The content in editor is explicitly defined in the test to avoid
        false positives from the test helpers that actually use the code
        itself.
        """

        content = {'data': [Content.deepcopy(Reference.GITLOG)]}
        content['data'][0]['tags'] = ('commit', )
        content['data'][0][
            'digest'] = '2dcb254063ccb5bbc27796df96033f89dae33dde53dbc038d4532e1a798c97c0'
        template = Content.dump_mkdn(content['data'][0])
        edited_gitlog.return_value = template
        cause = snippy.run([
            'snippy', 'update', '-d', '5c2071094dbfaa33', '--editor',
            '--format', 'mkdn', '--tags', 'commit'
        ])
        edited_gitlog.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)

        content['data'][0]['tags'] = ('git', )
        content['data'][0][
            'digest'] = 'b2228e2cc6e3d7fe01257f615175a1f33e617b0cfba55199a93e7e48dcdbecf1'
        template = Content.dump_text(content['data'][0])
        edited_gitlog.return_value = template
        content['data'][0]['updated'] = '2018-07-22T13:11:13.678729+00:00'
        cause = snippy.run([
            'snippy', 'update', '-d', '2dcb254063ccb5bbc', '--editor',
            '--format', 'text', '--tags', 'git'
        ])
        edited_gitlog.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)

        content['data'][0]['tags'] = ('commit', )
        content['data'][0][
            'digest'] = '2dcb254063ccb5bbc27796df96033f89dae33dde53dbc038d4532e1a798c97c0'
        template = Content.dump_mkdn(content['data'][0])
        edited_gitlog.return_value = template
        content['data'][0]['updated'] = '2018-08-22T13:11:13.678729+00:00'
        cause = snippy.run([
            'snippy', 'update', '-d', 'b2228e2cc6e3d7fe', '--editor',
            '--format', 'mkdn', '--tags', 'commit'
        ])
        edited_gitlog.assert_called_with(template)
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
    def test_cli_delete_solution_011(snippy):
        """Delete solution with data.

        Try to delete solution with content data that does not exist. In this
        case the content data is truncated.
        """

        content = {'data': [Solution.BEATS, Solution.NGINX]}
        data = Content.dump_text(Solution.KAFKA)
        cause = snippy.run(
            ['snippy', 'delete', '--scat', 'solution', '--content', data])
        assert cause == 'NOK: cannot find content with content data: ##############################...'
        Content.assert_storage(content)
    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)
Beispiel #9
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_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)
    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)
Beispiel #12
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)
    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)
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #18
0
    def test_cli_update_solution_008(snippy, edited_beats):
        """Update solution with ``--content`` option.

        Update solution based on content data.
        """

        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])
        data = Const.NEWLINE.join(Solution.BEATS['data'])
        cause = snippy.run([
            'snippy', 'update', '--scat', 'solution', '-c', data, '--format',
            'text', '--editor'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Beispiel #19
0
    def test_cli_update_solution_002(snippy, edited_beats):
        """Update solution with ``--digest`` option.

        Update solution with very short message digest. This must match to a
        single solution that must be 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', '--digest', '4346b',
            '--format', 'text'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Beispiel #20
0
    def test_cli_update_solution_005(snippy, edited_beats):
        """Update solution with ``--digest`` option.

        Update solution 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 solution is updated
        properly regardless of incorrect category.
        """

        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', '-d', '4346ba4c79247430', '--format', 'text'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
Beispiel #21
0
    def test_cli_update_solution_001(snippy, edited_beats):
        """Update solution with ``--digest`` option.

        Update solution with short message digest. Only the content data is
        updated. Because the description tag was changed, the ``description``
        attribute is not read and it results an empty string.
        """

        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', '4346ba4c79247430',
            '--format', 'text'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)