Beispiel #1
0
 def test_commit_hash(self):
     with self.assertRaises(validate.ValidationError):
         patch = None
         is_merge = False
         valid_sig = False
         commit_hash = 'not a real commit hash'
         validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
    def test_number_of_files(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff0b5ff1bde469dfcf0a3fbeef1224d61d05e570
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 16:40:10 2016 -0400

                two new files

            diff --git a/file3 b/file3
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file3
            @@ -0,0 +1 @@
            +file1
            diff --git a/file4 b/file4
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file4
            @@ -0,0 +1 @@
            +file1
            ''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError, '^Only 1 file per commit'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
 def test_commit_hash(self):
     with self.assertRaises(validate.ValidationError):
         patch = None
         is_merge = False
         valid_sig = False
         commit_hash = 'not a real commit hash'
         validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
Beispiel #4
0
    def test_number_of_files(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff0b5ff1bde469dfcf0a3fbeef1224d61d05e570
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 16:40:10 2016 -0400

                two new files

            diff --git a/file3 b/file3
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file3
            @@ -0,0 +1 @@
            +file1
            diff --git a/file4 b/file4
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file4
            @@ -0,0 +1 @@
            +file1
            ''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError,
                                     '^Only 1 file per commit'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
 def test_pow_fail(self):
     with self.assertRaisesRegexp(validate.ValidationError, '^Invalid proof of work'):
         patch = None
         is_merge = False
         valid_sig = False
         # The 2 leading digins are the source of work comparision
         commit_hash = '009f2c7fd25e1b3afad3e85a0bd17d9b100db4b3'
         validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
Beispiel #6
0
 def test_pow_fail(self):
     with self.assertRaisesRegexp(validate.ValidationError,
                                  '^Invalid proof of work'):
         patch = None
         is_merge = False
         valid_sig = False
         # The 2 leading digins are the source of work comparision
         commit_hash = '009f2c7fd25e1b3afad3e85a0bd17d9b100db4b3'
         validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
    def test_remove_files(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff12d98751c3ecaa816f56637360a4321b287857
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 15:28:14 2016 -0400

                rm a file

            diff --git a/file1 b/file1
            deleted file mode 100644
            index e212970..0000000
            --- a/file1
            +++ /dev/null
            @@ -1 +0,0 @@
            -file1''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError, '^No files can be removed'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
    def test_bad_date(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff18a9854424717420f138f7a282ea1ea62f0731
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 14:42:36 2016 -0400

                wrong path files

            diff --git a/file1 b/file1
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file1
            @@ -0,0 +1 @@
            +this is some random data''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError, '^invalid literal'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
    def test_wrong_schema(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff18a9854424717420f138f7a282ea1ea62f0731
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 14:42:36 2016 -0400

                wrong path files

            diff --git a/file1 b/file1
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file1
            @@ -0,0 +1 @@
            +d4:data17:This is a message6:parent40:4b1584a4dde35c7a9aa531b04f8df76d520b2a36e''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaises(voluptuous.MultipleInvalid):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
    def test_file_path(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff18a9854424717420f138f7a282ea1ea62f0731
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 14:42:36 2016 -0400

                wrong path files

            diff --git a/file1 b/file1
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file1
            @@ -0,0 +1 @@
            +d4:data17:This is a message11:parent_sha140:4b1584a4dde35c7a9aa531b04f8df76d520b2a36e''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError, 'Target file file1 is not named data/3f31cf174065d55f6fec9dc5fdec003bdd8df363'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
    def test_one_new_file(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ffe763251a92e4f318d76a6df0fcd1d81d4befc4
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 15:42:21 2016 -0400

                modify a file

            diff --git a/file2 b/file2
            index 6c493ff..3408900 100644
            --- a/file2
            +++ b/file2
            @@ -1 +1,2 @@
             file2
            +file2''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError, '^One new file per commit'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
Beispiel #12
0
    def test_remove_files(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff12d98751c3ecaa816f56637360a4321b287857
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 15:28:14 2016 -0400

                rm a file

            diff --git a/file1 b/file1
            deleted file mode 100644
            index e212970..0000000
            --- a/file1
            +++ /dev/null
            @@ -1 +0,0 @@
            -file1''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError,
                                     '^No files can be removed'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
Beispiel #13
0
    def test_bad_date(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff18a9854424717420f138f7a282ea1ea62f0731
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 14:42:36 2016 -0400

                wrong path files

            diff --git a/file1 b/file1
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file1
            @@ -0,0 +1 @@
            +this is some random data''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError,
                                     '^invalid literal'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
Beispiel #14
0
    def test_wrong_schema(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff18a9854424717420f138f7a282ea1ea62f0731
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 14:42:36 2016 -0400

                wrong path files

            diff --git a/file1 b/file1
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file1
            @@ -0,0 +1 @@
            +d4:data17:This is a message6:parent40:4b1584a4dde35c7a9aa531b04f8df76d520b2a36e'''
                                ).split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaises(voluptuous.MultipleInvalid):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
Beispiel #15
0
    def test_one_new_file(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ffe763251a92e4f318d76a6df0fcd1d81d4befc4
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 15:42:21 2016 -0400

                modify a file

            diff --git a/file2 b/file2
            index 6c493ff..3408900 100644
            --- a/file2
            +++ b/file2
            @@ -1 +1,2 @@
             file2
            +file2''').split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(validate.ValidationError,
                                     '^One new file per commit'):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)
Beispiel #16
0
    def test_file_path(self):
        # This is not a an accurate commit
        lines = textwrap.dedent('''
            commit ff18a9854424717420f138f7a282ea1ea62f0731
            Author: Tim Watts <*****@*****.**>
            Date:   Tue Mar 22 14:42:36 2016 -0400

                wrong path files

            diff --git a/file1 b/file1
            new file mode 100644
            index 0000000..e212970
            --- /dev/null
            +++ b/file1
            @@ -0,0 +1 @@
            +d4:data17:This is a message11:parent_sha140:4b1584a4dde35c7a9aa531b04f8df76d520b2a36e'''
                                ).split('\n')

        commit_hash, valid_sig, is_merge, patch = validate.parse_diff(lines)
        with self.assertRaisesRegexp(
                validate.ValidationError,
                'Target file file1 is not named data/3f31cf174065d55f6fec9dc5fdec003bdd8df363'
        ):
            validate.make_assertions(commit_hash, valid_sig, is_merge, patch)