[IMP] *: testing helpers

* add a sorted method on fake models
* fix recordset equality to ignore ids order
* when creating commits on a ref, add a param to only *update* the ref
  (forcefully): when simulating a force-push we don't want to *create*
  a ref as that might silently be done in the wrong repository entirely
* fix pytest.skip call at the module level, not sure where it came
  from and why I missed it until now
This commit is contained in:
Xavier Morel 2019-10-14 09:33:21 +02:00
parent cc029c2891
commit 8f3f773eef
3 changed files with 15 additions and 7 deletions

View File

@ -523,7 +523,7 @@ class Repo:
)
return h
def make_commits(self, root, *commits, ref=None):
def make_commits(self, root, *commits, ref=None, make=True):
assert self.hook
if isinstance(root, list):
parents = root
@ -567,7 +567,8 @@ class Repo:
parents = [hashes[-1]]
if ref:
self.make_ref(ref, hashes[-1], force=True)
fn = self.make_ref if make else self.update_ref
fn(ref, hashes[-1], force=True)
return hashes
@ -925,7 +926,7 @@ class Model:
def __eq__(self, other):
if not isinstance(other, Model):
return NotImplemented
return self._model == other._model and self._ids == other._ids
return self._model == other._model and set(self._ids) == set(other._ids)
def __repr__(self):
return "{}({})".format(self._model, ', '.join(str(id_) for id_ in self._ids))
@ -950,6 +951,10 @@ class Model:
def unlink(self):
return self._env(self._model, 'unlink', self._ids)
def sorted(self, field):
rs = sorted(self.read([field]), key=lambda r: r[field])
return Model(self._env, self._model, [r['id'] for r in rs])
def __getitem__(self, index):
if isinstance(index, str):
return getattr(self, index)

View File

@ -283,7 +283,8 @@ More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port
[new_c] = pr_repo.make_commits(
pr1.target.name,
Commit('whop whop', tree={'x': '5'}),
ref='heads/%s' % pr_ref
ref='heads/%s' % pr_ref,
make=False
)
env.run_crons()
@ -398,7 +399,8 @@ xxx
# "b" was cloned before that branch got rolled back
prod.commit('b').id,
Commit('g should indeed b xxx', tree={'g': 'xxx'}),
ref='heads/%s' % pr_ref
ref='heads/%s' % pr_ref,
make=False,
)
env.run_crons()
assert prod.read_tree(prod.commit(pr1.head)) == {
@ -502,7 +504,8 @@ def test_conflict_deleted(env, config, make_repo):
# "b" was cloned before that branch got rolled back
prod.commit('b').id,
Commit('f should indeed be removed', tree={'g': 'c'}, reset=True),
ref='heads/%s' % pr_ref
ref='heads/%s' % pr_ref,
make=False,
)
env.run_crons()
assert prod.read_tree(prod.commit(pr1.head)) == {

View File

@ -809,7 +809,7 @@ def test_forward_port(env, repo, config):
commits = {c['sha'] for c in repo.log('heads/master')}
assert len(commits) == 112
@pytest.skip("Needs to find a way to make set_ref fail on *second* call.")
@pytest.mark.skip("Needs to find a way to make set_ref fail on *second* call.")
def test_rebase_failure(env, repo, users, config):
""" It looks like gh.rebase() can fail in the final ref-setting after
the merging & commits creation has been performed. At this point, the