'Make assertions common to all API entities.
If a reference is provided, the entity will also be compared against
the reference.'

def assertValidEntity(self, entity, ref=None, keys_to_check=None):

    if (keys_to_check is not None):
        keys = keys_to_check
    else:
        keys = ['name', 'description', 'enabled']
    for k in (['id'] + keys):
        msg = ('%s    unexpectedly    None    in    %s' % (k, entity))
        self.assertIsNotNone(entity.get(k), msg)
    self.assertIsNotNone(entity.get('links'))
    self.assertIsNotNone(entity['links'].get('self'))
    self.assertThat(entity['links']['self'], matchers.StartsWith('http://localhost'))
    self.assertIn(entity['id'], entity['links']['self'])
    if ref:
        for k in keys:
            msg = ('%s    not    equal:    %s    !=    %s' % (k, ref[k], entity[k]))
            self.assertEqual(ref[k], entity[k])
    return entity
