ForgeSCM: add tests, make pass after _id=>shortname

Andy Verprauskus Andy Verprauskus 2010-02-03

added ForgeSCM/forgescm/tests/test_model.py
changed ForgeSCM/forgescm/controllers/root.py
changed ForgeSCM/forgescm/lib/command.py
changed ForgeSCM/forgescm/lib/git.py
changed ForgeSCM/forgescm/lib/hg.py
changed ForgeSCM/forgescm/lib/svn.py
changed ForgeSCM/forgescm/model/__init__.py
changed ForgeSCM/forgescm/model/artifacts.py
changed ForgeSCM/forgescm/reactors/common_react.py
changed ForgeSCM/forgescm/reactors/git_react.py
changed ForgeSCM/forgescm/templates/index.html
changed ForgeSCM/forgescm/tests/__init__.py
changed ForgeSCM/forgescm/tests/test_command.py
changed ForgeSCM/forgescm/tests/test_controller.py
changed ForgeSCM/forgescm/tests/test_react.py
copied ForgeSCM/forgescm/tests/test_parser.py -> ForgeSCM/forgescm/tests/test_helper.py
ForgeSCM/forgescm/tests/test_model.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/controllers/root.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/lib/command.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/lib/git.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/lib/hg.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/lib/svn.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/model/__init__.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/model/artifacts.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/reactors/common_react.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/reactors/git_react.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/templates/index.html Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/tests/__init__.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/tests/test_command.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/tests/test_controller.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/tests/test_react.py Diff Switch to side-by-side view
Loading...
ForgeSCM/forgescm/tests/test_parser.py to ForgeSCM/forgescm/tests/test_helper.py
--- a/ForgeSCM/forgescm/tests/test_parser.py
+++ b/ForgeSCM/forgescm/tests/test_helper.py
@@ -1,55 +1,74 @@
 import os
-from unittest import TestCase
+import sys
+from forgescm.lib import hg, git
 from pylons import c, g
-import ming
+from tg import config
+from paste.deploy import loadapp
 from pyforge import model as M
+from paste.script.appinstall import SetupCommand
+from webtest import TestApp
+from time import sleep
 from pyforge.lib import app_globals
-from forgescm.lib import hg, git
-from forgescm import model as FM
 
-ming.configure(**{'ming.main.master':'mongo://localhost:27017/pyforge'})
+from forgescm.lib.command import Command
+
+class git_add_all(Command):
+    base='git add .'
+
+class git_commit_all(Command):
+    base='git commit -a -m "foo"'
+
+def create_readme(dir):
+    fn = os.path.join(dir, 'README')
+    with open(fn, 'w') as fp:
+        fp.write("Nothing to read, really\n")
+    return fn
 
 class EmptyClass(object): pass
 
-class TestHgLogParser(TestCase):
+def test_setup_app():
+    """Method called by nose before running each test"""
+    # Loading the application:
+    conf_dir = config.here = os.path.abspath(
+        os.path.dirname(__file__) + '/../..')
+    wsgiapp = loadapp('config:test.ini#main', relative_to=conf_dir)
+    app = TestApp(wsgiapp)
 
-    def setUp(self):
-        path = os.path.join(
-            os.path.dirname(__file__),
-            'hg.log')
-        self.fp = open(path)
-        g._push_object(app_globals.Globals())
-        c._push_object(EmptyClass())
-        c.project = M.Project.query.get(_id='projects/test/')
-        c.app = c.project.app_instance('src')
-        FM.Commit.query.remove(dict(app_conf_id=c.app.config._id))
-        FM.Patch.query.remove(dict(app_conf_id=c.app.config._id))
+    # Setting it up:
+    test_file = os.path.join(conf_dir, 'test.ini')
+    cmd = SetupCommand('setup-app')
+    cmd.run([test_file])
+    hg_repo_url = config.here + '/forgescm/tests/hg_repo'
+    if not os.path.exists(hg_repo_url):
+        system('hg init %s' % hg_repo_url)
+    return app
 
-    def test_parse_hg(self):
-        parser = hg.LogParser(c.app.repo._id)
-        commits = parser.feed(self.fp)
-        for ct in commits:
-            pass
+def ensure_c_project_and_app():
+    g._push_object(app_globals.Globals())
+    c._push_object(EmptyClass())
+    get_project = lambda: M.Project.query.get(shortname='test')
+    while get_project() is None:
+      sleep(0.1)
+    c.project = get_project()
+    c.app = c.project.app_instance('src')
 
-class TestGitLogParser(TestCase):
-            
-    def setUp(self):
-        path = os.path.join(
-            os.path.dirname(__file__),
-            'git.log')
-        self.fp = open(path)
-        g._push_object(app_globals.Globals())
-        c._push_object(EmptyClass())
-        c.project = M.Project.query.get(_id='projects/test/')
-        c.app = c.project.app_instance('src_git')
-        FM.Commit.query.remove(dict(app_conf_id=c.app.config._id))
-        FM.Patch.query.remove(dict(app_conf_id=c.app.config._id))
+def create_git_repo():
+    save_dir = os.getcwd()
+    os.chdir("/tmp")
+    cmd = git.init()
+    cmd.clean_dir()
+    cmd.run()
+    create_readme(c.app.repo.repo_dir)
+    git_add_all().run()
+    git_commit_all().run()
+    log = git.scm_log()
+    log.run()
+    os.chdir(save_dir)
+    return log
 
-    def test_parse_git(self):
-        parser = git.LogParser(c.app.repo._id)
-        commits = parser.feed(self.fp)
-        for ct in commits:
-            pass
-        
-            
+def clone_git_repo(repo):
+    repo.type = "git"
+    # following is copied from  reactors/git_react.py,
+    # should be factored out
+    repo.clear_commits()