Commit 4c53e75a authored by Łukasz Nowak's avatar Łukasz Nowak

Fine tune simulator.

parent 03bc7006
...@@ -10,15 +10,23 @@ import tempfile ...@@ -10,15 +10,23 @@ import tempfile
import os import os
class Simulator: class Simulator:
def __init__(self, outfile): def __init__(self, outfile, method):
self.outfile = outfile self.outfile = outfile
self.method = method
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
"""Simulation Method""" """Simulation Method"""
open(self.outfile, 'a').write('recargs = %r\nreckwargs = %r' % (args, old = open(self.outfile, 'r').read()
kwargs)) if old:
l = eval(old)
else:
l = []
l.append({'recmethod': self.method,
'recargs': args,
'reckwargs': kwargs})
open(self.outfile, 'w').write(repr(l))
class RaisingSimulator(Simulator): class RaisingSimulator:
def __init__(self, exception): def __init__(self, exception):
self.exception = exception self.exception = exception
...@@ -81,8 +89,8 @@ class VifibSlaposRestAPIV1Mixin(TestVifibSlapWebServiceMixin): ...@@ -81,8 +89,8 @@ class VifibSlaposRestAPIV1Mixin(TestVifibSlapWebServiceMixin):
self.person_request_simulator = tempfile.mkstemp()[1] self.person_request_simulator = tempfile.mkstemp()[1]
self.customer, self.customer_reference = self.createPerson() self.customer, self.customer_reference = self.createPerson()
self.customer.requestSoftwareInstance = Simulator( self.customer.requestSoftwareInstance = Simulator(self.person_request_simulator,
self.person_request_simulator) 'requestSoftwareInstance')
transaction.commit() transaction.commit()
def beforeTearDown(self): def beforeTearDown(self):
...@@ -121,10 +129,7 @@ class VifibSlaposRestAPIV1Mixin(TestVifibSlapWebServiceMixin): ...@@ -121,10 +129,7 @@ class VifibSlaposRestAPIV1Mixin(TestVifibSlapWebServiceMixin):
self.assertEqual(open(self.person_request_simulator).read(), '') self.assertEqual(open(self.person_request_simulator).read(), '')
def assertPersonRequestSimulator(self, args, kwargs): def assertPersonRequestSimulator(self, args, kwargs):
# fillup magic stored = eval(open(self.person_request_simulator).read())
recargs = ()
reckwargs = {}
exec(open(self.person_request_simulator).read())
# do the same translation magic as in tool # do the same translation magic as in tool
kwargs = kwargs.copy() kwargs = kwargs.copy()
for k_j, k_i in ( for k_j, k_i in (
...@@ -137,8 +142,9 @@ class VifibSlaposRestAPIV1Mixin(TestVifibSlapWebServiceMixin): ...@@ -137,8 +142,9 @@ class VifibSlaposRestAPIV1Mixin(TestVifibSlapWebServiceMixin):
('status', 'state') ('status', 'state')
): ):
kwargs[k_i] = kwargs.pop(k_j) kwargs[k_i] = kwargs.pop(k_j)
self.assertEqual(args, recargs) self.assertEqual(stored,
self.assertEqual(kwargs, reckwargs) [{'recargs': args, 'reckwargs': kwargs,
'recmethod': 'requestSoftwareInstance'}])
class TestInstanceRequest(VifibSlaposRestAPIV1Mixin): class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
def test_not_logged_in(self): def test_not_logged_in(self):
...@@ -608,7 +614,7 @@ class VifibSlaposRestAPIV1BangMixin(VifibSlaposRestAPIV1InstanceMixin): ...@@ -608,7 +614,7 @@ class VifibSlaposRestAPIV1BangMixin(VifibSlaposRestAPIV1InstanceMixin):
super(VifibSlaposRestAPIV1BangMixin, self).afterSetUp() super(VifibSlaposRestAPIV1BangMixin, self).afterSetUp()
self.instance_bang_simulator = tempfile.mkstemp()[1] self.instance_bang_simulator = tempfile.mkstemp()[1]
self.software_instance.reportComputerPartitionBang = Simulator( self.software_instance.reportComputerPartitionBang = Simulator(
self.instance_bang_simulator) self.instance_bang_simulator, 'reportComputerPartitionBang')
transaction.commit() transaction.commit()
def beforeTearDown(self): def beforeTearDown(self):
...@@ -620,14 +626,12 @@ class VifibSlaposRestAPIV1BangMixin(VifibSlaposRestAPIV1InstanceMixin): ...@@ -620,14 +626,12 @@ class VifibSlaposRestAPIV1BangMixin(VifibSlaposRestAPIV1InstanceMixin):
self.assertEqual(open(self.instance_bang_simulator).read(), '') self.assertEqual(open(self.instance_bang_simulator).read(), '')
def assertInstanceBangSimulator(self, args, kwargs): def assertInstanceBangSimulator(self, args, kwargs):
# fillup magic stored = eval(open(self.instance_bang_simulator).read())
recargs = ()
reckwargs = {}
exec(open(self.instance_bang_simulator).read())
# do the same translation magic as in workflow # do the same translation magic as in workflow
kwargs['comment'] = kwargs.pop('log') kwargs['comment'] = kwargs.pop('log')
self.assertEqual(args, recargs) self.assertEqual(stored,
self.assertEqual(kwargs, reckwargs) [{'recargs': args, 'reckwargs': kwargs,
'recmethod': 'reportComputerPartitionBang'}])
class TestInstancePOSTbang(VifibSlaposRestAPIV1BangMixin): class TestInstancePOSTbang(VifibSlaposRestAPIV1BangMixin):
def test(self): def test(self):
......
36 37
\ No newline at end of file \ No newline at end of file
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