def component_to_tests(component, one_sided=True):
    device_path = '/'.join(component.device().getPrimaryPath())
    component_path = '/'.join(component.getPrimaryPath())
    component_path = re.sub('^' + device_path + '/', '', component_path)

    me = ManagedEntity('')
    propnames = sorted(set(component.propertyIds()) - set(me.propertyIds()))
    relnames = sorted(
        set(component.getRelationshipNames()) -
        set(me.getRelationshipNames()) -
        set(('depedencies', 'dependents', 'maintenanceWindows')))

    if one_sided:
        # remove relationships that are not alphabetically the first
        # one between themselves and the remote end of of the relationship.
        # This assumes that we'll be building tests for the other side of the
        # relationship and avoids duplicate tests.
        new_relnames = []
        for relname in relnames:
            rel = component._getOb(relname)
            if rel.id < rel.remoteName():
                new_relnames.append(relname)
        relnames = new_relnames

    out = []
    out.append("        component = self.device.getObjByPath(%r)" %
               component_path)
    for propname in ['title'] + propnames:
        out.append("        self.assertEquals(component.%s, %r)" %
                   (propname, getattr(component, propname)))

    for relname in relnames:
        rel = getattr(component, relname)
        objs = rel()
        if objs is None:
            out.append("        self.assertIsNone(component.%s())" % relname)
        elif isinstance(objs, list):
            out.append("        self.assertIsNotNone(component.%s())" %
                       relname)
            objids = sorted([x.id for x in objs])
            out.append(
                "        self.assertEquals(sorted([x.id for x in component.%s()]), %r)"
                % (relname, objids))
        else:
            out.append("        self.assertIsNotNone(component.%s())" %
                       relname)
            out.append("        self.assertEquals(component.%s().id, %r)" %
                       (relname, objs.id))

    return "\n".join(out)