Beispiel #1
0
async def test_make_entity_links():
    schema = make_pfb_schema([person_entity_def, pet_entity_def])
    file = make_avro_file(schema, [
        {'name': 'person', 'id': '123', 'object': {'first_name': 'Brian'}},
        {'name': 'pet', 'id': '456', 'object': {'pet_name': 'Asa'}, 'relations': [
            {'dst_name': 'person', 'dst_id': '123'}
        ]}
    ])

    result = await translate(fastavro.reader(file))
    assert result == [
        {
            'name': '123',
            'entityType': 'person',
            'operations': [
                add_update_attribute('first_name', 'Brian')
            ]
        },
        {
            'name': '456',
            'entityType': 'pet',
            'operations': [
                add_update_attribute('pet_name', 'Asa'),
                add_update_attribute('person', {
                    'entityType': 'person',
                    'entityName': '123'
                })
            ]
        }
    ]
Beispiel #2
0
async def test_decode_enum_value():
    use_base64_encoded_enums = True

    schema = make_pfb_schema([make_sample_entity_def(use_base64_encoded_enums)])
    file = make_avro_file(schema, [
        {'name': 'sample', 'id': '123', 'object': {'tissue_type': tissue_type_b64_values['Tumor']}},
        {'name': 'sample', 'id': '456', 'object': {'tissue_type': tissue_type_b64_values['Normal']}},
        {'name': 'sample', 'id': '789', 'object': {'tissue_type': tissue_type_b64_values['Unknown']}}
    ])

    result = await translate(fastavro.reader(file), {'b64-decode-enums': use_base64_encoded_enums})
    assert result == [
        {
            'name': '123',
            'entityType': 'sample',
            'operations': [
                add_update_attribute('tissue_type', 'Tumor')
            ]
        },
        {
            'name': '456',
            'entityType': 'sample',
            'operations': [
                add_update_attribute('tissue_type', 'Normal')
            ]
        },
        {
            'name': '789',
            'entityType': 'sample',
            'operations': [
                add_update_attribute('tissue_type', 'Unknown')
            ]
        }
    ]
Beispiel #3
0
async def test_make_file_links():
    schema = make_pfb_schema([file_def])
    file = make_avro_file(schema, [
        {'name': 'file', 'id': '123', 'object': {'object_id': 'abc.de/12345'}}
    ])

    result = await translate(fastavro.reader(file))
    assert result == [
        {
            'name': '123',
            'entityType': 'file',
            'operations': [
                add_update_attribute('object_id', 'abc.de/12345')
            ]
        }
    ]
    file.seek(0)
    result = await translate(fastavro.reader(file), {'prefix-object-ids': True})
    assert result == [
        {
            'name': '123',
            'entityType': 'file',
            'operations': [
                add_update_attribute('object_id', 'drs://abc.de/12345')
            ]
        }
    ]
Beispiel #4
0
async def test_disambiguate_enum_and_non_enum():
    """
    Verify enum value decoding when different entities have fields with the same names
    """
    schema = make_pfb_schema([make_sample_entity_def(), other_sample_entity_def])
    file = make_avro_file(schema, [
        {'name': 'sample', 'id': '123', 'object': {'tissue_type': tissue_type_b64_values['Tumor']}},
        {'name': 'other_sample', 'id': '456', 'object': {'tissue_type': 'not a tumor'}},
    ])

    result = await translate(fastavro.reader(file), {'b64-decode-enums': True})
    assert result == [
        {
            'name': '123',
            'entityType': 'sample',
            'operations': [
                add_update_attribute('tissue_type', 'Tumor')
            ]
        },
        {
            'name': '456',
            'entityType': 'other_sample',
            'operations': [
                add_update_attribute('tissue_type', 'not a tumor')
            ]
        }
    ]
Beispiel #5
0
async def test_ignore_metadata():
    schema = make_pfb_schema()
    file = make_avro_file(schema, [
        {'name': 'Metadata', 'object': {}}
    ])

    result = await translate(fastavro.reader(file))
    assert result == []
Beispiel #6
0
async def test_filter_none_values():
    schema = make_pfb_schema([person_entity_def])
    file = make_avro_file(schema, [
        {'name': 'person', 'id': '123', 'object': {'first_name': 'Test'}}
    ])

    result = await translate(fastavro.reader(file))
    assert result == [
        {
            'name': '123',
            'entityType': 'person',
            'operations': [
                add_update_attribute('first_name', 'Test')
            ]
        }
    ]
Beispiel #7
0
async def test_rename_name_attributes():
    schema = make_pfb_schema([named_entity_def])
    file = make_avro_file(schema, [
        {'name': 'thing', 'id': '1', 'object': {'name': 'Thing 1'}}
    ])

    result = await translate(fastavro.reader(file))
    assert result == [
        {
            'name': '1',
            'entityType': 'thing',
            'operations': [
                add_update_attribute('thing_name', 'Thing 1')
            ]
        }
    ]
Beispiel #8
0
async def test_translate_record():
    schema = make_pfb_schema([person_entity_def])
    file = make_avro_file(schema, [
        {'name': 'person', 'id': '123', 'object': {
            'first_name': 'Test', 'last_name': 'Dummy', 'eye_color': 'gray'
        }}
    ])

    result = await translate(fastavro.reader(file))
    assert result == [
        {
            'name': '123',
            'entityType': 'person',
            'operations': [
                add_update_attribute('first_name', 'Test'),
                add_update_attribute('last_name', 'Dummy'),
                add_update_attribute('eye_color', 'gray')
            ]
        }
    ]
Beispiel #9
0
async def test_translate_nothing():
    schema = make_pfb_schema()
    file = make_avro_file(schema)
    result = await translate(fastavro.reader(file))
    assert result == []