Fixed non working test on riak backend

- test was renamed from test_return_siblings_on_write to
  test_conflict_resolution_called
- custom mock like context manager created because riak.bucket disallows delattr

Change-Id: I1f8ff7ca85b34609d3b743d2a97e7e2748a335b4
Closes-bug: #1545772
This commit is contained in:
Jedrzej Nowak 2016-02-22 17:30:23 +01:00
parent e26f0083bb
commit 6137f1fe28

View File

@ -17,7 +17,6 @@ from __future__ import print_function
import pytest import pytest
from solar.config import C from solar.config import C
from solar.dblayer.conflict_resolution import SiblingsError
from solar.dblayer.model import check_state_for from solar.dblayer.model import check_state_for
from solar.dblayer.model import clear_cache from solar.dblayer.model import clear_cache
from solar.dblayer.model import StrInt from solar.dblayer.model import StrInt
@ -739,7 +738,7 @@ def test_remove_input(rk):
not ('riak' in C.solar_db and not C.riak_ensemble), not ('riak' in C.solar_db and not C.riak_ensemble),
reason=('Siblings error on write is expected' reason=('Siblings error on write is expected'
' only with n_val=1 and 1 node installation')) ' only with n_val=1 and 1 node installation'))
def test_return_siblings_on_write(rk): def test_conflict_resolution_called(rk):
pytest.importorskip('riak') pytest.importorskip('riak')
uid = next(rk) uid = next(rk)
@ -747,11 +746,31 @@ def test_return_siblings_on_write(rk):
lock.save() lock.save()
clear_cache() clear_cache()
with pytest.raises(SiblingsError): # manual mock like because riak_bucket disallow delattr
# which is used by mock
class PseudoMock(object):
def __init__(self):
self.call_count = 0
def __enter__(self):
def _manual_pseudo_mock(riak_object):
self.call_count += 1
assert len(riak_object.siblings) == 2
return Lock.bucket._orig_resolver(riak_object)
Lock.bucket._orig_resolver = Lock.bucket.resolver
Lock.bucket.resolver = _manual_pseudo_mock
return self
def __exit__(self, *exc_info):
Lock.bucket.resolver = Lock.bucket._orig_resolver
del Lock.bucket._orig_resolver
return False
with PseudoMock() as m:
lock1 = Lock.from_dict(uid, {'identity': uid}) lock1 = Lock.from_dict(uid, {'identity': uid})
lock1.save() lock1.save()
s1, s2 = lock1._riak_object.siblings assert m.call_count == 1
assert s1.data == s2.data
@pytest.mark.skipif( @pytest.mark.skipif(