'Test linking a user account to a pre-existing person record'

def testLinkToExistingPerson(self):

    auth = current.auth
    s3db = current.s3db
    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    utable = auth.settings.table_user
    user = Storage(first_name='TestLTPR', last_name='User', email='testltpr@example.com', password='XYZ')
    user_id = utable.insert(**user)
    assertTrue((user_id is not None))
    user['id'] = user_id
    person_id = auth.s3_link_to_person(user, self.org_id)
    assertNotEqual(person_id, None)
    assertFalse(isinstance(person_id, list))
    assertEqual(person_id, self.person_id)
    ptable = s3db.pr_person
    person = ptable[person_id]
    assertNotEqual(person, None)
    ltable = s3db.pr_person_user
    query = ((ltable.user_id == user_id) & (ltable.pe_id == person.pe_id))
    links = current.db(query).select()
    assertEqual(len(links), 1)
