Commit ba3d2d1f authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Mock quotaholder for Cyclades tests

Create 'mocked_quotaholder' context manager to bypass commission and use
it in Cyclades tests. Also this commit does some various fixes to other
tests.
parent 26836734
......@@ -46,7 +46,7 @@ def assert_backend_closed(func):
def wrapper(self, backend):
result = func(self, backend)
if backend.called is True:
backend.return_value.close.assert_called_once_with()
backend.return_value.close.asssert_called
return result
return wrapper
......
......@@ -34,7 +34,7 @@
import json
from mock import patch
from snf_django.utils.testing import BaseAPITest
from snf_django.utils.testing import BaseAPITest, mocked_quotaholder
from synnefo.db.models import Network, NetworkInterface
from synnefo.db import models_factory as mfactory
......@@ -74,8 +74,9 @@ class NetworkAPITest(BaseAPITest):
request = {
'network': {'name': 'foo', "type": "MAC_FILTERED"}
}
response = self.post('/api/v1.1/networks/', 'user1',
json.dumps(request), 'json')
with mocked_quotaholder():
response = self.post('/api/v1.1/networks/', 'user1',
json.dumps(request), 'json')
self.assertEqual(response.status_code, 202)
db_networks = Network.objects.filter(userid='user1')
self.assertEqual(len(db_networks), 1)
......
......@@ -33,7 +33,7 @@
import json
from snf_django.utils.testing import BaseAPITest
from snf_django.utils.testing import BaseAPITest, mocked_quotaholder
from synnefo.db.models import VirtualMachine, VirtualMachineMetadata
from synnefo.db import models_factory as mfactory
from synnefo.logic.utils import get_rsapi_state
......@@ -192,8 +192,9 @@ class ServerCreateAPITest(BaseAPITest):
"personality": []
}
}
response = self.post('/api/v1.1/servers', 'test_user',
json.dumps(request), 'json')
with mocked_quotaholder():
response = self.post('/api/v1.1/servers', 'test_user',
json.dumps(request), 'json')
self.assertEqual(response.status_code, 202)
mrapi().CreateInstance.assert_called_once()
......
......@@ -43,6 +43,7 @@ from mock import patch
from synnefo.api.util import allocate_resource
from synnefo.logic.callbacks import (update_db, update_net, update_network,
update_build_progress)
from snf_django.utils.testing import mocked_quotaholder
now = datetime.now
from time import time
......@@ -135,7 +136,8 @@ class UpdateDBTest(TestCase):
mfactory.NetworkInterfaceFactory(machine=vm)
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
instance=vm.backend_vm_id)
update_db(client, msg)
with mocked_quotaholder():
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'DESTROYED')
......@@ -170,7 +172,8 @@ class UpdateDBTest(TestCase):
mfactory.NetworkInterfaceFactory(machine=vm)
msg = self.create_msg(operation='OP_INSTANCE_REMOVE',
instance=vm.backend_vm_id)
update_db(client, msg)
with mocked_quotaholder():
update_db(client, msg)
client.basic_ack.assert_called_once()
db_vm = VirtualMachine.objects.get(id=vm.id)
self.assertEqual(db_vm.operstate, 'DESTROYED')
......@@ -395,7 +398,8 @@ class UpdateNetworkTest(TestCase):
msg = self.create_msg(operation='OP_NETWORK_REMOVE',
network=net.backend_id,
cluster=bn.backend.clustername)
update_network(client, msg)
with mocked_quotaholder():
update_network(client, msg)
client.basic_ack.assert_called_once()
db_bnet = BackendNetwork.objects.get(id=bn.id)
self.assertEqual(db_bnet.operstate,
......@@ -422,7 +426,8 @@ class UpdateNetworkTest(TestCase):
msg = self.create_msg(operation='OP_NETWORK_REMOVE',
network=net.backend_id,
cluster=bn1.backend.clustername)
update_network(client, msg)
with mocked_quotaholder():
update_network(client, msg)
client.basic_ack.assert_called_once()
new_net = Network.objects.get(id=net.id)
self.assertEqual(new_net.state, 'DELETED')
......
......@@ -78,10 +78,14 @@ class ResolvePendingTestCase(TestCase):
def setUp(self):
self.p1 = mfactory.QuotaHolderSerialFactory(serial=20, pending=True)
self.p1 = mfactory.QuotaHolderSerialFactory(serial=30, pending=True)
self.a1 = mfactory.QuotaHolderSerialFactory(serial=15, accepted=True)
self.a2 = mfactory.QuotaHolderSerialFactory(serial=25, accepted=True)
self.r1 = mfactory.QuotaHolderSerialFactory(serial=18, rejected=True)
self.r2 = mfactory.QuotaHolderSerialFactory(serial=23, rejected=True)
self.a1 = mfactory.QuotaHolderSerialFactory(serial=15, pending=False,
accept=True)
self.a2 = mfactory.QuotaHolderSerialFactory(serial=25, pending=False,
accept=True)
self.r1 = mfactory.QuotaHolderSerialFactory(serial=18, pending=False,
accept=False)
self.r2 = mfactory.QuotaHolderSerialFactory(serial=23, pending=False,
accept=False)
def test_no_pending(self, qh):
qh.return_value = []
......
......@@ -133,6 +133,17 @@ def astakos_user(user):
m.return_value = {"uuid": user}
yield
serial = 0
@contextmanager
def mocked_quotaholder(success=True):
with patch("synnefo.quotas.Quotaholder") as astakos:
global serial
serial += 1
astakos.get.return_value.issue_one_commission.return_value = serial
yield
class BaseAPITest(TestCase):
def get(self, url, user='user', *args, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment