'Test construction of date field'

def testDateFieldConstruction(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    dm = S3DynamicModel(self.TABLENAME)
    define_field = dm._field
    params = Storage(name='start_date', field_type='date')
    field = define_field(self.TABLENAME, params)
    assertEqual(field.name, 'start_date')
    assertEqual(field.type, 'date')
    requires = field.requires
    assertTrue(isinstance(requires, IS_EMPTY_OR))
    requires = requires.other
    assertTrue(isinstance(requires, IS_UTC_DATE))
    assertEqual(requires.minimum, None)
    assertEqual(requires.maximum, None)
    params = Storage(name='start_date', field_type='date', require_not_empty=True, settings={'past': 10, 'future': 8})
    field = define_field(self.TABLENAME, params)
    assertEqual(field.name, 'start_date')
    assertEqual(field.type, 'date')
    requires = field.requires
    assertTrue(isinstance(requires, IS_UTC_DATE))
    now = current.request.utcnow.date()
    from dateutil.relativedelta import relativedelta
    assertEqual(requires.minimum, (now - relativedelta(months=10)))
    assertEqual(requires.maximum, (now + relativedelta(months=8)))
    params = Storage(name='start_date', field_type='date', default_value='now', require_not_empty=True)
    field = define_field(self.TABLENAME, params)
    assertEqual(field.name, 'start_date')
    assertEqual(field.type, 'date')
    requires = field.requires
    assertTrue(isinstance(requires, IS_UTC_DATE))
    assertEqual(field.default, now)
    params = Storage(name='start_date', field_type='date', default_value='2016-08-14', require_not_empty=True)
    field = define_field(self.TABLENAME, params)
    assertEqual(field.name, 'start_date')
    assertEqual(field.type, 'date')
    requires = field.requires
    assertTrue(isinstance(requires, IS_UTC_DATE))
    assertEqual(field.default, datetime.date(2016, 8, 14))
    params = Storage(name='start_date', field_type='date', default_value='invalid_default', require_not_empty=True)
    field = define_field(self.TABLENAME, params)
    assertEqual(field.name, 'start_date')
    assertEqual(field.type, 'date')
    requires = field.requires
    assertTrue(isinstance(requires, IS_UTC_DATE))
    assertEqual(field.default, None)
