Exemplo n.º 1
0
def datetime_field_data(field, **kwargs):
    """
    Return random value for DateTimeField

    >>> result = any_form_field(forms.DateTimeField())
    >>> type(result)
    <type 'str'>
    """
    from_date = kwargs.get('from_date', datetime(1990, 1, 1))
    to_date = kwargs.get('to_date', datetime.today())
    date_format = random.choice(field.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'))
    return xunit.any_datetime(from_date=from_date, to_date=to_date).strftime(date_format)
Exemplo n.º 2
0
def datetime_field_data(field, **kwargs):
    """
    Return random value for DateTimeField

    >>> result = any_form_field(forms.DateTimeField())
    >>> type(result)
    <type 'str'>
    """
    from_date = kwargs.get('from_date', datetime(1990, 1, 1))
    to_date = kwargs.get('to_date', datetime.today())
    date_format = random.choice(field.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'))
    return xunit.any_datetime(from_date=from_date, to_date=to_date).strftime(date_format)
Exemplo n.º 3
0
def any_datetime_field(field, **kwargs):
    """
    Return random value for DateTimeField,
    skips auto_now and auto_now_add fields

    >>> result = any_field(models.DateTimeField())
    >>> type(result)
    <type 'datetime.datetime'>
    """
    from_date = kwargs.get('from_date', datetime(1990, 1, 1))
    to_date = kwargs.get('to_date', datetime.today())
    return xunit.any_datetime(from_date=from_date, to_date=to_date)
Exemplo n.º 4
0
def any_datetime_field(field, **kwargs):
    """
    Return random value for DateTimeField,
    skips auto_now and auto_now_add fields

    >>> result = any_field(models.DateTimeField())
    >>> type(result)
    <type 'datetime.datetime'>
    """
    from_date = kwargs.get('from_date', datetime(1990, 1, 1))
    to_date = kwargs.get('to_date', datetime.today())
    return xunit.any_datetime(from_date=from_date, to_date=to_date)
Exemplo n.º 5
0
def any_datetime_field(field, **kwargs):
    """
    Return random value for DateTimeField,
    skips auto_now and auto_now_add fields

    >>> result = any_field(models.DateTimeField())
    >>> type(result)
    <type 'datetime.datetime'>
    """
    USE_TZ = getattr(settings, 'USE_TZ', False)
    from_date = kwargs.get('from_date', datetime(1990, 1, 1))
    
    if USE_TZ:
        from django.utils.timezone import now, get_current_timezone, make_aware
        
        from_date = make_aware(from_date, get_current_timezone())
        to_date = kwargs.get('to_date', now())
    else:    
        to_date = kwargs.get('to_date', datetime.today())
        
    return xunit.any_datetime(from_date=from_date, to_date=to_date)
Exemplo n.º 6
0
def any_datetime_field(field, **kwargs):
    """
    Return random value for DateTimeField,
    skips auto_now and auto_now_add fields

    >>> result = any_field(models.DateTimeField())
    >>> type(result)
    <type 'datetime.datetime'>
    """
    USE_TZ = getattr(settings, 'USE_TZ', False)
    from_date = kwargs.get('from_date', datetime(1990, 1, 1))

    if USE_TZ:
        from django.utils.timezone import now, get_current_timezone, make_aware

        from_date = make_aware(from_date, get_current_timezone())
        to_date = kwargs.get('to_date', now())
    else:
        to_date = kwargs.get('to_date', datetime.today())

    return xunit.any_datetime(from_date=from_date, to_date=to_date)