2018-01-13 12:18:03 +01:00
|
|
|
import os.path
|
2018-01-13 13:05:49 +01:00
|
|
|
|
2018-01-11 20:53:41 +01:00
|
|
|
import pytest
|
|
|
|
from byro_shackspace.utils import process_bank_csv
|
|
|
|
from django.core.files.uploadedfile import InMemoryUploadedFile
|
|
|
|
|
|
|
|
from byro.bookkeeping.models import RealTransactionSource
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def bank_transaction_csv_file():
|
2018-01-13 12:18:03 +01:00
|
|
|
filename = os.path.join(os.path.dirname(__file__), 'fixtures/transactions.csv')
|
|
|
|
actual_file = open(filename, encoding='iso-8859-1')
|
2018-01-11 20:53:41 +01:00
|
|
|
f = InMemoryUploadedFile(
|
|
|
|
file=actual_file,
|
|
|
|
field_name=None,
|
|
|
|
name='transactions.csv',
|
|
|
|
content_type='text',
|
|
|
|
size=len(actual_file.read()),
|
|
|
|
charset='iso-8859-1',
|
|
|
|
)
|
|
|
|
return RealTransactionSource.objects.create(source_file=f)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def test_bank_import(bank_transaction_csv_file):
|
2018-07-08 22:07:59 +02:00
|
|
|
assert bank_transaction_csv_file.bookings.count() == 0
|
2018-01-13 14:03:47 +01:00
|
|
|
process_bank_csv(bank_transaction_csv_file, None)
|
|
|
|
bank_transaction_csv_file.refresh_from_db()
|
2018-07-08 22:07:59 +02:00
|
|
|
assert bank_transaction_csv_file.bookings.count() == 6
|
2018-01-13 14:03:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def test_bank_import_no_duplicates(bank_transaction_csv_file):
|
2018-07-08 22:07:59 +02:00
|
|
|
assert bank_transaction_csv_file.bookings.count() == 0
|
2018-01-13 14:03:47 +01:00
|
|
|
process_bank_csv(bank_transaction_csv_file, None)
|
|
|
|
bank_transaction_csv_file.refresh_from_db()
|
2018-07-08 22:07:59 +02:00
|
|
|
assert bank_transaction_csv_file.bookings.count() == 6
|
2018-01-13 14:03:47 +01:00
|
|
|
process_bank_csv(bank_transaction_csv_file, None)
|
2018-01-11 20:53:41 +01:00
|
|
|
bank_transaction_csv_file.refresh_from_db()
|
2018-07-08 22:07:59 +02:00
|
|
|
assert bank_transaction_csv_file.bookings.count() == 6
|