'Test sending to a group that contains an invalid membership'

def testProcessingEmailToInvalidPersonInGroup(self):

    db = current.db
    s3db = current.s3db
    ptable = s3db.pr_person
    gtable = s3db.pr_group
    mtable = s3db.pr_group_membership
    query = ((((gtable.uuid == 'MsgTestGroup') & (mtable.group_id == gtable.id)) & (ptable.id == mtable.person_id)) & (ptable.uuid == 'MsgTestPerson1'))
    membership = db(query).select(mtable.id).first()
    db((mtable.id == membership.id)).update(person_id=None)
    s3db = current.s3db
    resource = s3db.resource('pr_group', uid=['MsgTestGroup'])
    rows = resource.select(['pe_id'], as_rows=True)
    self.sent = []
    outbox = s3db.msg_outbox
    for row in rows:
        outbox_id = outbox.insert(pe_id=row.pe_id, message_id=self.message_id)
    msg = current.msg
    msg.send_email = self.send_email
    msg.process_outbox()
    self.assertEqual(len(self.sent), 1)
    self.assertTrue(('test2@example.com' in self.sent))
