コード例 #1
0
    def test_cli_delete_snippet_001(snippy):
        """Delete snippet with digest.

        Delete snippet with short 16 byte version of message digest.
        """

        content = {'data': [Snippet.REMOVE]}
        Content.assert_storage_size(2)
        cause = snippy.run(['snippy', 'delete', '-d', '53908d68425c61dc'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #2
0
    def test_cli_delete_solution_002(snippy):
        """Delete solution with digest.

        Delete solution with without explicitly specifying solution category.
        """

        content = {'data': [Solution.BEATS]}
        Content.assert_storage_size(2)
        cause = snippy.run(['snippy', 'delete', '-d', '6cfe47a8880a8f81'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #3
0
    def test_cli_delete_solution_004(snippy):
        """Delete solution with digest.

        Delete solution with long 16 byte version of message digest.
        """

        content = {'data': [Solution.BEATS]}
        Content.assert_storage_size(2)
        cause = snippy.run(['snippy', 'delete', '--scat', 'solution', '-d', '6cfe47a8880a8f81b66ff6bd71e795069ed1dfdd259c9fd181133f683c7697eb'])  # pylint: disable=line-too-long
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #4
0
    def test_cli_delete_reference_001(snippy):
        """Delete reference with digest.

        Delete reference with short 16 byte version of message digest.
        """

        content = {'data': [Reference.GITLOG]}
        Content.assert_storage_size(2)
        cause = snippy.run(['snippy', 'delete', '-d', 'cb9225a81eab8ced'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #5
0
    def test_cli_delete_snippet_004(snippy):
        """Delete snippet with dgiest.

        Delete snippet with empty message digest when there is only one
        content stored. In this case the last content can be deleted with
        empty digest.
        """

        Content.assert_storage_size(1)
        cause = snippy.run(['snippy', 'delete', '-d', ''])
        assert cause == Cause.ALL_OK
        Content.assert_storage(None)
コード例 #6
0
    def test_cli_delete_snippet_002(snippy):
        """Delete snippet with digest.

        Delete snippet with very short version of digest that matches to one
        snippet.
        """

        content = {'data': [Snippet.FORCED]}
        Content.assert_storage_size(2)
        cause = snippy.run(['snippy', 'delete', '-d', '54e41'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #7
0
    def test_cli_delete_snippet_012(snippy):
        """Delete snippet with search.

        Delete snippet based on search keyword that results one hit. In this
        case the content is deleted.
        """

        content = {'data': [Snippet.REMOVE]}
        Content.assert_storage_size(2)
        cause = snippy.run(['snippy', 'delete', '--sall', 'redis'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #8
0
    def test_cli_delete_reference_004(snippy):
        """Delete reference with uuid.

        Try to delete reference with short content UUID. Since the UUID is
        unique, this must not delete the content.
        """

        content = {'data': [Reference.GITLOG, Reference.REGEXP]}
        Content.assert_storage_size(2)
        cause = snippy.run(['snippy', 'delete', '-u', '16cd5827'])
        assert cause == 'NOK: cannot find content with content uuid: 16cd5827'
        Content.assert_storage(content)
コード例 #9
0
    def test_cli_delete_solution_001(snippy):
        """Delete solution with digest.

        Delete solution with short 16 byte version of message digest.
        """

        content = {'data': [Solution.BEATS]}
        Content.assert_storage_size(2)
        cause = snippy.run([
            'snippy', 'delete', '--scat', 'solution', '-d', '6cfe47a8880a8f81'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #10
0
    def test_cli_delete_solution_009(snippy):
        """Delete solution with data.

        Delete solution based on content data.
        """

        content = {'data': [Solution.BEATS]}
        Content.assert_storage_size(2)
        data = '\n'.join(Solution.NGINX['data'])
        cause = snippy.run(
            ['snippy', 'delete', '--scat', 'solution', '--content', data])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #11
0
    def test_cli_delete_reference_012(snippy):
        """Delete reference with search.

        Delete reference based on search keyword that results one hit. In this
        case the content is deleted.
        """

        content = {'data': [Reference.REGEXP]}
        Content.assert_storage_size(2)
        cause = snippy.run(
            ['snippy', 'delete', '--sall', 'chris', '--scat', 'reference'])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #12
0
    def test_cli_delete_snippet_003(snippy):
        """Delete snippet with digest.

        Delete snippet with long 16 byte version of message digest.
        """

        content = {'data': [Snippet.FORCED]}
        Content.assert_storage_size(2)
        cause = snippy.run([
            'snippy', 'delete', '-d',
            '54e41e9b52a02b631b5c65a6a053fcbabc77ccd42b02c64fdfbc76efdb18e319'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #13
0
    def test_cli_delete_snippet_008(snippy):
        """Delete snippet with data.

        Delete snippet based on content data.
        """

        content = {'data': [Snippet.FORCED]}
        Content.assert_storage_size(2)
        cause = snippy.run([
            'snippy', 'delete', '--content',
            'docker rm --volumes $(docker ps --all --quiet)'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #14
0
    def test_cli_delete_reference_010(snippy):
        """Delete reference with link.

        Delete reference based on content link.
        """

        content = {'data': [Reference.REGEXP]}
        Content.assert_storage_size(2)
        cause = snippy.run([
            'snippy', 'delete', '--links',
            'https://chris.beams.io/posts/git-commit/'
        ])
        assert cause == Cause.ALL_OK
        Content.assert_storage(content)
コード例 #15
0
    def test_cli_performance(self, snippy_perf, capsys, caplog):
        """Test CLI performance.

        Verify performance of the tool on a rough scale. The intention
        is to keep a reference test that is just iterated few times and
        the time consumed is measured. This is more for manual analysis
        than automation as of now.

        Reference PC:   1 loop :  0.0252 /   55 loop :  1.0865 / 100 loop : 1.9484
        Reference PC: 880 loop : 17.6897 / 1000 loop : 19.6802

        The reference is with sqlite database in memory as with all tests.
        There is naturally jitter in results and the values are as of now
        hand picked from few examples.

        Note that when run on Python2, will use sqlite database in disk
        that is naturally slower than memory database.

        No errors should be printed and the runtime should be below 10
        seconds. The runtime is intentionally set 15 times higher value
        than with the reference PC to cope with slow test envrironments.
        """

        start = time.time()
        for _ in range(55):
            self.create_defaults(snippy_perf)
            Content.assert_storage_size(4)

            # Search all content.
            cause = snippy_perf.run(
                ['snippy', 'search', '--scat', 'all', '--sall', '.'] +
                Content.db_cli_params())
            assert cause == Cause.ALL_OK

            # Delete all content.
            cause = snippy_perf.run(
                ['snippy', 'delete', '-d', '54e41e9b52a02b63'] +
                Content.db_cli_params())
            assert cause == Cause.ALL_OK
            cause = snippy_perf.run(
                ['snippy', 'delete', '-d', '53908d68425c61dc'] +
                Content.db_cli_params())
            assert cause == Cause.ALL_OK
            cause = snippy_perf.run(
                ['snippy', 'delete', '-d', '4346ba4c79247430'] +
                Content.db_cli_params())
            assert cause == Cause.ALL_OK
            cause = snippy_perf.run(
                ['snippy', 'delete', '-d', '6cfe47a8880a8f81'] +
                Content.db_cli_params())
            assert cause == Cause.ALL_OK
            Content.assert_storage(None)

        runtime = time.time() - start
        out, err = capsys.readouterr()
        print("====================================")
        print("Runtime %.4f" % runtime)
        print("There are %d rows in stdout" % len(out))
        print("There are %d rows in stderr" % len(err))
        print("====================================")

        assert not err
        assert not caplog.records[:]
        assert runtime < 15