Parent: [a404b5] (diff)

Child: [e589f3] (diff)

Download this file

test_model.py    181 lines (151 with data), 6.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
from unittest import TestCase
from pylons import c, g
import ming
from pyforge import model as M
from pyforge.lib import app_globals
from forgescm.lib import hg, git
import sys
from forgescm import model as FM
from forgescm.tests import TestController
from nose.tools import assert_true
from forgescm.tests import test_helper
from pyforge.lib.helpers import push_config, set_context, encode_keys
from nose.tools import assert_equal
ming.configure(**{'ming.main.master':'mongo://localhost:27017/pyforge'})
class EmptyClass(object): pass
class TestRepository(TestCase):
new_fork_mount_point = "new_fork"
def setUp(self):
test_helper.test_setup_app()
test_helper.ensure_c_project_and_app()
def test_git_do_fork(self):
# setup a git repo with code
repo = c.app.repo
clone_url = test_helper.setup_simple_git_repo(repo)
assert repo.type == "git"
# fork it
# need: src_project, src_url, src_app
clone_url = repo.clone_url()
p = c.app.project
# need a user to fork
c.user = M.User.query.get(username='test_admin')
app = p.install_app('Repository',
"test_git_fork",
type="git")
with push_config(c, project=p, app=app):
repo = app.repo
repo.type = app.repo.type
repo.status = 'pending fork'
new_url = repo.url()
c.app.repo.do_fork(dict(
url=clone_url,
forked_to=dict(project_id=str(p._id),
app_config_id=str(app.config._id)),
forked_from=dict(project_id=str(c.project._id),
app_config_id=str(c.app.config._id))))
# verify fork
assert app.repo.repo_dir
assert app.repo.scmlib() == git
assert "commit" in app.repo.scmlib().scm_log().run().output
def test_hg_do_fork(self):
repo = c.app.repo
# setup an hg repo with code
test_helper.setup_simple_hg_repo(repo)
assert repo.type == "hg"
# fork it
# need: src_project, src_url, src_app
clone_url = repo.repo_dir # was repo.clone_url() but should use local, filesystem address
p = c.app.project
# need a user to fork
c.user = M.User.query.get(username='test_admin')
app = p.install_app('Repository',
"test_hg_fork",
type="hg")
with push_config(c, project=p, app=app):
repo = app.repo
repo.type = app.repo.type
repo.status = 'pending fork'
new_url = repo.url()
c.app.repo.do_fork(dict(
url=clone_url,
forked_to=dict(project_id=str(p._id),
app_config_id=str(app.config._id)),
forked_from=dict(project_id=str(c.project._id),
app_config_id=str(c.app.config._id))))
# verify fork
assert app.repo.repo_dir
assert app.repo.scmlib() == hg
assert "changeset" in app.repo.scmlib().scm_log().run().output
def test_setup_simple_git_repo(self):
repo = c.app.repo
url = test_helper.create_git_repo()
test_helper.setup_simple_git_repo(repo)
def test_fork(self):
c.user = M.User.query.get(username='test_admin')
c.app.repo.fork(c.project._id, self.new_fork_mount_point)
# 1. assert that a new mount point is created
assert_true(c.project.app_instance(self.new_fork_mount_point))
def test_hg_init(self):
repo = c.app.repo
repo.do_init(dict(), "hg")
assert repo.status == 'Ready'
assert_equal(repo.type, "hg")
# assert web is setup - NYI
# assert commit hook is setup
commit_hook_path = os.path.join(repo.repo_dir,'.hg', 'hgrc')
assert os.path.isfile(commit_hook_path)
assert "python:forgescm.lib.hg.incoming_hook" in open(commit_hook_path, "r").read()
repo.scmlib().scm_log().run_exc()
def test_svn_init(self):
repo = c.app.repo
repo.do_init(dict(), "svn")
assert_equal(repo.type, "svn")
assert repo.status == 'Ready'
# assert web is setup
# assert commit hook is setup
assert os.path.isfile(os.path.join(repo.repo_dir, "hooks/post-commit"))
def test_git_init(self):
repo = c.app.repo
readme_path = test_helper.create_readme(repo.repo_dir) # creates a file named README in repo_dir
repo.do_init(dict(), "git")
assert_equal(repo.type, "git")
# the readme we created above should be gone
assert os.path.isfile(readme_path) == False
assert repo.status == 'Ready'
# assert web is setup
gitweb_conf_path = os.path.join(repo.repo_dir, 'gitweb.conf')
assert os.path.isfile(gitweb_conf_path)
# assert commit hook is setup
commit_hook_path = os.path.join(repo.repo_dir,'.git', 'hooks', 'post-receive')
assert os.path.isfile(commit_hook_path)
def test_create_git_repo(self):
url = test_helper.create_git_repo()
assert "git_repo" in url
assert os.path.exists(url + "/.git")
def test_git_clone(self):
repo = c.app.repo
src_url = test_helper.create_git_repo()
repo.do_clone(src_url, "git")
assert_equal(repo.cloned_from, src_url)
assert src_url != repo.repo_dir
assert os.path.isdir(os.path.join(repo.repo_dir, ".git"))
# do_clone fires a scm.cloned message, lets do that manually here
assert_equal(repo.commits.count(), 0)
def test_hg_clone(self):
repo = c.app.repo
src_url = test_helper.test_hg_repo_dir()
repo.do_clone(src_url, "hg")
assert_equal(repo.cloned_from, src_url)
assert src_url != repo.repo_dir
assert os.path.isdir(os.path.join(repo.repo_dir, ".hg"))
def test_svn_clone(self):
repo = c.app.repo
src_url = test_helper.test_svn_repo_dir()
repo.do_clone(src_url, "svn")
assert_equal(repo.cloned_from, src_url)
assert src_url != repo.repo_dir
assert os.path.isfile(os.path.join(repo.repo_dir, "conf", "svnserve.conf"))
class TestCommit(TestCase):
def setUp(self):
return