Skip to content

Commit

Permalink
refactor(tests): move bank PDF fixtures to same dir as test files
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd committed Oct 29, 2023
1 parent 2b0df10 commit f1c843e
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tests/integration/fixtures/**/input.pdf filter=git-crypt diff=git-crypt
tests/integration/banks/**/input.pdf filter=git-crypt diff=git-crypt
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ _ignore*
*.txt

# allowed pdf files/fixtures
!tests/integration/fixtures/*/**
!tests/integration/fixtures/*.pdf
!tests/integration/banks/**/*.csv
!tests/integration/banks/**/*.pdf
!monopoly/examples/*.pdf

# john files
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions tests/integration/banks/test_banks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from pathlib import Path

import pandas as pd
import pytest
Expand All @@ -22,13 +23,11 @@
)
def test_bank_operations(bank_class: BankBase, total_amount, statement_date):
bank_name = bank_class.statement_config.bank_name
bank: BankBase = bank_class(
file_path=f"tests/integration/fixtures/{bank_name}/input.pdf"
)
raw_data = pd.read_csv(f"tests/integration/fixtures/{bank_name}/raw.csv")
transformed_data = pd.read_csv(
f"tests/integration/fixtures/{bank_name}/transformed.csv"
)

fixture_directory = Path(__file__).parent / bank_name
bank: BankBase = bank_class(fixture_directory / "input.pdf")
raw_data = pd.read_csv(fixture_directory / "raw.csv")
transformed_data = pd.read_csv(fixture_directory / "transformed.csv")

# Check extracted data is correct
statement: Statement = bank.extract()
Expand Down
18 changes: 11 additions & 7 deletions tests/integration/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
from pathlib import Path

from pytest import raises

from monopoly.banks import Hsbc
from monopoly.config import BruteForceConfig
from monopoly.pdf import PdfParser

fixture_directory = Path(__file__).parent / "fixtures"


def test_can_open_protected(parser: PdfParser):
parser.file_path = "tests/integration/fixtures/protected.pdf"
parser.file_path = fixture_directory / "protected.pdf"
parser.password = "foobar123"

parser.open()


def test_can_brute_force_open_protected(parser: PdfParser):
brute_force_config = BruteForceConfig("foobar", "?d?d?d")
parser.file_path = "tests/integration/fixtures/protected.pdf"
parser.file_path = fixture_directory / "protected.pdf"

parser.open(brute_force_config)


def test_wrong_password_raises_error(parser: PdfParser):
parser.file_path = "tests/integration/fixtures/protected.pdf"
parser.file_path = fixture_directory / "protected.pdf"
parser.password = "wrong_pw"

with raises(ValueError, match="Wrong password"):
parser.open()


def test_get_pages(parser: PdfParser):
parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf"
parser.file_path = fixture_directory / "4_pages_blank.pdf"
parser.page_range = slice(0, -1)

pages = parser.get_pages()
assert len(pages) == 3


def test_get_pages_invalid_returns_error(parser: PdfParser):
parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf"
parser.file_path = fixture_directory / "4_pages_blank.pdf"
parser.page_range = slice(99, -99)

with raises(ValueError, match="bad page number"):
parser.get_pages()


def test_override_password(hsbc: Hsbc):
hsbc = Hsbc("tests/integration/fixtures/protected.pdf", password="foobar123")
hsbc = Hsbc(fixture_directory / "protected.pdf", password="foobar123")

document = hsbc.open()
assert not document.is_encrypted


def test_error_raised_if_override_is_wrong():
with raises(ValueError, match="Wrong password"):
hsbc = Hsbc("tests/integration/fixtures/protected.pdf", password="wrongpw")
hsbc = Hsbc(fixture_directory / "protected.pdf", password="wrongpw")
hsbc.open()

0 comments on commit f1c843e

Please sign in to comment.