Slide 13
Slide 13 text
SMALL EXAMPLE: CREATE_VM
Factor out everything that uses the session…
…build a test double for the session object…
…and then write some tests.
@app.task(time_limit=120)
def create_vm(vm, xenserver, template, name, **others):
session = getSession(
xenserver.hostname, xenserver.username, xenserver.password)
return _create_vm(session, vm, template, name, **others)
def _create_vm(session, vm, template, name, **others):
storage = session.xenapi.SR.get_all()
# ... Another 180 lines of VM creation using the session ...
class FakeXenServer(object):
"""Fake XenServer to use in tests."""
# ... 300+ lines of implementation ...