def test_invalid_check_existing_file_status():
    '''
    Test the values returned by input that is invalid
    '''
    entity = synapseclient.Entity(name='second.txt', id='syn2345', md5='44444')
    entity.properties.versionNumber = '1'
    entities = [entity]

    file_status = input_to_database.check_existing_file_status(
        mock_csv_query_result(validation_statusdf),
        mock_csv_query_result(error_trackerdf), entities)
    assert not file_status['to_validate']
    assert file_status['status_list'] == ['INVALID']
    assert file_status['error_list'] == ['Invalid file format']
def test_nostorederrors_check_existing_file_status():
    '''
    If there is no error uploaded, must re-validate file
    '''
    entity = synapseclient.Entity(name='second.txt', id='syn2345', md5='44444')
    entity.properties.versionNumber = '1'
    entities = [entity]

    file_status = input_to_database.check_existing_file_status(
        mock_csv_query_result(validation_statusdf),
        mock_csv_query_result(emptydf), entities)
    assert file_status['to_validate']
    assert file_status['status_list'] == ['INVALID']
    assert file_status['error_list'] == []
def test_unvalidatedinput_check_existing_file_status():
    '''
    Test the values returned by input that hasn't be validated
    '''
    entity = synapseclient.Entity(id='syn1234')
    entity.properties.versionNumber = '1'

    entities = [entity]

    file_status = input_to_database.check_existing_file_status(
        mock_csv_query_result(emptydf), mock_csv_query_result(emptydf),
        entities)
    assert file_status['to_validate']
    assert file_status['status_list'] == []
    assert file_status['error_list'] == []
def test_twoinvalid_check_existing_file_status():
    '''
    Test to make sure both invalid statues get passed back
    '''
    validation_statusdf = pd.DataFrame({
        'id': ['syn1234', 'syn2345'],
        'versionNumber': ['1', '1'],
        'status': ['INVALID', 'INVALID'],
        'md5': ['3333', '44444'],
        'name': ['first.txt', 'second.txt']
    })
    error_trackerdf = pd.DataFrame({
        'id': ['syn1234', 'syn2345'],
        'versionNumber': ['1', '1'],
        'errors': ['Invalid file format', 'Invalid formatting issues']
    })

    first_entity = synapseclient.Entity(name='first.txt',
                                        id='syn1234',
                                        md5='3333')
    first_entity.properties.versionNumber = '1'

    second_entity = synapseclient.Entity(name='second.txt',
                                         id='syn2345',
                                         md5='44444')
    second_entity.properties.versionNumber = '1'

    entities = [first_entity, second_entity]
    file_status = input_to_database.check_existing_file_status(
        mock_csv_query_result(validation_statusdf),
        mock_csv_query_result(error_trackerdf), entities)
    assert not file_status['to_validate']
    assert file_status['status_list'] == ['INVALID', 'INVALID']
    assert file_status['error_list'] == [
        'Invalid file format', 'Invalid formatting issues'
    ]