'Test construction of reference field'

def testReferenceFieldConstruction(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    dm = S3DynamicModel(self.TABLENAME)
    define_field = dm._field
    params = Storage(name='organisation_id', field_type='reference    org_organisation')
    field = define_field(self.TABLENAME, params)
    assertEqual(field.name, 'organisation_id')
    assertEqual(field.type, 'reference    org_organisation')
    requires = field.requires
    assertTrue(isinstance(requires, IS_EMPTY_OR))
    requires = requires.other
    assertTrue(isinstance(requires, IS_ONE_OF))
    assertEqual(requires.ktable, 'org_organisation')
    params = Storage(name='organisation_id', field_type='reference    org_organisation', require_not_empty=True)
    field = define_field(self.TABLENAME, params)
    assertEqual(field.name, 'organisation_id')
    assertEqual(field.type, 'reference    org_organisation')
    requires = field.requires
    assertTrue(isinstance(requires, IS_ONE_OF))
    assertEqual(requires.ktable, 'org_organisation')
    params = Storage(name='organisation_id', field_type='reference    nonexistent_table')
    field = define_field(self.TABLENAME, params)
    assertEqual(field, None)
