def test_can_insert_into_total_order_fee(test_client, db, statements, expected):
    build_catalog(db, test_client)
    add_bandcamp_order_settings(db)
    for statement_type, filelist in statements.items():
        for _file in filelist:
            post_data(test_client, _file, statement_type)
    res = db.session.query(IncomePending).all()
    pi.normalize_distributor()
    pi.normalize_version()
    pi.normalize_track()
    pi.insert_into_imported_statements()
    pi.normalize_statement_id()
    pi.calculate_adjusted_amount()
    pi.move_from_pending_income_to_total()
    assert len(db.session.query(IncomeTotal).all()) == expected['records']
    amount_total = (db.session
            .query(func.sum(IncomeTotal.amount))
            .one()[0])
    assert round(float(amount_total), 2) == expected['amount_total']
    label_fee_total = (db.session
            .query(func.sum(IncomeTotal.label_fee))
            .one()[0])
    assert round(float(label_fee_total), 2) == expected['label_fee_total']
    label_net_total = (db.session
            .query(func.sum(IncomeTotal.label_net))
            .one()[0])
    assert round(float(label_net_total), 2) == expected['label_net_total']
def test_can_calculate_adjusted_label_amount(test_client, db):
    build_catalog(db, test_client)
    add_bandcamp_sales(test_client)
    pi.normalize_distributor()
    pi.normalize_version()
    pi.normalize_track()
    pi.insert_into_imported_statements()
    assert pi.calculate_adjusted_amount() == True
    res = db.session.query(IncomePending).filter(IncomePending.id == 4).first()
    assert res.id == 4
    assert res.label_fee == 0
    assert float(res.label_net) == 6.26
    add_bandcamp_order_settings(db)
    assert pi.calculate_adjusted_amount() == True
    res = db.session.query(IncomePending).filter(IncomePending.id == 4).first()
    assert res.id == 4
    assert float(res.label_fee) == 2.06
    assert float(res.label_net) == 4.20
示例#3
0
def setup_test1(test_client, db):
    path = os.getcwd() + "/tests/files/test1_catalog.csv"
    f = open(path, 'rb')
    data = {'CSV': f}
    response = test_client.post('/catalog/import-catalog', data=data)
    path = os.getcwd() + "/tests/files/test1_track.csv"
    f = open(path, 'rb')
    data = {'CSV': f}
    response = test_client.post('/catalog/import-track', data=data)
    path = os.getcwd() + "/tests/files/test1_version.csv"
    f = open(path, 'rb')
    data = {'CSV': f}
    response = test_client.post('/catalog/import-version', data=data)
    path = os.getcwd() + "/tests/files/test1_bandcamp.csv"
    data = {'statement_source': 'bandcamp'}
    data['file'] = (path, 'test1_bandcamp.csv')
    response = test_client.post('/income/import-sales',
                                data=data,
                                content_type="multipart/form-data")
    add_order_settings(db)
    path = os.getcwd() + "/tests/files/test1_expense_artist.csv"
    data = {'file': (path, 'test1_expense_artist.csv')}
    response = test_client.post('/expense/import-statement',
                                data=data,
                                content_type="multipart/form-data")
    path = os.getcwd() + "/tests/files/test1_expense_catalog.csv"
    data = {'file': (path, 'test1_expense_catalog.csv')}
    response = test_client.post('/expense/import-statement',
                                data=data,
                                content_type="multipart/form-data")
    pi.normalize_distributor()
    pi.normalize_version()
    pi.normalize_track()
    pi.insert_into_imported_statements()
    pi.normalize_statement_id()
    pi.calculate_adjusted_amount()
    pi.move_from_pending_income_to_total()
    pe.normalize_artist()
    pe.normalize_catalog()
    pe.normalize_expense_type()
    pe.insert_into_imported_statements()
    pe.normalize_statement_id()
    pe.move_from_pending_expense_to_total()
def test_zero_out_label_fees(test_client, db):
    build_catalog(db, test_client)
    add_two_bandcamp_sales(test_client)
    add_bandcamp_order_settings(db)
    pi.normalize_distributor()
    pi.normalize_version()
    pi.normalize_track()
    pi.insert_into_imported_statements()
    assert pi.calculate_adjusted_amount() == True
    res = db.session.query(IncomePending).filter(IncomePending.order_id == '2').first()
    assert res.label_fee == 0
    res = db.session.query(IncomePending).filter(IncomePending.order_id == '3').first()
    assert res.label_fee == 0
def test_can_divide_fees_over_order_items(test_client, db):
    build_catalog(db, test_client)
    add_two_bandcamp_sales(test_client)
    res = db.session.query(IncomePending).all()
    assert len(res) != 0
    add_bandcamp_order_settings(db)
    pi.normalize_distributor()
    pi.normalize_version()
    pi.normalize_track()
    pi.insert_into_imported_statements()
    assert pi.calculate_adjusted_amount() == True
    res = db.session.query(IncomePending).first()
    assert float(res.label_fee) == 0.73
    assert float(res.label_net) == 5.53