예제 #1
0
def test_create_valid_date():
    assert create_valid_date(1877) == '1877'
    assert create_valid_date('1877') == '1877'
    assert create_valid_date('1877-02') == '1877-02'
    assert create_valid_date('1877-02-03') == '1877-02-03'
    assert create_valid_date(1977) == '1977'
    assert create_valid_date('1977') == '1977'
    assert create_valid_date('1977-06-02') == '1977-06-02'
    assert create_valid_date('1977-06-022') == '1977-06'
    assert create_valid_date('1977-06-220') == '1977-06'
예제 #2
0
def test_create_valid_date():
    """TODO."""
    assert create_valid_date(1877) == '1877'
    assert create_valid_date('1877') == '1877'
    assert create_valid_date('1877-02') == '1877-02'
    assert create_valid_date('1877-02-03') == '1877-02-03'
    assert create_valid_date(1977) == '1977'
    assert create_valid_date('1977') == '1977'
    assert create_valid_date('1977-06-02') == '1977-06-02'
    assert create_valid_date('1977-06-022') == '1977-06'
    assert create_valid_date('1977-06-220') == '1977-06'
예제 #3
0
def test_create_valid_date():
    """Test date validator used in dojson conversions."""
    assert create_valid_date(1877) == '1877'
    assert create_valid_date('1877') == '1877'
    assert create_valid_date('1877-02') == '1877-02'
    assert create_valid_date('1877-02-03') == '1877-02-03'
    assert create_valid_date(1977) == '1977'
    assert create_valid_date('1977') == '1977'
    assert create_valid_date('1977-06-02') == '1977-06-02'
    assert create_valid_date('1977-06-022') == '1977-06'
    assert create_valid_date('1977-06-220') == '1977-06'
예제 #4
0
def dates_validator(recid, json, *args, **kwargs):
    """Find and assign the correct dates in a record."""
    dates_to_check = ['opening_date', 'closing_date', 'deadline_date']
    for date_key in dates_to_check:
        if date_key in json:
            valid_date = create_valid_date(json[date_key])
            if valid_date != json[date_key]:
                current_app.logger.warning(
                    'MALFORMED: {0} value in {1}: {3}'.format(
                        date_key, recid, json[date_key]))
            json[date_key] = valid_date
예제 #5
0
def dates_validator(recid, json, *args, **kwargs):
    """Find and assign the correct dates in a record."""
    dates_to_check = ['opening_date', 'closing_date', 'deadline_date']
    for date_key in dates_to_check:
        if date_key in json:
            valid_date = create_valid_date(json[date_key])
            if valid_date != json[date_key]:
                current_app.logger.warning(
                    'MALFORMED: {0} value in {1}: {3}'.format(
                        date_key, recid, json[date_key]
                    )
                )
            json[date_key] = valid_date
예제 #6
0
def dates_validator(sender, json, *args, **kwargs):
    """Validate some dates in a record before indexing.

    Logs a warning if the value of a `date_key` in `DATE_KEYS_TO_CHECK` is
    invalid, as determined by the `create_valid_date` function. The valid
    value is substituted for the old value in all cases.
    """
    DATE_KEYS_TO_CHECK = [
        'opening_date',
        'closing_date',
        'deadline_date',
    ]

    for date_key in DATE_KEYS_TO_CHECK:
        if date_key in json:
            valid_date = create_valid_date(json[date_key])
            if valid_date != json[date_key]:
                current_app.logger.warning(
                    'MALFORMED: %s value in %s: %s', date_key,
                    json['control_number'], json[date_key])
            json[date_key] = valid_date
예제 #7
0
def dates_validator(sender, json, *args, **kwargs):
    """Validate some dates in a record before indexing.

    Logs a warning if the value of a `date_key` in `DATE_KEYS_TO_CHECK` is
    invalid, as determined by the `create_valid_date` function. The valid
    value is substituted for the old value in all cases.
    """
    DATE_KEYS_TO_CHECK = [
        'opening_date',
        'closing_date',
        'deadline_date',
    ]

    for date_key in DATE_KEYS_TO_CHECK:
        if date_key in json:
            valid_date = create_valid_date(json[date_key])
            if valid_date != json[date_key]:
                current_app.logger.warning(
                    'MALFORMED: %s value in %s: %s', date_key,
                    json['control_number'], json[date_key])
            json[date_key] = valid_date