Exemplo n.º 1
0
def test_aggregation_for_multiple_trades_pending_state(
        mock_pre_transform_data):
    mock_pre_transform_data.return_value = [
        Trade(correlation_id=234,
              number_of_trades=3,
              trade_limit=1000,
              trade_value=100),
        Trade(correlation_id=234,
              number_of_trades=3,
              trade_limit=1000,
              trade_value=100),
    ]

    actual = get_aggregated_data(test_input_file)
    expected = {
        234:
        TradeAggregate(
            number_of_trades=3,
            trade_limit=1000,
            trade_value=200,
            trade_count=2,
            state="Pending",
        )
    }
    assert actual == expected
Exemplo n.º 2
0
def test_aggregation_for_multiple_trades_mock_aggregated_state(
        mock_pre_transform_data, mock_aggregate):
    mock_pre_transform_data.return_value = [
        Trade(correlation_id=234,
              number_of_trades=2,
              trade_limit=1000,
              trade_value=100),
        Trade(correlation_id=234,
              number_of_trades=2,
              trade_limit=1000,
              trade_value=200),
    ]

    mock_aggregate.return_value = TradeAggregate(
        number_of_trades=2,
        trade_limit=1000,
        trade_value=300,
        trade_count=2,
        state="Accepted",
    )

    actual = get_aggregated_data(test_input_file)
    expected = {
        234:
        TradeAggregate(
            number_of_trades=2,
            trade_limit=1000,
            trade_value=300,
            trade_count=2,
            state="Accepted",
        ),
    }
    assert actual == expected
Exemplo n.º 3
0
def test_aggregation_for_multiple_trades_all_three_states(
        mock_pre_transform_data):
    mock_pre_transform_data.return_value = [
        Trade(correlation_id=234,
              number_of_trades=3,
              trade_limit=1000,
              trade_value=100),
        Trade(correlation_id=234,
              number_of_trades=3,
              trade_limit=1000,
              trade_value=200),
        Trade(correlation_id=234,
              number_of_trades=3,
              trade_limit=1000,
              trade_value=200),
        Trade(correlation_id=222,
              number_of_trades=1,
              trade_limit=500,
              trade_value=600),
        Trade(correlation_id=200,
              number_of_trades=2,
              trade_limit=2000,
              trade_value=1000),
    ]

    actual = get_aggregated_data(test_input_file)
    expected = {
        234:
        TradeAggregate(
            number_of_trades=3,
            trade_limit=1000,
            trade_value=500,
            trade_count=3,
            state="Accepted",
        ),
        222:
        TradeAggregate(
            number_of_trades=1,
            trade_limit=500,
            trade_value=600,
            trade_count=1,
            state="Rejected",
        ),
        200:
        TradeAggregate(
            number_of_trades=2,
            trade_limit=2000,
            trade_value=1000,
            trade_count=1,
            state="Pending",
        ),
    }
    assert actual == expected
Exemplo n.º 4
0
def write_files(input_file=None, output_file=None, log_file=None):
    data = None

    try:
        data = get_aggregated_data(input_file)
        data = sorted(data.items(), key=lambda k: k)
        write_output_csv(output_file, data)
        write_server_log(log_file, total=len(data))

    except AggregationException as e:
        """TODO"""
        # Add more defensive error handling throught the application
        error_message = f"{str(e)} on {str(datetime.now())}"
        write_server_log(log_file, error_message=error_message)
    except Exception as e:
        error_message = f"{str(e)} {str(datetime.now())}"
        write_server_log(log_file, error_message=error_message)
        raise
Exemplo n.º 5
0
def test_accepted_single_trade_rejected_state(mock_pre_transform_data):
    mock_pre_transform_data.return_value = [
        Trade(correlation_id=234,
              number_of_trades=1,
              trade_limit=50,
              trade_value=100)
    ]

    actual = get_aggregated_data(test_input_file)
    expected = {
        234:
        TradeAggregate(
            number_of_trades=1,
            trade_limit=50,
            trade_value=100,
            trade_count=1,
            state="Rejected",
        )
    }
    assert actual == expected