def test_should_decode_valid(self): file_content = [ '"19-11-2020";"19-11-2020";"Entry 1";"269,00";"5.423,67"', '"18-11-2020";"18-11-2020";"Entry 2";"-200,00";"5.223,67"', '"16-11-2020";"16-11-2020";"Entry 3";"150,00";"5.373,67"', ] sut = LsbReceiver("dummy-path", FakeCsvReader(file_content)) actual = sut.decode() expect = [ Transaction("Entry 1", datetime(2020, 11, 19, 0, 0, 0, 0), 269.00), Transaction("Entry 2", datetime(2020, 11, 18, 0, 0, 0, 0), -200.00), Transaction("Entry 3", datetime(2020, 11, 16, 0, 0, 0, 0), 150.00), ] assert actual == expect
def decode(self) -> List[Transaction]: csv_lines = self.reader.read(self.filepath) transactions: List[Transaction] = [] for row in csv.reader(csv_lines, delimiter=";"): if self.validate(row): date = self.to_datetime(row[1]) description = row[2] amount = self.to_float(row[3]) transactions.append(Transaction(description, date, amount)) return transactions
def test_should_decode_high_amount_correctly(self): file_content = [ '"19-11-2020";"19-11-2020";"Entry 1";"5.269,00";"5.423,67"', ] sut = LsbReceiver("dummy-path", FakeCsvReader(file_content)) actual = sut.decode() expect = [ Transaction("Entry 1", datetime(2020, 11, 19, 0, 0, 0, 0), 5269.00), ] assert actual == expect
class TestTransaction: date = parser.parse("03-02-2020", dayfirst=True) amount = 10.0 desc = "description" sut = Transaction(desc, date, amount) def test_normalization(self): expect = " description " assert self.sut.normalized_description == expect def test_norm_visa_dankort(self): sut = Transaction("Visa/Dankort transaction", self.date, self.amount) expect = " transaction " assert sut.normalized_description == expect def test_norm_dankort(self): sut = Transaction("Dankort transaction", self.date, self.amount) expect = " transaction " assert sut.normalized_description == expect def test_norm_mobilepay(self): sut = Transaction("MobilePay transaction", self.date, self.amount) expect = " transaction " assert sut.normalized_description == expect def test_repr(self): expect = "<Transaction: description='description', date=2020-02-03 00:00:00, amount=10.0>" assert self.sut.__repr__() == expect def test_comparandum(self): expect = " description " assert self.sut.comparandum() == expect def test_date(self): expect = self.date actual = self.sut.date() assert actual == expect def test_eq(self): other = Transaction(self.desc, self.date, self.amount) assert self.sut.__eq__(other)
def test_eq(self): other = Transaction(self.desc, self.date, self.amount) assert self.sut.__eq__(other)
def test_norm_mobilepay(self): sut = Transaction("MobilePay transaction", self.date, self.amount) expect = " transaction " assert sut.normalized_description == expect
def test_norm_dankort(self): sut = Transaction("Dankort transaction", self.date, self.amount) expect = " transaction " assert sut.normalized_description == expect