fixtures.events module

Event testing fixture.

The idea of this fixture is to pass some “expected” events to utils.events.EventListener and check whether all expected events are received at the test end.

register_event fixture accepts attributes for one expected event

simple example:

register_event(target_type='VmOrTemplate', target_name=vm_crud.name, event_type='vm_create')

more complex example:

def add_cmp(_, y):
    data = yaml.load(y)
    return data['resourceId'].endswith(nsg_name) and data['status']['value'] == 'Accepted' and             data['subStatus']['value'] == 'Created'

fd_add_attr = {'full_data': 'will be ignored',
               'cmp_func': add_cmp}

# add network security group event
register_event(fd_add_attr, source='AZURE',
               event_type='networkSecurityGroups_write_EndRequest')

def rm_cmp(_, y):
    data = yaml.load(y)
    return data['resourceId'].endswith(nsg_name) and data['status']['value'] == 'Succeeded'             and len(data['subStatus']['value']) == 0

fd_rm_attr = {'full_data': 'will be ignored',
              'cmp_func': rm_cmp}

# remove network security group event
register_event(fd_rm_attr, source=provider.type.upper(),
               event_type='networkSecurityGroups_delete_EndRequest')

Expected events are defined by set of event attributes which should match to the same event attributes in event_streams db table except one fake attribute - target_name which is resolved into certain object’s id.

Default match algorithm is ==. Event also accepts match function in order to change default match type.

fixtures.events.pytest_runtest_call(item)[source]
fixtures.events.register_event(list of event attributes)[source]

Event registration fixture.

This fixture is used to notify the testing system that some event should have occurred during execution of the test case using it. It does not register anything by itself.

Parameters:
  • attribute 1 (event) –
  • ..
  • attribute N (event) –

Returns: None

Usage:

def test_something(foo, bar, register_event, appliance):
    register_event(target_type = 'VmOrTemplate', target_name = vm.name,
        event_type = 'vm_create')