Exemplo n.º 1
0
 def setUp(self):
     self.config = Config(['/repo'])
     self.repo = RepositoryMock()
     self.writer = DumpWriterMock(self)
     self.interesting_paths = InterestingPaths()
     self.builder = LumpBuilder(self.config, self.repo,
                                self.interesting_paths, self.writer)
    def test_get_interesting_sub_directories(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/ca')
        interesting_path.mark_path_as_interesting('a/b/cb')
        interesting_path.mark_path_as_boring('a/b/ca/x')
        interesting_path.mark_path_as_boring('a/y')
        
        dirs = sorted(interesting_path.get_interesting_sub_directories('a/b'))
        self.assertEqual(dirs, [ 'a/b/ca', 'a/b/cb' ])

        self.assertEqual([], interesting_path.get_interesting_sub_directories("a/b/c/x"))
Exemplo n.º 3
0
 def setUp(self):
     self.config = Config([ '/dummy' ])
     self.interesting_paths = InterestingPaths()
     self.repo = RepositoryMock()
     self.builder = LumpBuilderMock()
     self.dump_filter = DumpFilter(
         config = self.config,
         source_repository = self.repo,
         interesting_paths = self.interesting_paths,
         lump_builder = self.builder
     )
Exemplo n.º 4
0
    def test_include_with_exclude(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/c')
        interesting_path.mark_path_as_boring('a/b/c/x')

        self.assertTrue(interesting_path.is_interesting('a/b/c'))
        self.assertTrue(interesting_path.is_interesting('a/b/c/d'))
        self.assertFalse(interesting_path.is_interesting('a/b'))
        self.assertFalse(interesting_path.is_interesting('x/y'))
        self.assertFalse(interesting_path.is_interesting('a/b/c/x'))
        self.assertFalse(interesting_path.is_interesting('a/b/c/x/y'))
Exemplo n.º 5
0
 def setUp(self):
     self.config = Config(['/dummy'])
     self.interesting_paths = InterestingPaths()
     self.repo = RepositoryMock()
     self.repo.revision_properties_by_revision[3] = [
         'some author', 'some date', 'same log message'
     ]
     self.builder = LumpBuilderMock()
     self.boots_trapper = BootsTrapper(
         config=self.config,
         source_repository=self.repo,
         interesting_paths=self.interesting_paths,
         lump_builder=self.builder)
Exemplo n.º 6
0
    def test_get_interesting_sub_directories(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/ca')
        interesting_path.mark_path_as_interesting('a/b/cb')
        interesting_path.mark_path_as_boring('a/b/ca/x')
        interesting_path.mark_path_as_boring('a/y')

        dirs = sorted(interesting_path.get_interesting_sub_directories('a/b'))
        self.assertEqual(dirs, ['a/b/ca', 'a/b/cb'])

        self.assertEqual([], interesting_path.get_interesting_sub_directories("a/b/c/x"))
    def test_simple_include(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/c')

        self.assertTrue(interesting_path.is_interesting('a/b/c'))
        self.assertTrue(interesting_path.is_interesting('a/b/c/d'))
        self.assertFalse(interesting_path.is_interesting('a/b'))
        self.assertFalse(interesting_path.is_interesting('x/y'))
Exemplo n.º 8
0
 def setUp(self):
     self.config = Config([ '/dummy' ])
     self.interesting_paths = InterestingPaths()
     self.repo = RepositoryMock()
     self.repo.revision_properties_by_revision[3] = [ 'some author', 'some date', 'same log message' ]
     self.builder = LumpBuilderMock()
     self.boots_trapper = BootsTrapper(
         config = self.config,
         source_repository = self.repo,
         interesting_paths = self.interesting_paths,
         lump_builder = self.builder
     )
Exemplo n.º 9
0
    def test_simple_include(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/c')

        self.assertTrue(interesting_path.is_interesting('a/b/c'))
        self.assertTrue(interesting_path.is_interesting('a/b/c/d'))
        self.assertFalse(interesting_path.is_interesting('a/b'))
        self.assertFalse(interesting_path.is_interesting('x/y'))
Exemplo n.º 10
0
    def test_empty_string(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('')

        self.assertTrue(interesting_path.is_interesting('a'))
        self.assertTrue(interesting_path.is_interesting('b'))

        dirs = sorted(interesting_path.get_interesting_sub_directories('a'))
        self.assertEqual(dirs, [ 'a' ])

        dirs = sorted(interesting_path.get_interesting_sub_directories(''))
        self.assertEqual(dirs, [ '' ])
Exemplo n.º 11
0
    def test_empty_string(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('')

        self.assertTrue(interesting_path.is_interesting('a'))
        self.assertTrue(interesting_path.is_interesting('b'))

        dirs = sorted(interesting_path.get_interesting_sub_directories('a'))
        self.assertEqual(dirs, ['a'])

        dirs = sorted(interesting_path.get_interesting_sub_directories(''))
        self.assertEqual(dirs, [''])
Exemplo n.º 12
0
class TestLumpBuilder(TestCase):

    def setUp(self):
        self.config = Config(['/repo'])
        self.repo = RepositoryMock()
        self.writer = DumpWriterMock(self)
        self.interesting_paths = InterestingPaths();
        self.builder = LumpBuilder(self.config, self.repo, self.interesting_paths, self.writer);

    def test_delete_lump(self):
        self.builder.delete_path('a/b/c')

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), [ 'Node-path', 'Node-action' ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/c')
        self.assertEqual(lump.get_header('Node-action'), 'delete')

    def test_mkdir(self):
        self.builder.mkdir('a/b/c')

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), [ 'Node-path', 'Node-kind', 'Node-action' ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/c')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')

    def test_add_file_from_source_repo(self):
        self.repo.files_by_name_and_revision['file/in/source/repo_rev17'] = { 17: 'xxx' }
        self.repo.properties_by_path_and_revision['file/in/source/repo_rev17'] = { 17:  { 'a': 'x1', 'b': 'x2' } }
        
        self.builder.get_node_from_source('file', 'a/b', 'add', 'file/in/source/repo_rev17', 17)
        
        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Text-content-length', 'Text-content-md5' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '3')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, { 'a': 'x1', 'b': 'x2' } )
        self.writer.check_content_tin_of_lump_nr(0, 'xxx')

    def test_add_file_from_source_repo_via_recursive_call(self):
        self.repo.files_by_name_and_revision['file/in/source/repo_rev17'] = { 17: 'xxx' }
        self.repo.properties_by_path_and_revision['file/in/source/repo_rev17'] = { 17:  { 'a': 'x1', 'b': 'x2' } }
        
        self.builder.get_recursively_from_source('file', 'a/b', 'add', 'file/in/source/repo_rev17', 17)
        
        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Text-content-length', 'Text-content-md5' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '3')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, { 'a': 'x1', 'b': 'x2' } )
        self.writer.check_content_tin_of_lump_nr(0, 'xxx')

    def test_add_dir_from_source_repo(self):
        self.repo.tree_by_path_and_revision['dir/in/source/repo_rev2'] = { 2: [ 'dir/in/source/repo_rev2/' ] }
        self.repo.properties_by_path_and_revision['dir/in/source/repo_rev2'] = { 2:  { 'a2': 'y1', 'b2': 'y2' } }

        self.builder.get_node_from_source('dir', 'a/b', 'add', 'dir/in/source/repo_rev2/', 2)
        
        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { 'a2': 'y1', 'b2': 'y2' } )
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_add_path_from_target(self):
        self.builder.get_path_from_target('file', 'new/path', 'add', 'source/path', 17)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Node-copyfrom-path', 'Node-copyfrom-rev' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'new/path')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Node-copyfrom-path'), 'source/path')
        self.assertEqual(lump.get_header('Node-copyfrom-rev'), '17')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_clone_change_lump_from_add_lump(self):
        sample_lump = SvnLump()
        sample_lump.set_header('Node-path', 'a/b/c')
        sample_lump.set_header('Node-kind', 'file')
        sample_lump.set_header('Node-action', 'add')
        sample_lump.set_header('Text-content-length', '3')
        sample_lump.set_header('Text-content-md5', 'FAKEMD5')
        sample_lump.set_header('Node-copyfrom-path', 'blubber')
        sample_lump.set_header('Node-copyfrom-rev', '2')
        sample_lump.properties =  { 'a': 'x1', 'b': 'x2' }
        sample_fh = StringIO("abcXXX")
        sample_tin = ContentTin(sample_fh, 3, 'FAKEMD5')
        sample_lump.content = sample_tin

        self.builder.change_lump_from_add_or_replace_lump(sample_lump)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-action', 'Text-content-length', 'Text-content-md5' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b/c')
        self.assertEqual(lump.get_header('Node-action'), 'change')
        self.assertEqual(lump.get_header('Text-content-length'), '3')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, { 'a': 'x1', 'b': 'x2' } )
        self.writer.check_content_tin_of_lump_nr(0, 'abc')

    def test_revision_header(self):
        self.repo.revision_properties_by_revision[23] = [ 'testuser', 'some date', 'log message' ]
        
        self.builder.revision_header(23, 'my title')

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Revision-number' ]
        )
        self.assertEqual(lump.get_header('Revision-number'), '23')
        self.assertEqual(lump.properties, { 'svn:author': 'testuser', 'svn:date': 'some date', 'svn:log': 'my title' })
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_dump_header_lumps(self):
        self.builder.dump_header_lumps()

        self.assertEqual(len(self.writer.lumps), 2)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), [ 'SVN-fs-dump-format-version' ])
        self.assertEqual(lump.get_header('SVN-fs-dump-format-version'), '2')
        self.assertEqual(lump.properties, { })
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(lump.get_header_keys(), [ 'UUID' ])
        self.assertEqual(lump.get_header('UUID'), 'fake-uuid')
        self.assertEqual(lump.properties, { })
        self.writer.check_content_tin_of_lump_nr(1, None)

    def test_pass_lump(self):
        sample_lump = SvnLump()
        sample_lump.set_header('Marker', 'abc')

        self.builder.pass_lump(sample_lump)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Marker' ]
        )
        self.assertEqual(lump.get_header('Marker'), 'abc')
        self.assertEqual(lump.properties, { })
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_add_tree_from_source(self):
        self.repo.tree_by_path_and_revision['source/dir'] = { 2: [ 'source/dir/', 'source/dir/x', 'source/dir/y' ] }
        self.repo.properties_by_path_and_revision['source/dir'] = { 2: { 'a2': 'y1', 'b2': 'y2' } }
        self.repo.files_by_name_and_revision['source/dir/x'] = { 2: 'x' }
        self.repo.properties_by_path_and_revision['source/dir/x'] = { 2: { } }
        self.repo.files_by_name_and_revision['source/dir/y'] = { 2: 'y' }
        self.repo.properties_by_path_and_revision['source/dir/y'] = { 2: { } }
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.builder.get_recursively_from_source('dir', 'a/b', 'add', 'source/dir', 2)

        self.assertEqual(len(self.writer.lumps), 3)
        
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { 'a2': 'y1', 'b2': 'y2' } )
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Text-content-length', 'Text-content-md5' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b/x')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '1')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(1, 'x')

        lump = self.writer.lumps[2]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Text-content-length', 'Text-content-md5' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b/y')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '1')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(2, 'y')

    def test_add_tree_from_source_with_boring_path(self):
        self.repo.tree_by_path_and_revision['source/dir'] = { 2: [ 'source/dir/', 'source/dir/x', 'source/dir/y' ] }
        self.repo.properties_by_path_and_revision['source/dir'] = { 2: { 'a2': 'y1', 'b2': 'y2' } }
        self.repo.files_by_name_and_revision['source/dir/x'] = { 2: 'x' }
        self.repo.properties_by_path_and_revision['source/dir/x'] = { 2: { } }
        self.repo.files_by_name_and_revision['source/dir/y'] = { 2: 'y' }
        self.repo.properties_by_path_and_revision['source/dir/y'] = { 2: { } }
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.interesting_paths.mark_path_as_boring('a/b/x')

        self.builder.get_recursively_from_source('dir', 'a/b', 'add', 'source/dir/', 2)

        self.assertEqual(len(self.writer.lumps), 2)
        
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { 'a2': 'y1', 'b2': 'y2' } )
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Text-content-length', 'Text-content-md5' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b/y')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '1')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(1, 'y')

    def test_add_tree_from_source_with_current_tag(self):
        self.repo.tree_by_path_and_revision['source/dir'] = { 5: [ 'source/dir/', 'source/dir/x' ] }
        self.repo.properties_by_path_and_revision['source/dir'] = { 5: { 'a2': 'y1', 'b2': 'y2' } }
        self.repo.files_by_name_and_revision['source/dir/x'] = { 5: 'x' }
        self.repo.properties_by_path_and_revision['source/dir/x'] = { 5: { } }
        self.config.start_rev = 4
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a/tags/NEW_TAG', 'add', 'source/dir/', 5)

        self.assertEqual(len(self.writer.lumps), 0)
        self.assertFalse(self.interesting_paths.is_interesting('a/tags/NEW_TAG'))

    def test_add_tree_from_source_with_obsolte_tag(self):
        self.repo.tree_by_path_and_revision['source/dir'] = { 5: [ 'source/dir/', 'source/dir/x' ] }
        self.repo.properties_by_path_and_revision['source/dir'] = { 5: { 'a2': 'y1', 'b2': 'y2' } }
        self.repo.files_by_name_and_revision['source/dir/x'] = { 5: 'x' }
        self.repo.properties_by_path_and_revision['source/dir/x'] = { 5: { } }
        self.config.start_rev = 6
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a/tags/OLD_TAG', 'add', 'source/dir/', 5)

        self.assertEqual(len(self.writer.lumps), 0)
        self.assertFalse(self.interesting_paths.is_interesting('a/tags/OLD_TAG'))

    def test_add_tree_from_source_with_valid_tag_inside(self):
        self.repo.tree_by_path_and_revision['source/dir'] = { 5: [
            'source/dir/', 'source/dir/tags/', 'source/dir/tags/NEW_TAG/', 'source/dir/tags/NEW_TAG/x'
        ] }
        self.repo.properties_by_path_and_revision['source/dir'] = { 5: { } }
        self.repo.tree_by_path_and_revision['source/dir/tags'] = { 5: [
            'source/dir/tags/', 'source/dir/tags/NEW_TAG/', 'source/dir/tags/NEW_TAG/x'
        ] }
        self.repo.properties_by_path_and_revision['source/dir/tags'] = { 5: { } }
        self.repo.tree_by_path_and_revision['source/dir/tags/NEW_TAG'] = { 5: [
            'source/dir/tags/NEW_TAG/', 'source/dir/tags/NEW_TAG/x'
        ] }
        self.repo.properties_by_path_and_revision['source/dir/tags/NEW_TAG'] = { 5: { } }
        self.repo.files_by_name_and_revision['source/dir/tags/NEW_TAG/x'] = { 5: 'x' }
        self.repo.properties_by_path_and_revision['source/dir/tags/NEW_TAG/x'] = { 5: { } }
        self.config.start_rev = 3
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a', 'add', 'source/dir/', 5)
        
        self.assertEqual(len(self.writer.lumps), 2)
        self.assertFalse(self.interesting_paths.is_interesting('a/tags/NEW_TAG'))

        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/tags')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(1, None)

    def test_add_tree_from_source_with_obsolete_tag_inside(self):
        self.repo.tree_by_path_and_revision['source/dir'] = { 5: [
            'source/dir/', 'source/dir/tags/', 'source/dir/tags/OLD_TAG', 'source/dir/tags/OLD_TAG/x'
         ] }
        self.repo.properties_by_path_and_revision['source/dir'] = { 5: { } }
        self.repo.tree_by_path_and_revision['source/dir/tags'] = { 5: [
            'source/dir/tags/', 'source/dir/tags/OLD_TAG/', 'source/dir/tags/OLD_TAG/x'
        ] }
        self.repo.properties_by_path_and_revision['source/dir/tags'] = { 5: { } }
        self.repo.tree_by_path_and_revision['source/dir/tags/OLD_TAG'] = { 5: [
            'source/dir/tags/OLD_TAG', 'source/dir/tags/OLD_TAG/x'
        ] }
        self.repo.properties_by_path_and_revision['source/dir/tags/OLD_TAG'] = { 5: { } }
        self.repo.files_by_name_and_revision['source/dir/tags/OLD_TAG/x'] = { 5: 'x' }
        self.repo.properties_by_path_and_revision['source/dir/tags/OLD_TAG/x'] = { 5: { } }
        self.config.start_rev = 7
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a', 'add', 'source/dir/', 5)

        self.assertEqual(len(self.writer.lumps), 2)
        self.assertFalse(self.interesting_paths.is_interesting('a/tags/OLD_TAG'))
        
        lump = self.writer.lumps[0]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/tags')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { } )
        self.writer.check_content_tin_of_lump_nr(1, None)
Exemplo n.º 13
0
class TestDumpFilter(TestCase):
    def setUp(self):
        self.config = Config([ '/dummy' ])
        self.interesting_paths = InterestingPaths()
        self.repo = RepositoryMock()
        self.builder = LumpBuilderMock()
        self.dump_filter = DumpFilter(
            config = self.config,
            source_repository = self.repo,
            interesting_paths = self.interesting_paths,
            lump_builder = self.builder
        )

    def test_dump_empty(self):
        self.interesting_paths.mark_path_as_interesting('other/path')
        self.repo.dumps_by_revision[3] = DUMP_CHANGE_FILE_A_B

        self.dump_filter.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 1)
        self._verfiy_revision_header()

    def test_dump_simple(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.dumps_by_revision[3] = DUMP_CHANGE_FILE_A_B

        self.dump_filter.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)

        self._verfiy_revision_header()

        self.assertEqual(self.builder.call_history[1][0], 'pass_lump' )
        lump = self.builder.call_history[1][1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Text-content-length',
            'Text-content-md5', 'Text-content-sha1', 'Content-length' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'change')
        self._assertTin(lump, "y\n")

    def test_internal_copy(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.interesting_paths.mark_path_as_interesting('x/y')
        self.repo.dumps_by_revision[3] = DUMP_COPY_FILE_X_Y_TO_A_B

        self.dump_filter.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)
        self._verfiy_revision_header()

        self.assertEqual(self.builder.call_history[1][0], 'pass_lump' )
        lump = self.builder.call_history[1][1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Node-copyfrom-rev',
            'Node-copyfrom-path', 'Text-copy-source-md5', 'Text-copy-source-sha1' ]
        )
        self.assertEqual(lump.properties, { })
        self.assertEqual(lump.content, None)

    def test_copy_in(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.dumps_by_revision[3] = DUMP_COPY_FILE_X_Y_TO_A_B
        self.repo.files_by_name_and_revision['x/y'] = { 2: "xxx\n\yyy\n" }
        self.repo.properties_by_path_and_revision['x/y'] = { 2: { } }

        self.dump_filter.process_revision(3, None)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1],
            [ 'get_recursively_from_source', 'file', 'a/b', 'add', 'x/y', 2 ]
        )

    def test_copy_in_start_rev(self):
        self.config.start_rev = 3
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.interesting_paths.mark_path_as_interesting('x/y')
        self.repo.dumps_by_revision[3] = DUMP_COPY_FILE_X_Y_TO_A_B
        self.repo.files_by_name_and_revision['x/y'] = { 2: "xxx\n\yyy\n" }
        self.repo.properties_by_path_and_revision['x/y'] = { 2: { } }

        self.dump_filter.process_revision(3, None)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1],
            [ 'get_recursively_from_source', 'file', 'a/b', 'add', 'x/y', 2 ]
        )

    def test_copy_in_with_change(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.dumps_by_revision[3] = DUMP_COPY_FILE_X_Y_TO_A_B_WITH_CHANGE
        self.repo.files_by_name_and_revision['x/y'] = { 2: "xxx\n\yyy\n" }
        self.repo.properties_by_path_and_revision['x/y'] = { 2: { 'prop1': 'value1' } }

        self.dump_filter.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 3)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1], 
            [ 'get_recursively_from_source', 'file', 'a/b', 'add', 'x/y', 2 ]
        )

        self.assertEqual(self.builder.call_history[2][0], 'change_lump_from_add_or_replace_lump')
        lump = self.builder.call_history[2][1]
        self.assertEqual(
            lump.get_header_keys(),
            ['Node-path', 'Node-kind', 'Node-action', 'Node-copyfrom-rev', 'Node-copyfrom-path',
            'Text-copy-source-md5', 'Text-copy-source-sha1', 'Text-content-length', 'Text-content-md5',
            'Text-content-sha1', 'Prop-content-length', 'Content-length']
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, { 'propa': 'value2', 'propb': 'valueb' } )
        self._assertTin(lump, "y\n")

    def test_copy_in_dir(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.dumps_by_revision[3] = DUMP_COPY_DIR_X_Y_TO_A_B 
        self.repo.tree_by_path_and_revision['x/y'] = { 2: [ 'x/y/', 'x/y/c1', 'x/y/c2' ] }
        self.repo.files_by_name_and_revision['x/y/c1'] = { 2: "xxx\n\yy1\n" }
        self.repo.files_by_name_and_revision['x/y/c2'] = { 2: "xxx\n\yy2\n" }
        self.repo.properties_by_path_and_revision['x/y'] = { 2: { 'prop1': 'value1' } }
        self.repo.properties_by_path_and_revision['x/y/c1'] = { 2: { 'prop2': 'value2' } }
        self.repo.properties_by_path_and_revision['x/y/c2'] = { 2: { } }

        self.dump_filter.process_revision(3, None)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1],
            [ 'get_recursively_from_source', 'dir', 'a/b', 'add', 'x/y', 2 ]
        )
        
    def test_copy_to_path_above_from_boring(self):
        self.interesting_paths.mark_path_as_interesting('a/b/c1')
        self.repo.dumps_by_revision[3] = DUMP_COPY_DIR_X_Y_TO_A_B 
        self.repo.tree_by_path_and_revision['x/y'] = { 2: [ 'x/y/', 'x/y/c1', 'x/y/c2' ] }
        self.repo.files_by_name_and_revision['x/y/c1'] = { 2: "xxx\n\yy1\n" }
        self.repo.files_by_name_and_revision['x/y/c2'] = { 2: "xxx\n\yy2\n" }
        self.repo.properties_by_path_and_revision['x/y'] = { 2: { 'prop1': 'value1' } }
        self.repo.properties_by_path_and_revision['x/y/c1'] = { 2: { 'prop2': 'value2' } }
        self.repo.properties_by_path_and_revision['x/y/c2'] = { 2: { } }

        self.dump_filter.process_revision(3, None)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1],
            ['get_recursively_from_source', 'file', 'a/b/c1', 'add', 'x/y/c1', 2]
        )

    def test_copy_to_path_above_from_interesting(self):
        self.interesting_paths.mark_path_as_interesting('x/y')
        self.interesting_paths.mark_path_as_interesting('a/b/c1')
        self.repo.dumps_by_revision[3] = DUMP_COPY_DIR_X_Y_TO_A_B 
        self.repo.tree_by_path_and_revision['x/y'] = { 2: [ 'x/y/', 'x/y/c1', 'x/y/c2' ] }
        self.repo.files_by_name_and_revision['x/y/c1'] = { 2: "xxx\n\yy1\n" }
        self.repo.files_by_name_and_revision['x/y/c2'] = { 2: "xxx\n\yy2\n" }
        self.repo.properties_by_path_and_revision['x/y'] = { 2: { 'prop1': 'value1' } }
        self.repo.properties_by_path_and_revision['x/y/c1'] = { 2: { 'prop2': 'value2' } }
        self.repo.properties_by_path_and_revision['x/y/c2'] = { 2: { } }

        self.dump_filter.process_revision(3, None)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1],
            [ 'get_path_from_target', 'file', 'a/b/c1', 'add', 'x/y/c1', 2 ]
        )

    def test_copy_to_path_above_2_from_interesting(self):
        self.interesting_paths.mark_path_as_interesting('x/b')
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.dumps_by_revision[3] = DUMP_COPY_DIR_X_TO_A
        self.repo.tree_by_path_and_revision['x'] = { 2: [ 'x/', 'x/b/', 'x/b/c1', 'x/b/c2' ] }
        self.repo.tree_by_path_and_revision['x/b'] = { 2: [ 'x/b/', 'x/b/c1', 'x/b/c2' ] }
        self.repo.files_by_name_and_revision['x/b/c1'] = { 2: "xxx\n\yy1\n" }
        self.repo.files_by_name_and_revision['x/b/c2'] = { 2: "xxx\n\yy2\n" }
        self.repo.properties_by_path_and_revision['x/b'] = { 2: { 'prop1': 'value1' } }
        self.repo.properties_by_path_and_revision['x/b/c1'] = { 2: { 'prop2': 'value2' } }
        self.repo.properties_by_path_and_revision['x/b/c2'] = { 2: { } }

        self.dump_filter.process_revision(3, None)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1:], [
            [ 'get_path_from_target', 'dir', 'a/b', 'add', 'x/b', 2 ]
        ] )

    def test_delete_inside(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.dumps_by_revision[3] = DUMP_DELETE_FILE_A_B

        self.dump_filter.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1][0], 'pass_lump')

        lump = self.builder.call_history[1][1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-action' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-action'), 'delete')
        self.assertEqual(lump.properties, { })
        self.assertEqual(lump.content, None)

    def test_delete_over_existing(self):
        self.interesting_paths.mark_path_as_interesting('a/b/c')
        self.repo.dumps_by_revision[3] = DUMP_DELETE_FILE_A_B
        self.repo.files_by_name_and_revision['a/b/c'] = { 2: "xxx\n\yyy\n" }

        self.dump_filter.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1], 
            [ 'delete_path', 'a/b/c' ]
        )

    def test_unsupported_dump_version(self):
        self.interesting_paths.mark_path_as_interesting('a/b/c')
        self.repo.dumps_by_revision[3] = DUMP_UNSUPPORTED_VERSION
        self.repo.files_by_name_and_revision['a/b/c'] = { 2: "xxx\n\yyy\n" }

        self.assertRaises(UnsupportedDumpVersionException, self.dump_filter.process_revision, 3, None)

    def test_delete_over_non_existing(self):
        self.interesting_paths.mark_path_as_interesting('a/b/c')
        self.repo.dumps_by_revision[3] = DUMP_DELETE_FILE_A_B

        self.dump_filter.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 1)
        self._verfiy_revision_header()

    def test_replace_file_with_new_content(self):
        self.interesting_paths.mark_path_as_interesting('a')
        self.repo.dumps_by_revision[3] = DUMP_REPLACE_FILE_WITH_NEW_CONTENT

        self.dump_filter.process_revision(3, None)
        
        self._verfiy_revision_header()

        self.assertEqual(self.builder.call_history[1][0], 'pass_lump' )
        lump = self.builder.call_history[1][1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Node-path', 'Node-kind', 'Node-action', 'Text-content-length',
            'Text-content-md5', 'Text-content-sha1', 'Content-length' ]
        )
        self.assertEqual(lump.get_header('Node-path'), 'a/bla')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'replace')
        self._assertTin(lump, "ghi\n")

    def _verfiy_revision_header(self):
        self.assertEqual(self.builder.call_history[0][0], 'pass_lump')
        lump = self.builder.call_history[0][1]
        self.assertEqual(
            lump.get_header_keys(),
            [ 'Revision-number', 'Prop-content-length', 'Content-length' ]
        )
        self.assertEqual(lump.get_header('Revision-number'), '3')
        self.assertEqual(
            lump.properties,
            { 'svn:log': "Bl\n", 'svn:author': 'wilhelmh', 'svn:date': '2011-09-04T10:27:15.088237Z' }
        )

    def _assertTin(self, lump, expected_content):
        # Hack: Works only in conjunction with LumpBuilderMock
        self.assertEqual(lump.content, expected_content)
Exemplo n.º 14
0
 def setUp(self):
     self.config = Config(['/repo'])
     self.repo = RepositoryMock()
     self.writer = DumpWriterMock(self)
     self.interesting_paths = InterestingPaths();
     self.builder = LumpBuilder(self.config, self.repo, self.interesting_paths, self.writer);
Exemplo n.º 15
0
class TestLumpBuilder(TestCase):
    def setUp(self):
        self.config = Config(['/repo'])
        self.repo = RepositoryMock()
        self.writer = DumpWriterMock(self)
        self.interesting_paths = InterestingPaths()
        self.builder = LumpBuilder(self.config, self.repo,
                                   self.interesting_paths, self.writer)

    def test_delete_lump(self):
        self.builder.delete_path('a/b/c')

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), ['Node-path', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/c')
        self.assertEqual(lump.get_header('Node-action'), 'delete')

    def test_mkdir(self):
        self.builder.mkdir('a/b/c')

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/c')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')

    def test_add_file_from_source_repo(self):
        self.repo.files_by_name_and_revision['file/in/source/repo_rev17'] = {
            17: 'xxx'
        }
        self.repo.properties_by_path_and_revision[
            'file/in/source/repo_rev17'] = {
                17: {
                    'a': 'x1',
                    'b': 'x2'
                }
            }

        self.builder.get_node_from_source('file', 'a/b', 'add',
                                          'file/in/source/repo_rev17', 17)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), [
            'Node-path', 'Node-kind', 'Node-action', 'Text-content-length',
            'Text-content-md5'
        ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '3')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, {'a': 'x1', 'b': 'x2'})
        self.writer.check_content_tin_of_lump_nr(0, 'xxx')

    def test_add_file_from_source_repo_via_recursive_call(self):
        self.repo.files_by_name_and_revision['file/in/source/repo_rev17'] = {
            17: 'xxx'
        }
        self.repo.properties_by_path_and_revision[
            'file/in/source/repo_rev17'] = {
                17: {
                    'a': 'x1',
                    'b': 'x2'
                }
            }

        self.builder.get_recursively_from_source('file', 'a/b', 'add',
                                                 'file/in/source/repo_rev17',
                                                 17)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), [
            'Node-path', 'Node-kind', 'Node-action', 'Text-content-length',
            'Text-content-md5'
        ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '3')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, {'a': 'x1', 'b': 'x2'})
        self.writer.check_content_tin_of_lump_nr(0, 'xxx')

    def test_add_dir_from_source_repo(self):
        self.repo.tree_by_path_and_revision['dir/in/source/repo_rev2'] = {
            2: ['dir/in/source/repo_rev2/']
        }
        self.repo.properties_by_path_and_revision[
            'dir/in/source/repo_rev2'] = {
                2: {
                    'a2': 'y1',
                    'b2': 'y2'
                }
            }

        self.builder.get_node_from_source('dir', 'a/b', 'add',
                                          'dir/in/source/repo_rev2/', 2)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, {'a2': 'y1', 'b2': 'y2'})
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_add_path_from_target(self):
        self.builder.get_path_from_target('file', 'new/path', 'add',
                                          'source/path', 17)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), [
            'Node-path', 'Node-kind', 'Node-action', 'Node-copyfrom-path',
            'Node-copyfrom-rev'
        ])
        self.assertEqual(lump.get_header('Node-path'), 'new/path')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Node-copyfrom-path'), 'source/path')
        self.assertEqual(lump.get_header('Node-copyfrom-rev'), '17')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_clone_change_lump_from_add_lump(self):
        sample_lump = SvnLump()
        sample_lump.set_header('Node-path', 'a/b/c')
        sample_lump.set_header('Node-kind', 'file')
        sample_lump.set_header('Node-action', 'add')
        sample_lump.set_header('Text-content-length', '3')
        sample_lump.set_header('Text-content-md5', 'FAKEMD5')
        sample_lump.set_header('Node-copyfrom-path', 'blubber')
        sample_lump.set_header('Node-copyfrom-rev', '2')
        sample_lump.properties = {'a': 'x1', 'b': 'x2'}
        sample_fh = StringIO("abcXXX")
        sample_tin = ContentTin(sample_fh, 3, 'FAKEMD5')
        sample_lump.content = sample_tin

        self.builder.change_lump_from_add_or_replace_lump(sample_lump)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), [
            'Node-path', 'Node-action', 'Text-content-length',
            'Text-content-md5'
        ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/c')
        self.assertEqual(lump.get_header('Node-action'), 'change')
        self.assertEqual(lump.get_header('Text-content-length'), '3')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, {'a': 'x1', 'b': 'x2'})
        self.writer.check_content_tin_of_lump_nr(0, 'abc')

    def test_revision_header(self):
        self.repo.revision_properties_by_revision[23] = [
            'testuser', 'some date', 'log message'
        ]

        self.builder.revision_header(23, 'my title')

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), ['Revision-number'])
        self.assertEqual(lump.get_header('Revision-number'), '23')
        self.assertEqual(
            lump.properties, {
                'svn:author': 'testuser',
                'svn:date': 'some date',
                'svn:log': 'my title'
            })
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_dump_header_lumps(self):
        self.builder.dump_header_lumps()

        self.assertEqual(len(self.writer.lumps), 2)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(),
                         ['SVN-fs-dump-format-version'])
        self.assertEqual(lump.get_header('SVN-fs-dump-format-version'), '2')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(lump.get_header_keys(), ['UUID'])
        self.assertEqual(lump.get_header('UUID'), 'fake-uuid')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(1, None)

    def test_pass_lump(self):
        sample_lump = SvnLump()
        sample_lump.set_header('Marker', 'abc')

        self.builder.pass_lump(sample_lump)

        self.assertEqual(len(self.writer.lumps), 1)
        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(), ['Marker'])
        self.assertEqual(lump.get_header('Marker'), 'abc')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(0, None)

    def test_add_tree_from_source(self):
        self.repo.tree_by_path_and_revision['source/dir'] = {
            2: ['source/dir/', 'source/dir/x', 'source/dir/y']
        }
        self.repo.properties_by_path_and_revision['source/dir'] = {
            2: {
                'a2': 'y1',
                'b2': 'y2'
            }
        }
        self.repo.files_by_name_and_revision['source/dir/x'] = {2: 'x'}
        self.repo.properties_by_path_and_revision['source/dir/x'] = {2: {}}
        self.repo.files_by_name_and_revision['source/dir/y'] = {2: 'y'}
        self.repo.properties_by_path_and_revision['source/dir/y'] = {2: {}}
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.builder.get_recursively_from_source('dir', 'a/b', 'add',
                                                 'source/dir', 2)

        self.assertEqual(len(self.writer.lumps), 3)

        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, {'a2': 'y1', 'b2': 'y2'})
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(lump.get_header_keys(), [
            'Node-path', 'Node-kind', 'Node-action', 'Text-content-length',
            'Text-content-md5'
        ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/x')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '1')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(1, 'x')

        lump = self.writer.lumps[2]
        self.assertEqual(lump.get_header_keys(), [
            'Node-path', 'Node-kind', 'Node-action', 'Text-content-length',
            'Text-content-md5'
        ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/y')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '1')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(2, 'y')

    def test_add_tree_from_source_with_boring_path(self):
        self.repo.tree_by_path_and_revision['source/dir'] = {
            2: ['source/dir/', 'source/dir/x', 'source/dir/y']
        }
        self.repo.properties_by_path_and_revision['source/dir'] = {
            2: {
                'a2': 'y1',
                'b2': 'y2'
            }
        }
        self.repo.files_by_name_and_revision['source/dir/x'] = {2: 'x'}
        self.repo.properties_by_path_and_revision['source/dir/x'] = {2: {}}
        self.repo.files_by_name_and_revision['source/dir/y'] = {2: 'y'}
        self.repo.properties_by_path_and_revision['source/dir/y'] = {2: {}}
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.interesting_paths.mark_path_as_boring('a/b/x')

        self.builder.get_recursively_from_source('dir', 'a/b', 'add',
                                                 'source/dir/', 2)

        self.assertEqual(len(self.writer.lumps), 2)

        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a/b')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, {'a2': 'y1', 'b2': 'y2'})
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(lump.get_header_keys(), [
            'Node-path', 'Node-kind', 'Node-action', 'Text-content-length',
            'Text-content-md5'
        ])
        self.assertEqual(lump.get_header('Node-path'), 'a/b/y')
        self.assertEqual(lump.get_header('Node-kind'), 'file')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.get_header('Text-content-length'), '1')
        self.assertEqual(lump.get_header('Text-content-md5'), 'FAKEMD5')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(1, 'y')

    def test_add_tree_from_source_with_current_tag(self):
        self.repo.tree_by_path_and_revision['source/dir'] = {
            5: ['source/dir/', 'source/dir/x']
        }
        self.repo.properties_by_path_and_revision['source/dir'] = {
            5: {
                'a2': 'y1',
                'b2': 'y2'
            }
        }
        self.repo.files_by_name_and_revision['source/dir/x'] = {5: 'x'}
        self.repo.properties_by_path_and_revision['source/dir/x'] = {5: {}}
        self.config.start_rev = 4
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a/tags/NEW_TAG',
                                                 'add', 'source/dir/', 5)

        self.assertEqual(len(self.writer.lumps), 0)
        self.assertFalse(
            self.interesting_paths.is_interesting('a/tags/NEW_TAG'))

    def test_add_tree_from_source_with_obsolte_tag(self):
        self.repo.tree_by_path_and_revision['source/dir'] = {
            5: ['source/dir/', 'source/dir/x']
        }
        self.repo.properties_by_path_and_revision['source/dir'] = {
            5: {
                'a2': 'y1',
                'b2': 'y2'
            }
        }
        self.repo.files_by_name_and_revision['source/dir/x'] = {5: 'x'}
        self.repo.properties_by_path_and_revision['source/dir/x'] = {5: {}}
        self.config.start_rev = 6
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a/tags/OLD_TAG',
                                                 'add', 'source/dir/', 5)

        self.assertEqual(len(self.writer.lumps), 0)
        self.assertFalse(
            self.interesting_paths.is_interesting('a/tags/OLD_TAG'))

    def test_add_tree_from_source_with_valid_tag_inside(self):
        self.repo.tree_by_path_and_revision['source/dir'] = {
            5: [
                'source/dir/', 'source/dir/tags/', 'source/dir/tags/NEW_TAG/',
                'source/dir/tags/NEW_TAG/x'
            ]
        }
        self.repo.properties_by_path_and_revision['source/dir'] = {5: {}}
        self.repo.tree_by_path_and_revision['source/dir/tags'] = {
            5: [
                'source/dir/tags/', 'source/dir/tags/NEW_TAG/',
                'source/dir/tags/NEW_TAG/x'
            ]
        }
        self.repo.properties_by_path_and_revision['source/dir/tags'] = {5: {}}
        self.repo.tree_by_path_and_revision['source/dir/tags/NEW_TAG'] = {
            5: ['source/dir/tags/NEW_TAG/', 'source/dir/tags/NEW_TAG/x']
        }
        self.repo.properties_by_path_and_revision[
            'source/dir/tags/NEW_TAG'] = {
                5: {}
            }
        self.repo.files_by_name_and_revision['source/dir/tags/NEW_TAG/x'] = {
            5: 'x'
        }
        self.repo.properties_by_path_and_revision[
            'source/dir/tags/NEW_TAG/x'] = {
                5: {}
            }
        self.config.start_rev = 3
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a', 'add',
                                                 'source/dir/', 5)

        self.assertEqual(len(self.writer.lumps), 2)
        self.assertFalse(
            self.interesting_paths.is_interesting('a/tags/NEW_TAG'))

        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a/tags')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(1, None)

    def test_add_tree_from_source_with_obsolete_tag_inside(self):
        self.repo.tree_by_path_and_revision['source/dir'] = {
            5: [
                'source/dir/', 'source/dir/tags/', 'source/dir/tags/OLD_TAG',
                'source/dir/tags/OLD_TAG/x'
            ]
        }
        self.repo.properties_by_path_and_revision['source/dir'] = {5: {}}
        self.repo.tree_by_path_and_revision['source/dir/tags'] = {
            5: [
                'source/dir/tags/', 'source/dir/tags/OLD_TAG/',
                'source/dir/tags/OLD_TAG/x'
            ]
        }
        self.repo.properties_by_path_and_revision['source/dir/tags'] = {5: {}}
        self.repo.tree_by_path_and_revision['source/dir/tags/OLD_TAG'] = {
            5: ['source/dir/tags/OLD_TAG', 'source/dir/tags/OLD_TAG/x']
        }
        self.repo.properties_by_path_and_revision[
            'source/dir/tags/OLD_TAG'] = {
                5: {}
            }
        self.repo.files_by_name_and_revision['source/dir/tags/OLD_TAG/x'] = {
            5: 'x'
        }
        self.repo.properties_by_path_and_revision[
            'source/dir/tags/OLD_TAG/x'] = {
                5: {}
            }
        self.config.start_rev = 7
        self.config.drop_old_tags_and_branches = True
        self.interesting_paths.mark_path_as_interesting('a')

        self.builder.get_recursively_from_source('dir', 'a', 'add',
                                                 'source/dir/', 5)

        self.assertEqual(len(self.writer.lumps), 2)
        self.assertFalse(
            self.interesting_paths.is_interesting('a/tags/OLD_TAG'))

        lump = self.writer.lumps[0]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(0, None)

        lump = self.writer.lumps[1]
        self.assertEqual(lump.get_header_keys(),
                         ['Node-path', 'Node-kind', 'Node-action'])
        self.assertEqual(lump.get_header('Node-path'), 'a/tags')
        self.assertEqual(lump.get_header('Node-kind'), 'dir')
        self.assertEqual(lump.get_header('Node-action'), 'add')
        self.assertEqual(lump.properties, {})
        self.writer.check_content_tin_of_lump_nr(1, None)
Exemplo n.º 16
0
    def test_include_with_exclude(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/c')
        interesting_path.mark_path_as_boring('a/b/c/x')

        self.assertTrue(interesting_path.is_interesting('a/b/c'))
        self.assertTrue(interesting_path.is_interesting('a/b/c/d'))
        self.assertFalse(interesting_path.is_interesting('a/b'))
        self.assertFalse(interesting_path.is_interesting('x/y'))
        self.assertFalse(interesting_path.is_interesting('a/b/c/x'))
        self.assertFalse(interesting_path.is_interesting('a/b/c/x/y'))
Exemplo n.º 17
0
class TestBootsTrapper(TestCase):
    def setUp(self):
        self.config = Config([ '/dummy' ])
        self.interesting_paths = InterestingPaths()
        self.repo = RepositoryMock()
        self.repo.revision_properties_by_revision[3] = [ 'some author', 'some date', 'same log message' ]
        self.builder = LumpBuilderMock()
        self.boots_trapper = BootsTrapper(
            config = self.config,
            source_repository = self.repo,
            interesting_paths = self.interesting_paths,
            lump_builder = self.builder
        )

    def test_empty(self):
        self.boots_trapper.process_revision(3, None)
        self._verfiy_revision_header()

    def test_simple_file(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.tree_by_path_and_revision['a/b'] = { 3: [ 'a/b' ] }
        self.repo.files_by_name_and_revision['a/b'] = { 3: "xxx\n\yyy\n" }

        self.boots_trapper.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1], [ 'get_recursively_from_source', 'file', 'a/b', 'add', 'a/b', 3 ])

    def test_simple_dir(self):
        self.interesting_paths.mark_path_as_interesting('a/b/c')
        self.repo.tree_by_path_and_revision['a/b/c'] = { 3: [ 'a/b/c/', 'a/b/c/x', 'a/b/c/y' ] }
        self.repo.files_by_name_and_revision['a/b/c/x'] = { 3: "xxx" }
        self.repo.files_by_name_and_revision['a/b/c/y'] = { 3: "yyy" }

        self.boots_trapper.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1], [ 'get_recursively_from_source', 'dir', 'a/b/c', 'add', 'a/b/c', 3 ])

    def test_multi_dir(self):
        self.interesting_paths.mark_path_as_interesting('a/a')
        self.interesting_paths.mark_path_as_interesting('a/b/x')
        self.interesting_paths.mark_path_as_interesting('a/b/y')
        self.interesting_paths.mark_path_as_interesting('a/b/z')
        self.repo.tree_by_path_and_revision['a/a'] = { 3: [ 'a/a/', 'a/a/a' ] }
        self.repo.files_by_name_and_revision['a/a/a'] = { 3: "A" }
        self.repo.tree_by_path_and_revision['a/b/x'] = { 3: [ 'a/b/c/', 'a/b/c/x', 'a/b/c/y' ] }
        self.repo.files_by_name_and_revision['a/b/x/x1'] = { 3: "111" }
        self.repo.files_by_name_and_revision['a/b/x/x2'] = { 3: "222" }
        self.repo.files_by_name_and_revision['a/b/y'] = { 3: "yyy" }

        self.boots_trapper.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 4)
        self._verfiy_revision_header()
        self.assertEqual(self.builder.call_history[1], [ 'get_recursively_from_source', 'dir', 'a/a', 'add', 'a/a', 3 ])
        self.assertEqual(self.builder.call_history[2], [ 'get_recursively_from_source', 'dir', 'a/b/x', 'add', 'a/b/x', 3 ])
        self.assertEqual(self.builder.call_history[3], [ 'get_recursively_from_source', 'file', 'a/b/y', 'add', 'a/b/y', 3 ])

    def _verfiy_revision_header(self):
        self.assertEqual(self.builder.call_history[0], [ 'revision_header', 3, 'svnfiltereddump boots trap revision' ])
Exemplo n.º 18
0
    def test_paths_with_trailing_slashes(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/')

        self.assertTrue(interesting_path.is_interesting('a/b'))
        self.assertTrue(interesting_path.is_interesting('a/b/'))
class TestParentDirectoryLumpGenerator(TestCase):
    def setUp(self):
        self.interesting_paths = InterestingPaths()
        self.builder = LumpBuilderMock()
        self.generator = ParentDirectoryLumpGenerator(self.interesting_paths, self.builder)

    def test_empty(self):
        self.generator.write_lumps()
        self.assertEqual(self.builder.call_history, [ ])

    def test_trivial(self):
        self.interesting_paths.mark_path_as_interesting('a')
        self.generator.write_lumps()
        self.assertEqual(self.builder.call_history, [ ])

    def test_all_intersting(self):
        self.interesting_paths.mark_path_as_interesting('')
        self.generator.write_lumps()
        self.assertEqual(self.builder.call_history, [ ])

    def test_simple(self):
        self.interesting_paths.mark_path_as_interesting('a/b')

        self.generator.write_lumps()

        self.assertEqual(self.builder.call_history, [
            [ 'mkdir', 'a' ]
        ])

    def test_complex(self):
        self.interesting_paths.mark_path_as_interesting('a')
        self.interesting_paths.mark_path_as_interesting('b/c')
        self.interesting_paths.mark_path_as_interesting('b/x/y/z1')
        self.interesting_paths.mark_path_as_interesting('b/x/y/z2')
        self.interesting_paths.mark_path_as_interesting('b/x/y/z3')
        self.interesting_paths.mark_path_as_interesting('d/e')

        self.generator.write_lumps()

        self.assertEqual(self.builder.call_history, [
            [ 'mkdir', 'b' ],
            [ 'mkdir', 'd' ],
            [ 'mkdir', 'b/x' ],
            [ 'mkdir', 'b/x/y' ],
        ])
Exemplo n.º 20
0
    def test_paths_with_trailing_slashes(self):
        interesting_path = InterestingPaths()
        interesting_path.mark_path_as_interesting('a/b/')

        self.assertTrue(interesting_path.is_interesting('a/b'))
        self.assertTrue(interesting_path.is_interesting('a/b/'))
Exemplo n.º 21
0
class TestParentDirectoryLumpGenerator(TestCase):
    def setUp(self):
        self.interesting_paths = InterestingPaths()
        self.builder = LumpBuilderMock()
        self.generator = ParentDirectoryLumpGenerator(self.interesting_paths,
                                                      self.builder)

    def test_empty(self):
        self.generator.write_lumps()
        self.assertEqual(self.builder.call_history, [])

    def test_trivial(self):
        self.interesting_paths.mark_path_as_interesting('a')
        self.generator.write_lumps()
        self.assertEqual(self.builder.call_history, [])

    def test_all_intersting(self):
        self.interesting_paths.mark_path_as_interesting('')
        self.generator.write_lumps()
        self.assertEqual(self.builder.call_history, [])

    def test_simple(self):
        self.interesting_paths.mark_path_as_interesting('a/b')

        self.generator.write_lumps()

        self.assertEqual(self.builder.call_history, [['mkdir', 'a']])

    def test_complex(self):
        self.interesting_paths.mark_path_as_interesting('a')
        self.interesting_paths.mark_path_as_interesting('b/c')
        self.interesting_paths.mark_path_as_interesting('b/x/y/z1')
        self.interesting_paths.mark_path_as_interesting('b/x/y/z2')
        self.interesting_paths.mark_path_as_interesting('b/x/y/z3')
        self.interesting_paths.mark_path_as_interesting('d/e')

        self.generator.write_lumps()

        self.assertEqual(self.builder.call_history, [
            ['mkdir', 'b'],
            ['mkdir', 'd'],
            ['mkdir', 'b/x'],
            ['mkdir', 'b/x/y'],
        ])
Exemplo n.º 22
0
 def setUp(self):
     self.interesting_paths = InterestingPaths()
     self.builder = LumpBuilderMock()
     self.generator = ParentDirectoryLumpGenerator(self.interesting_paths,
                                                   self.builder)
 def setUp(self):
     self.interesting_paths = InterestingPaths()
     self.builder = LumpBuilderMock()
     self.generator = ParentDirectoryLumpGenerator(self.interesting_paths, self.builder)
Exemplo n.º 24
0
class TestBootsTrapper(TestCase):
    def setUp(self):
        self.config = Config(['/dummy'])
        self.interesting_paths = InterestingPaths()
        self.repo = RepositoryMock()
        self.repo.revision_properties_by_revision[3] = [
            'some author', 'some date', 'same log message'
        ]
        self.builder = LumpBuilderMock()
        self.boots_trapper = BootsTrapper(
            config=self.config,
            source_repository=self.repo,
            interesting_paths=self.interesting_paths,
            lump_builder=self.builder)

    def test_empty(self):
        self.boots_trapper.process_revision(3, None)
        self._verfiy_revision_header()

    def test_simple_file(self):
        self.interesting_paths.mark_path_as_interesting('a/b')
        self.repo.tree_by_path_and_revision['a/b'] = {3: ['a/b']}
        self.repo.files_by_name_and_revision['a/b'] = {3: "xxx\n\yyy\n"}

        self.boots_trapper.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)
        self._verfiy_revision_header()
        self.assertEqual(
            self.builder.call_history[1],
            ['get_recursively_from_source', 'file', 'a/b', 'add', 'a/b', 3])

    def test_simple_dir(self):
        self.interesting_paths.mark_path_as_interesting('a/b/c')
        self.repo.tree_by_path_and_revision['a/b/c'] = {
            3: ['a/b/c/', 'a/b/c/x', 'a/b/c/y']
        }
        self.repo.files_by_name_and_revision['a/b/c/x'] = {3: "xxx"}
        self.repo.files_by_name_and_revision['a/b/c/y'] = {3: "yyy"}

        self.boots_trapper.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 2)
        self._verfiy_revision_header()
        self.assertEqual(
            self.builder.call_history[1],
            ['get_recursively_from_source', 'dir', 'a/b/c', 'add', 'a/b/c', 3])

    def test_multi_dir(self):
        self.interesting_paths.mark_path_as_interesting('a/a')
        self.interesting_paths.mark_path_as_interesting('a/b/x')
        self.interesting_paths.mark_path_as_interesting('a/b/y')
        self.interesting_paths.mark_path_as_interesting('a/b/z')
        self.repo.tree_by_path_and_revision['a/a'] = {3: ['a/a/', 'a/a/a']}
        self.repo.files_by_name_and_revision['a/a/a'] = {3: "A"}
        self.repo.tree_by_path_and_revision['a/b/x'] = {
            3: ['a/b/c/', 'a/b/c/x', 'a/b/c/y']
        }
        self.repo.files_by_name_and_revision['a/b/x/x1'] = {3: "111"}
        self.repo.files_by_name_and_revision['a/b/x/x2'] = {3: "222"}
        self.repo.files_by_name_and_revision['a/b/y'] = {3: "yyy"}

        self.boots_trapper.process_revision(3, None)

        self.assertEqual(len(self.builder.call_history), 4)
        self._verfiy_revision_header()
        self.assertEqual(
            self.builder.call_history[1],
            ['get_recursively_from_source', 'dir', 'a/a', 'add', 'a/a', 3])
        self.assertEqual(
            self.builder.call_history[2],
            ['get_recursively_from_source', 'dir', 'a/b/x', 'add', 'a/b/x', 3])
        self.assertEqual(self.builder.call_history[3], [
            'get_recursively_from_source', 'file', 'a/b/y', 'add', 'a/b/y', 3
        ])

    def _verfiy_revision_header(self):
        self.assertEqual(
            self.builder.call_history[0],
            ['revision_header', 3, 'svnfiltereddump boots trap revision'])