コード例 #1
0
def test_concat_persons():
    persons = [
        Person(FirstName="Grant",
               LastName="Nicholas",
               Gender="M",
               FavoriteColor="Purple",
               DateOfBirth=datetime.datetime(year=1993,
                                             month=7,
                                             day=6,
                                             hour=0,
                                             minute=0)),
        Person(FirstName="Sally",
               LastName="Mae",
               Gender="F",
               FavoriteColor="Blue",
               DateOfBirth=datetime.datetime(year=1990,
                                             month=6,
                                             day=1,
                                             hour=0,
                                             minute=0))
    ]
    person_inputs = [persons for _ in xrange(3)]
    person_outputs = persons * 3
    persons = concat_persons(person_inputs)

    assert persons == person_outputs
コード例 #2
0
def test_df_to_persons():
    expected_persons = [
        Person(FirstName="Grant",
               LastName="Nicholas",
               Gender="M",
               FavoriteColor="Purple",
               DateOfBirth=datetime.datetime(year=1993,
                                             month=7,
                                             day=6,
                                             hour=0,
                                             minute=0)),
        Person(FirstName="Sally",
               LastName="Mae",
               Gender="F",
               FavoriteColor="Blue",
               DateOfBirth=datetime.datetime(year=1990,
                                             month=6,
                                             day=1,
                                             hour=0,
                                             minute=0))
    ]

    persons = df_to_persons(expected_df)

    assert expected_persons == persons
コード例 #3
0
def test_transform_persons_lastnamedesc():
    expected_persons = [
        Person(FirstName="Grant",
               LastName="Nicholas",
               Gender="M",
               FavoriteColor="Purple",
               DateOfBirth=datetime.datetime(year=1993,
                                             month=7,
                                             day=6,
                                             hour=0,
                                             minute=0)),
        Person(FirstName="Jillian",
               LastName="Nicholas",
               Gender="F",
               FavoriteColor="Purple",
               DateOfBirth=datetime.datetime(year=1992,
                                             month=1,
                                             day=1,
                                             hour=0,
                                             minute=0)),
        Person(FirstName="Sally",
               LastName="Mae",
               Gender="F",
               FavoriteColor="Blue",
               DateOfBirth=datetime.datetime(year=1990,
                                             month=6,
                                             day=1,
                                             hour=0,
                                             minute=0))
    ]
    transformed_persons = transform_persons(
        persons=persons, transform_option=TransformOptions.LastNameDesc)

    assert transformed_persons == expected_persons
コード例 #4
0
def test_ingest_three_files(filepipepath, filecommapath, filewhitespacepath):
    expected_persons = [
        Person(FirstName="Grant",
               LastName="Nicholas",
               Gender="M",
               FavoriteColor="Purple",
               DateOfBirth=datetime.datetime(
                   year=1993, month=7, day=6, hour=0, minute=0)),
        Person(FirstName="Sally",
               LastName="Mae",
               Gender="F",
               FavoriteColor="Blue",
               DateOfBirth=datetime.datetime(
                   year=1990, month=6, day=1, hour=0, minute=0))
    ] * 3

    persons = ingest_files([
        FileInfo(file_path=filepipepath, delimiter='|'),
        FileInfo(file_path=filecommapath, delimiter=','),
        FileInfo(file_path=filewhitespacepath, delimiter=' ')
    ])

    assert persons == expected_persons
コード例 #5
0
def test_post_good(test_client, db_client):
    assert db_client.get_records() == []
    posted_data = dumps({
        "line": "Nicholas,Grant,M,Purple,07-06-1993",
        "delimiter": ","
    })
    rv = test_client.post('/records', data=posted_data)

    assert rv.data == ""
    assert rv.status_code == 200
    assert db_client.get_records() == [
        Person(FirstName="Grant",
               LastName="Nicholas",
               Gender="M",
               FavoriteColor="Purple",
               DateOfBirth=datetime.datetime(year=1993,
                                             month=7,
                                             day=6,
                                             hour=0,
                                             minute=0))
    ]
コード例 #6
0
def df_to_persons(df, header=True):
    """
    Dataframe -> [Person];
    note we only ingest the columns of the dataframe that are in the Person object
    extra columns are ignored, but can be added by adding the correct column header to the person object
    :param df: Pandas dataframe containing the ingested person files
    :return: [Person]
    """
    col_mapping = {
        col: index
        for index, col in enumerate(df.columns)
    }

    # If we have a header, then we can ingest the data by the header name
    # Otherwise assume that the data is in the correct order
    attrs = [col_mapping[attr] for attr in Person._fields] if header else [index for index in range(len(df.columns))]
    persons = [
        Person(*[row[attr] for attr in attrs])
        for i, row in df.iterrows()
    ]

    return persons
コード例 #7
0
from personapi.lib.person_transformer import transform_persons, TransformOptions
from personapi.models.models import FileInfo, Person
import datetime
import pytest

persons = [
    Person(FirstName="Grant",
           LastName="Nicholas",
           Gender="M",
           FavoriteColor="Purple",
           DateOfBirth=datetime.datetime(year=1993,
                                         month=7,
                                         day=6,
                                         hour=0,
                                         minute=0)),
    Person(FirstName="Sally",
           LastName="Mae",
           Gender="F",
           FavoriteColor="Blue",
           DateOfBirth=datetime.datetime(year=1990,
                                         month=6,
                                         day=1,
                                         hour=0,
                                         minute=0)),
    Person(FirstName="Jillian",
           LastName="Nicholas",
           Gender="F",
           FavoriteColor="Purple",
           DateOfBirth=datetime.datetime(year=1992,
                                         month=1,
                                         day=1,