allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [39/45] allura git commit: [#7837] ticket:738 Fix repo initialization in tests
Date Wed, 01 Apr 2015 21:10:56 GMT
[#7837] ticket:738 Fix repo initialization in tests

The problem with previous configuration is in the following:

1. `with_tool` installs app, which creates Repository model
2. test setup in most places creates *another* Repository model in a context of
   app installed by `with_tool`. This makes two Repositories linked to one app.
3. `app.repo` returns first Repository from the DB for app, which can be any of
   those two, depending on test run

That's why some tests, that depend on `app.repo` have failed occasionally (e.g.
`test_webhook_payload` for both git and svn)

Fixed all the tests I found to avoid this problems in the future. It took me
awhile to figure out what's wrong.


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/02879be3
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/02879be3
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/02879be3

Branch: refs/heads/hss/7072
Commit: 02879be348331df7a01bb3f4d0f680c8ce1b8735
Parents: b361bdf
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Mar 4 16:31:03 2015 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Mar 30 19:20:42 2015 +0000

----------------------------------------------------------------------
 .../forgegit/tests/model/test_repository.py     | 46 ++++---------
 .../forgesvn/tests/model/test_repository.py     | 68 ++++++++------------
 2 files changed, 41 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/02879be3/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 84dd40d..3ffb2a2 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -62,12 +62,6 @@ class TestNewGit(unittest.TestCase):
         c.app.repo.fs_path = repo_dir
         c.app.repo.name = 'testgit.git'
         self.repo = c.app.repo
-        # self.repo = GM.Repository(
-        #     name='testgit.git',
-        #     fs_path=repo_dir,
-        #     url_path = '/test/',
-        #     tool = 'git',
-        #     status = 'creating')
         self.repo.refresh()
         self.rev = self.repo.commit('master')
         ThreadLocalORMSession.flush_all()
@@ -141,12 +135,9 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         h.set_context('test', 'src-git', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgegit', 'tests/data')
-        self.repo = GM.Repository(
-            name='testgit.git',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='git',
-            status='creating')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.name = 'testgit.git'
+        self.repo = c.app.repo
         self.repo.refresh()
         ThreadLocalORMSession.flush_all()
         ThreadLocalORMSession.close_all()
@@ -526,10 +517,10 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
     def test_clone_url(self):
         assert_equal(
             self.repo.clone_url('rw', 'nobody'),
-            'ssh://nobody@localhost:8022/scm-repo/test/testgit')
+            'ssh://nobody@localhost:8022/scm-repo/p/test/testgit')
         assert_equal(
             self.repo.clone_url('https', 'nobody'),
-            'https://nobody@localhost:8022/scm-repo/test/testgit')
+            'https://nobody@localhost:8022/scm-repo/p/test/testgit')
         with h.push_config(self.repo.app.config.options, external_checkout_url='https://$username@foo.com/'):
             assert_equal(
                 self.repo.clone_url('https', 'user'),
@@ -760,12 +751,9 @@ class TestGitCommit(unittest.TestCase):
         h.set_context('test', 'src-git', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgegit', 'tests/data')
-        self.repo = GM.Repository(
-            name='testgit.git',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='git',
-            status='creating')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.name = 'testgit.git'
+        self.repo = c.app.repo
         self.repo.refresh()
         self.rev = self.repo.commit('HEAD')
         ThreadLocalORMSession.flush_all()
@@ -839,12 +827,9 @@ class TestGitHtmlView(unittest.TestCase):
         h.set_context('test', 'src-git', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgegit', 'tests/data')
-        self.repo = GM.Repository(
-            name='testmime.git',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='git',
-            status='creating')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.name = 'testmime.git'
+        self.repo = c.app.repo
         self.repo.refresh()
         self.rev = self.repo.commit('HEAD')
         ThreadLocalORMSession.flush_all()
@@ -873,12 +858,9 @@ class TestGitRename(unittest.TestCase):
         h.set_context('test', 'src-git', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgegit', 'tests/data')
-        self.repo = GM.Repository(
-            name='testrename.git',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='git',
-            status='creating')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.name = 'testrename.git'
+        self.repo = c.app.repo
         self.repo.refresh()
         self.rev = self.repo.commit('HEAD')
         ThreadLocalORMSession.flush_all()

http://git-wip-us.apache.org/repos/asf/allura/blob/02879be3/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index c3a392a..8fa8314 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -61,12 +61,9 @@ class TestNewRepo(unittest.TestCase):
         h.set_context('test', 'src', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgesvn', 'tests/data/')
-        self.repo = SM.Repository(
-            name='testsvn',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='svn',
-            status='creating')
+        c.app.repo.name = 'testsvn'
+        c.app.repo.fs_path = repo_dir
+        self.repo = c.app.repo
         self.repo.refresh()
         self.rev = self.repo.commit('HEAD')
         ThreadLocalORMSession.flush_all()
@@ -118,25 +115,23 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
     @with_tool('test', 'SVN', 'svn-tags', 'SVN with tags')
     def setup_with_tools(self):
         setup_global_objects()
-        h.set_context('test', 'src', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgesvn', 'tests/data/')
-        self.repo = SM.Repository(
-            name='testsvn',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='svn',
-            status='creating')
-        self.repo.refresh()
-        self.svn_tags = SM.Repository(
-            name='testsvn-trunk-tags-branches',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='svn',
-            status='creating')
-        self.svn_tags.refresh()
-        ThreadLocalORMSession.flush_all()
-        ThreadLocalORMSession.close_all()
+        with h.push_context('test', 'src', neighborhood='Projects'):
+            c.app.repo.name = 'testsvn'
+            c.app.repo.fs_path = repo_dir
+            self.repo = c.app.repo
+            self.repo.refresh()
+            ThreadLocalORMSession.flush_all()
+            ThreadLocalORMSession.close_all()
+        with h.push_context('test', 'svn-tags', neighborhood='Projects'):
+            c.app.repo.name = 'testsvn-trunk-tags-branches'
+            c.app.repo.fs_path = repo_dir
+            self.svn_tags = c.app.repo
+            self.svn_tags.refresh()
+            ThreadLocalORMSession.flush_all()
+            ThreadLocalORMSession.close_all()
+        h.set_context('test', 'src', neighborhood='Projects')
 
     def test_init(self):
         repo = SM.Repository(
@@ -640,12 +635,9 @@ class TestSVNRev(unittest.TestCase):
         h.set_context('test', 'src', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgesvn', 'tests/data/')
-        self.repo = SM.Repository(
-            name='testsvn',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='svn',
-            status='creating')
+        c.app.repo.name = 'testsvn'
+        c.app.repo.fs_path = repo_dir
+        self.repo = c.app.repo
         self.repo.refresh()
         self.rev = self.repo.commit(1)
         ThreadLocalORMSession.flush_all()
@@ -1145,12 +1137,9 @@ class TestRename(unittest.TestCase):
         h.set_context('test', 'src', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgesvn', 'tests/data/')
-        self.repo = SM.Repository(
-            name='testsvn-rename',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='svn',
-            status='creating')
+        c.app.repo.name = 'testsvn-rename'
+        c.app.repo.fs_path = repo_dir
+        self.repo = c.app.repo
         self.repo.refresh()
         self.rev = self.repo.commit('HEAD')
         ThreadLocalORMSession.flush_all()
@@ -1185,12 +1174,9 @@ class TestDirectRepoAccess(object):
         h.set_context('test', 'src', neighborhood='Projects')
         repo_dir = pkg_resources.resource_filename(
             'forgesvn', 'tests/data/')
-        self.repo = SM.Repository(
-            name='testsvn',
-            fs_path=repo_dir,
-            url_path='/test/',
-            tool='svn',
-            status='creating')
+        c.app.repo.name = 'testsvn'
+        c.app.repo.fs_path = repo_dir
+        self.repo = c.app.repo
         self.repo.refresh()
         self.rev = self.repo.commit('HEAD')
         ThreadLocalORMSession.flush_all()


Mime
View raw message