--- 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()