class SvnCachedRepositoryTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() DbRepositoryProvider(self.env).add_repository(REPOS_NAME, self.path, 'svn') self.repos = self.env.get_repository(REPOS_NAME) self.repos.sync() def tearDown(self): self.env.reset_db() self.repos.close() self.repos = None
class SubversionRepositoryTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() repositories = self.env.config['repositories'] DbRepositoryProvider(self.env).add_repository(REPOS_NAME, self.path, 'direct-svnfs') self.repos = self.env.get_repository(REPOS_NAME) def tearDown(self): self.env.reset_db() # needed to avoid issue with 'WindowsError: The process cannot access # the file ... being used by another process: ...\rep-cache.db' self.env.shutdown(get_thread_id())
class SvnCachedRepositoryTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() dbprovider = DbRepositoryProvider(self.env) dbprovider.add_repository(REPOS_NAME, self.path, 'svn') dbprovider.modify_repository(REPOS_NAME, {'url': URL}) self.repos = self.env.get_repository(REPOS_NAME) self.repos.sync() def tearDown(self): self.env.reset_db() self.repos.close() self.repos = None # clear cached repositories to avoid TypeError on termination (#11505) RepositoryManager(self.env).reload_repositories()
class SubversionRepositoryTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() repositories = self.env.config['repositories'] dbprovider = DbRepositoryProvider(self.env) dbprovider.add_repository(REPOS_NAME, self.path, 'direct-svnfs') dbprovider.modify_repository(REPOS_NAME, {'url': URL}) self.repos = self.env.get_repository(REPOS_NAME) def tearDown(self): self.repos.close() self.repos = None # clear cached repositories to avoid TypeError on termination (#11505) RepositoryManager(self.env).reload_repositories() self.env.reset_db() # needed to avoid issue with 'WindowsError: The process cannot access # the file ... being used by another process: ...\rep-cache.db' self.env.shutdown(get_thread_id())
class CollectChangesTestCase(unittest.TestCase): """ Unit tests for the `bitten.queue.collect_changes` function. """ def setUp(self): self.env = EnvironmentStub() self.env.path = tempfile.mkdtemp() db = self.env.get_db_cnx() cursor = db.cursor() connector, _ = DatabaseManager(self.env)._get_connector() for table in schema: for stmt in connector.to_sql(table): cursor.execute(stmt) self.config = BuildConfig(self.env, name='test', path='somepath') self.config.insert(db=db) self.platform = TargetPlatform(self.env, config='test', name='Foo') self.platform.insert(db=db) db.commit() def tearDown(self): shutil.rmtree(self.env.path) def test_stop_on_copy(self): self.env.get_repository = lambda authname=None: Mock( get_node=lambda path, rev=None: Mock( get_history=lambda: [('otherpath', 123, 'copy')] ), normalize_path=lambda path: path ) retval = list(collect_changes(self.env.get_repository(), self.config)) self.assertEqual(0, len(retval)) def test_stop_on_minrev(self): self.env.get_repository = lambda authname=None: Mock( get_node=lambda path, rev=None: Mock( get_entries=lambda: [Mock(), Mock()], get_history=lambda: [('somepath', 123, 'edit'), ('somepath', 121, 'edit'), ('somepath', 120, 'edit')] ), normalize_path=lambda path: path, rev_older_than=lambda rev1, rev2: rev1 < rev2 ) self.config.min_rev = 123 self.config.update() retval = list(collect_changes(self.env.get_repository(), self.config)) self.assertEqual(1, len(retval)) self.assertEqual(123, retval[0][1]) def test_skip_until_maxrev(self): self.env.get_repository = lambda authname=None: Mock( get_node=lambda path, rev=None: Mock( get_entries=lambda: [Mock(), Mock()], get_history=lambda: [('somepath', 123, 'edit'), ('somepath', 121, 'edit'), ('somepath', 120, 'edit')] ), normalize_path=lambda path: path, rev_older_than=lambda rev1, rev2: rev1 < rev2 ) self.config.max_rev=121 self.config.update() retval = list(collect_changes(self.env.get_repository(), self.config)) self.assertEqual(2, len(retval)) self.assertEqual(121, retval[0][1]) self.assertEqual(120, retval[1][1]) def test_skip_empty_dir(self): def _mock_get_node(path, rev=None): if rev and rev == 121: return Mock( get_entries=lambda: [] ) else: return Mock( get_entries=lambda: [Mock(), Mock()], get_history=lambda: [('somepath', 123, 'edit'), ('somepath', 121, 'edit'), ('somepath', 120, 'edit')] ) self.env.get_repository = lambda authname=None: Mock( get_node=_mock_get_node, normalize_path=lambda path: path, rev_older_than=lambda rev1, rev2: rev1 < rev2 ) retval = list(collect_changes(self.env.get_repository(), self.config)) self.assertEqual(2, len(retval)) self.assertEqual(123, retval[0][1]) self.assertEqual(120, retval[1][1])
class ChangesetsSvnTestCase(unittest.TestCase): @classmethod def setupClass(cls): svn_fs._import_svn() core.apr_initialize() pool = core.svn_pool_create(None) dumpstream = None cls.repos_path = tempfile.mkdtemp(prefix='svn-tmp') shutil.rmtree(cls.repos_path) dumpfile = open(os.path.join(os.path.split(__file__)[0], 'svn.dump')) try: r = repos.svn_repos_create(cls.repos_path, '', '', None, None, pool) if hasattr(repos, 'svn_repos_load_fs2'): repos.svn_repos_load_fs2(r, dumpfile, StringIO(), repos.svn_repos_load_uuid_default, '', 0, 0, None, pool) else: dumpstream = core.svn_stream_from_aprfile(dumpfile, pool) repos.svn_repos_load_fs(r, dumpstream, None, repos.svn_repos_load_uuid_default, '', None, None, pool) finally: if dumpstream: core.svn_stream_close(dumpstream) core.svn_pool_destroy(pool) core.apr_terminate() @classmethod def teardownClass(cls): if os.name == 'nt': # The Windows version of 'shutil.rmtree' doesn't override the # permissions of read-only files, so we have to do it ourselves: import stat format_file = os.path.join(cls.repos_path, 'db', 'format') if os.path.isfile(format_file): os.chmod(format_file, stat.S_IRWXU) os.chmod(os.path.join(cls.repos_path, 'format'), stat.S_IRWXU) shutil.rmtree(cls.repos_path) def setUp(self): self.env = EnvironmentStub(enable=['trac.*', FullTextSearch]) DbRepositoryProvider(self.env).add_repository('', self.repos_path, 'svn') self.repos = self.env.get_repository('') self.repos.sync() self.fts = FullTextSearch(self.env) self.fts.backend = Backend(self.fts.solr_endpoint, self.env.log, MockSolrInterface) def tearDown(self): self.env.reset_db() self.repos.close() self.repos = None def _get_so(self, i=-1): si = self.fts.backend.si_class(self.fts.backend.solr_endpoint) return si.hist[i][2] def _feedback(self, realm, resource): pass def _finish_fb(self, realm, resource): pass def test_reindex_changeset(self): self.assertEquals({'changeset': self.repos.youngest_rev}, self.fts.index(['changeset'], True, self._feedback, self._finish_fb)) def test_add_changeset(self): sw = SubversionWriter(self.env, self.repos, 'kalle') new_rev = sw.put_content('/trunk/foo.txt', content='Foo Bar', commit_msg='A comment') RepositoryManager(self.env).notify('changeset_added', '', [new_rev]) # Node so = self._get_so() self.assertEquals('trac:source:trunk/foo.txt', so.doc_id) self.assertEquals('source', so.realm) self.assertEquals('trunk/foo.txt', so.id) self.assertEquals('trunk/foo.txt', so.title) self.assertEquals('kalle', so.author) self.assertEquals('Foo Bar', so.body.read()) self.assertTrue('A comment' in so.comments) # Changeset so = self._get_so(-2) self.assertEquals('trac:changeset:%i' % new_rev, so.doc_id) self.assertEquals('changeset', so.realm) self.assertEquals('%i' % new_rev, so.id) self.assertTrue(so.title.startswith('[%i]: A comment' % new_rev)) self.assertEquals('kalle', so.author) self.assertEquals('A comment', so.body)
class NormalTestCase(unittest.TestCase, GitCommandMixin): def setUp(self): self.env = EnvironmentStub() self.repos_path = tempfile.mkdtemp(prefix='trac-gitrepos-') # create git repository and master branch self._git('init') self._git('config', 'core.quotepath', 'true') # ticket:11198 self._git('config', 'user.name', "Joe") self._git('config', 'user.email', "*****@*****.**") create_file(os.path.join(self.repos_path, '.gitignore')) self._git('add', '.gitignore') self._git_commit('-a', '-m', 'test', date=datetime(2013, 1, 1, 9, 4, 56)) def tearDown(self): RepositoryManager(self.env).reload_repositories() StorageFactory._clean() self.env.reset_db() if os.path.isdir(self.repos_path): rmtree(self.repos_path) def _factory(self, weak, path=None): if path is None: path = os.path.join(self.repos_path, '.git') return StorageFactory(path, self.env.log, weak) def _storage(self, path=None): if path is None: path = os.path.join(self.repos_path, '.git') return Storage(path, self.env.log, self.git_bin, 'utf-8') def test_control_files_detection(self): # Exception not raised when path points to ctrl file dir self.assertIsInstance(self._storage().repo, GitCore) # Exception not raised when path points to parent of ctrl files dir self.assertIsInstance(self._storage(self.repos_path).repo, GitCore) # Exception raised when path points to dir with no ctrl files path = tempfile.mkdtemp(dir=self.repos_path) self.assertRaises(GitError, self._storage, path) # Exception raised if a ctrl file is missing os.remove(os.path.join(self.repos_path, '.git', 'HEAD')) self.assertRaises(GitError, self._storage, self.repos_path) def test_get_branches_with_cr_in_commitlog(self): # regression test for #11598 message = 'message with carriage return'.replace(' ', '\r') create_file(os.path.join(self.repos_path, 'ticket11598.txt')) self._git('add', 'ticket11598.txt') self._git_commit('-m', message, date=datetime(2013, 5, 9, 11, 5, 21)) storage = self._storage() branches = sorted(storage.get_branches()) self.assertEqual('master', branches[0][0]) self.assertEqual(1, len(branches)) if os.name == 'nt': del test_get_branches_with_cr_in_commitlog def test_rev_is_anchestor_of(self): # regression test for #11215 path = os.path.join(self.repos_path, '.git') DbRepositoryProvider(self.env).add_repository('gitrepos', path, 'git') repos = self.env.get_repository('gitrepos') parent_rev = repos.youngest_rev create_file(os.path.join(self.repos_path, 'ticket11215.txt')) self._git('add', 'ticket11215.txt') self._git_commit('-m', 'ticket11215', date=datetime(2013, 6, 27, 18, 26, 2)) repos.sync() rev = repos.youngest_rev self.assertNotEqual(rev, parent_rev) self.assertFalse(repos.rev_older_than(None, None)) self.assertFalse(repos.rev_older_than(None, rev[:7])) self.assertFalse(repos.rev_older_than(rev[:7], None)) self.assertTrue(repos.rev_older_than(parent_rev, rev)) self.assertTrue(repos.rev_older_than(parent_rev[:7], rev[:7])) self.assertFalse(repos.rev_older_than(rev, parent_rev)) self.assertFalse(repos.rev_older_than(rev[:7], parent_rev[:7])) def test_node_get_history_with_empty_commit(self): # regression test for #11328 path = os.path.join(self.repos_path, '.git') DbRepositoryProvider(self.env).add_repository('gitrepos', path, 'git') repos = self.env.get_repository('gitrepos') parent_rev = repos.youngest_rev self._git_commit('-m', 'ticket:11328', '--allow-empty', date=datetime(2013, 10, 15, 9, 46, 27)) repos.sync() rev = repos.youngest_rev node = repos.get_node('', rev) self.assertEqual(rev, repos.git.last_change(rev, '')) history = list(node.get_history()) self.assertEqual(u'', history[0][0]) self.assertEqual(rev, history[0][1]) self.assertEqual(Changeset.EDIT, history[0][2]) self.assertEqual(u'', history[1][0]) self.assertEqual(parent_rev, history[1][1]) self.assertEqual(Changeset.ADD, history[1][2]) self.assertEqual(2, len(history)) def test_sync_after_removing_branch(self): self._git('checkout', '-b', 'b1', 'master') self._git('checkout', 'master') create_file(os.path.join(self.repos_path, 'newfile.txt')) self._git('add', 'newfile.txt') self._git_commit('-m', 'added newfile.txt to master', date=datetime(2013, 12, 23, 6, 52, 23)) storage = self._storage() storage.sync() self.assertEqual(['b1', 'master'], sorted(b[0] for b in storage.get_branches())) self._git('branch', '-D', 'b1') self.assertEqual(True, storage.sync()) self.assertEqual(['master'], sorted(b[0] for b in storage.get_branches())) self.assertEqual(False, storage.sync()) def test_turn_off_persistent_cache(self): # persistent_cache is enabled parent_rev = self._factory(False).getInstance().youngest_rev() create_file(os.path.join(self.repos_path, 'newfile.txt')) self._git('add', 'newfile.txt') self._git_commit('-m', 'test_turn_off_persistent_cache', date=datetime(2014, 1, 29, 13, 13, 25)) # persistent_cache is disabled rev = self._factory(True).getInstance().youngest_rev() self.assertNotEqual(rev, parent_rev)
class NormalTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() self.repos_path = tempfile.mkdtemp(prefix='trac-gitrepos-') self.git_bin = locate('git') # create git repository and master branch self._git('init', self.repos_path) self._git('config', 'core.quotepath', 'true') # ticket:11198 self._git('config', 'user.name', "Joe") self._git('config', 'user.email', "*****@*****.**") create_file(os.path.join(self.repos_path, '.gitignore')) self._git('add', '.gitignore') self._git('commit', '-a', '-m', 'test', '--date', 'Tue Jan 1 18:04:56 2013 +0900') def tearDown(self): RepositoryManager(self.env).reload_repositories() StorageFactory._clean() self.env.reset_db() if os.path.isdir(self.repos_path): rmtree(self.repos_path) def _git(self, *args): args = [self.git_bin] + list(args) proc = Popen(args, stdout=PIPE, stderr=PIPE, close_fds=close_fds, cwd=self.repos_path) stdout, stderr = proc.communicate() self.assertEqual( 0, proc.returncode, 'git exits with %r, stdout %r, stderr %r' % (proc.returncode, stdout, stderr)) return proc def _factory(self, weak, path=None): if path is None: path = os.path.join(self.repos_path, '.git') return StorageFactory(path, self.env.log, weak) def _storage(self, path=None): if path is None: path = os.path.join(self.repos_path, '.git') return Storage(path, self.env.log, self.git_bin, 'utf-8') def test_control_files_detection(self): # Exception not raised when path points to ctrl file dir self.assertIsInstance(self._storage().repo, GitCore) # Exception not raised when path points to parent of ctrl files dir self.assertIsInstance(self._storage(self.repos_path).repo, GitCore) # Exception raised when path points to dir with no ctrl files path = tempfile.mkdtemp(dir=self.repos_path) self.assertRaises(GitError, self._storage, path) # Exception raised if a ctrl file is missing os.remove(os.path.join(self.repos_path, '.git', 'HEAD')) self.assertRaises(GitError, self._storage, self.repos_path) def test_get_branches_with_cr_in_commitlog(self): # regression test for #11598 message = 'message with carriage return'.replace(' ', '\r') create_file(os.path.join(self.repos_path, 'ticket11598.txt')) self._git('add', 'ticket11598.txt') self._git('commit', '-m', message, '--date', 'Thu May 9 20:05:21 2013 +0900') storage = self._storage() branches = sorted(storage.get_branches()) self.assertEqual('master', branches[0][0]) self.assertEqual(1, len(branches)) if os.name == 'nt': del test_get_branches_with_cr_in_commitlog def test_rev_is_anchestor_of(self): # regression test for #11215 path = os.path.join(self.repos_path, '.git') DbRepositoryProvider(self.env).add_repository('gitrepos', path, 'git') repos = self.env.get_repository('gitrepos') parent_rev = repos.youngest_rev create_file(os.path.join(self.repos_path, 'ticket11215.txt')) self._git('add', 'ticket11215.txt') self._git('commit', '-m', 'ticket11215', '--date', 'Fri Jun 28 03:26:02 2013 +0900') repos.sync() rev = repos.youngest_rev self.assertNotEqual(rev, parent_rev) self.assertFalse(repos.rev_older_than(None, None)) self.assertFalse(repos.rev_older_than(None, rev[:7])) self.assertFalse(repos.rev_older_than(rev[:7], None)) self.assertTrue(repos.rev_older_than(parent_rev, rev)) self.assertTrue(repos.rev_older_than(parent_rev[:7], rev[:7])) self.assertFalse(repos.rev_older_than(rev, parent_rev)) self.assertFalse(repos.rev_older_than(rev[:7], parent_rev[:7])) def test_node_get_history_with_empty_commit(self): # regression test for #11328 path = os.path.join(self.repos_path, '.git') DbRepositoryProvider(self.env).add_repository('gitrepos', path, 'git') repos = self.env.get_repository('gitrepos') parent_rev = repos.youngest_rev self._git('commit', '-m', 'ticket:11328', '--allow-empty', '--date', 'Tue Oct 15 18:46:27 2013 +0900') repos.sync() rev = repos.youngest_rev node = repos.get_node('', rev) self.assertEqual(rev, repos.git.last_change(rev, '')) history = list(node.get_history()) self.assertEqual(u'', history[0][0]) self.assertEqual(rev, history[0][1]) self.assertEqual(Changeset.EDIT, history[0][2]) self.assertEqual(u'', history[1][0]) self.assertEqual(parent_rev, history[1][1]) self.assertEqual(Changeset.ADD, history[1][2]) self.assertEqual(2, len(history)) def test_sync_after_removing_branch(self): self._git('checkout', '-b', 'b1', 'master') self._git('checkout', 'master') create_file(os.path.join(self.repos_path, 'newfile.txt')) self._git('add', 'newfile.txt') self._git('commit', '-m', 'added newfile.txt to master', '--date', 'Mon Dec 23 15:52:23 2013 +0900') storage = self._storage() storage.sync() self.assertEqual(['b1', 'master'], sorted(b[0] for b in storage.get_branches())) self._git('branch', '-D', 'b1') self.assertEqual(True, storage.sync()) self.assertEqual(['master'], sorted(b[0] for b in storage.get_branches())) self.assertEqual(False, storage.sync()) def test_turn_off_persistent_cache(self): # persistent_cache is enabled parent_rev = self._factory(False).getInstance().youngest_rev() create_file(os.path.join(self.repos_path, 'newfile.txt')) self._git('add', 'newfile.txt') self._git('commit', '-m', 'test_turn_off_persistent_cache', '--date', 'Wed, 29 Jan 2014 22:13:25 +0900') # persistent_cache is disabled rev = self._factory(True).getInstance().youngest_rev() self.assertNotEqual(rev, parent_rev)
class NormalTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() self.repos_path = tempfile.mkdtemp(prefix='trac-gitrepos-') self.git_bin = locate('git') # create git repository and master branch self._git('init', self.repos_path) self._git('config', 'core.quotepath', 'true') # ticket:11198 self._git('config', 'user.name', "Joe") self._git('config', 'user.email', "*****@*****.**") create_file(os.path.join(self.repos_path, '.gitignore')) self._git('add', '.gitignore') self._git('commit', '-a', '-m', 'test') def tearDown(self): self.env.reset_db() if os.path.isdir(self.repos_path): rmtree(self.repos_path) def _git(self, *args): args = [self.git_bin] + list(args) proc = Popen(args, stdout=PIPE, stderr=PIPE, close_fds=close_fds, cwd=self.repos_path) proc.wait() assert proc.returncode == 0, proc.stderr.read() return proc def _storage(self): path = os.path.join(self.repos_path, '.git') return Storage(path, self.env.log, self.git_bin, 'utf-8') def test_get_branches_with_cr_in_commitlog(self): # regression test for #11598 message = 'message with carriage return'.replace(' ', '\r') create_file(os.path.join(self.repos_path, 'ticket11598.txt')) self._git('add', 'ticket11598.txt') self._git('commit', '-m', message, '--date', 'Thu May 9 20:05:21 2013 +0900') storage = self._storage() branches = sorted(storage.get_branches()) self.assertEquals('master', branches[0][0]) self.assertEquals(1, len(branches)) def test_rev_is_anchestor_of(self): # regression test for #11215 path = os.path.join(self.repos_path, '.git') DbRepositoryProvider(self.env).add_repository('gitrepos', path, 'git') repos = self.env.get_repository('gitrepos') parent_rev = repos.youngest_rev create_file(os.path.join(self.repos_path, 'ticket11215.txt')) self._git('add', 'ticket11215.txt') self._git('commit', '-m', 'ticket11215', '--date', 'Fri Jun 28 03:26:02 2013 +0900') repos.sync() rev = repos.youngest_rev self.assertNotEqual(rev, parent_rev) self.assertEquals(False, repos.rev_older_than(None, None)) self.assertEquals(False, repos.rev_older_than(None, rev[:7])) self.assertEquals(False, repos.rev_older_than(rev[:7], None)) self.assertEquals(True, repos.rev_older_than(parent_rev, rev)) self.assertEquals(True, repos.rev_older_than(parent_rev[:7], rev[:7])) self.assertEquals(False, repos.rev_older_than(rev, parent_rev)) self.assertEquals(False, repos.rev_older_than(rev[:7], parent_rev[:7]))
class NormalTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() self.repos_path = tempfile.mkdtemp(prefix='trac-gitrepos') self.git_bin = locate('git') # create git repository and master branch self._git('init', self.repos_path) self._git('config', 'core.quotepath', 'true') # ticket:11198 self._git('config', 'user.name', "Joe") self._git('config', 'user.email', "*****@*****.**") create_file(os.path.join(self.repos_path, '.gitignore')) self._git('add', '.gitignore') self._git('commit', '-a', '-m', 'test') def tearDown(self): self.env.reset_db() if os.path.isdir(self.repos_path): rmtree(self.repos_path) def _git(self, *args): args = [self.git_bin] + list(args) proc = Popen(args, stdout=PIPE, stderr=PIPE, close_fds=close_fds, cwd=self.repos_path) proc.wait() assert proc.returncode == 0, proc.stderr.read() return proc def _storage(self): path = os.path.join(self.repos_path, '.git') return Storage(path, self.env.log, self.git_bin, 'utf-8') def test_get_branches_with_cr_in_commitlog(self): # regression test for #11598 message = 'message with carriage return'.replace(' ', '\r') create_file(os.path.join(self.repos_path, 'ticket11598.txt')) self._git('add', 'ticket11598.txt') self._git('commit', '-m', message, '--date', 'Thu May 9 20:05:21 2013 +0900') storage = self._storage() branches = sorted(storage.get_branches()) self.assertEquals('master', branches[0][0]) self.assertEquals(1, len(branches)) def test_rev_is_anchestor_of(self): # regression test for #11215 path = os.path.join(self.repos_path, '.git') DbRepositoryProvider(self.env).add_repository('gitrepos', path, 'git') repos = self.env.get_repository('gitrepos') parent_rev = repos.youngest_rev create_file(os.path.join(self.repos_path, 'ticket11215.txt')) self._git('add', 'ticket11215.txt') self._git('commit', '-m', 'ticket11215', '--date', 'Fri Jun 28 03:26:02 2013 +0900') repos.sync() rev = repos.youngest_rev self.assertNotEqual(rev, parent_rev) self.assertEquals(False, repos.rev_older_than(None, None)) self.assertEquals(False, repos.rev_older_than(None, rev[:7])) self.assertEquals(False, repos.rev_older_than(rev[:7], None)) self.assertEquals(True, repos.rev_older_than(parent_rev, rev)) self.assertEquals(True, repos.rev_older_than(parent_rev[:7], rev[:7])) self.assertEquals(False, repos.rev_older_than(rev, parent_rev)) self.assertEquals(False, repos.rev_older_than(rev[:7], parent_rev[:7]))