Beispiel #1
0
    def test_fail():
        """Factory should raise ValueError when input row is undefined type."""

        # Reason: This class is just for test. pylint: disable=too-few-public-methods
        class UndefinedZaimRowConverter(ZaimRowConverter):
            pass

        class UndefinedInputRow(InputRow):
            pass

        class UndefinedInputRowData(InputRowData):
            # Reason: Raw code is simple enough. pylint: disable=missing-docstring
            @property
            def date(self) -> datetime:
                return datetime.now()

            @property
            def store_name(self) -> str:
                return ""

            @property
            def item_name(self) -> str:
                return ""

            @property
            def validate(self) -> bool:
                return False

        with pytest.raises(ValueError) as error:
            ZaimRowFactory.create(UndefinedZaimRowConverter(UndefinedInputRow(UndefinedInputRowData())))
        assert str(error.value) == "Undefined Zaim row converter. Zaim row converter = UndefinedZaimRowConverter"
    def test(yaml_config_load, database_session_stores_sf_card_viewer):
        """Arguments should set into properties."""
        expected_amount = 3000
        config_account_name = "PASMO"
        config_auto_charge_source = "TOKYU CARD"
        sf_card_viewer_row = SFCardViewerRow(
            InstanceResource.
            ROW_DATA_SF_CARD_VIEWER_AUTO_CHARGE_AKIHABARA_STATION,
            CONFIG.pasmo)

        class ConcreteSFCardViewerZaimTransferRowConverter(
                SFCardViewerZaimTransferRowConverter):
            account_config = CONFIG.pasmo

        zaim_row = ZaimRowFactory.create(
            ConcreteSFCardViewerZaimTransferRowConverter(sf_card_viewer_row))
        assert isinstance(zaim_row, ZaimTransferRow)
        list_zaim_row = zaim_row.convert_to_list()
        zaim_row_data = ZaimRowData(*list_zaim_row)
        assert zaim_row_data.date == "2018-11-11"
        assert zaim_row_data.store_name == ""
        assert zaim_row_data.item_name == ""
        assert zaim_row_data.cash_flow_source == config_auto_charge_source
        assert zaim_row_data.cash_flow_target == config_account_name
        assert zaim_row_data.amount_transfer == expected_amount
    def test(yaml_config_load, database_session_stores_sf_card_viewer):
        """Arguments should set into properties."""
        expected_amount = 195
        config_account_name = "PASMO"
        sf_card_viewer_row = SFCardViewerEnterExitRow(
            InstanceResource.
            ROW_DATA_SF_CARD_VIEWER_TRANSPORTATION_KOHRAKUEN_STATION,
            CONFIG.pasmo)

        class ConcreteSFCardViewerZaimPaymentOnStationRowConverter(
                SFCardViewerZaimPaymentOnStationRowConverter):
            account_config = CONFIG.pasmo

        # Reason: Pylint's bug. pylint: disable=no-member
        zaim_row = ZaimRowFactory.create(
            ConcreteSFCardViewerZaimPaymentOnStationRowConverter(
                sf_card_viewer_row))
        assert isinstance(zaim_row, ZaimPaymentRow)
        list_zaim_row = zaim_row.convert_to_list()
        zaim_row_data = ZaimRowData(*list_zaim_row)
        assert zaim_row_data.date == "2018-11-13"
        assert zaim_row_data.store_name == "東京地下鉄株式会社 南北線後楽園駅"
        assert zaim_row_data.item_name == ""
        assert zaim_row_data.cash_flow_source == config_account_name
        assert zaim_row_data.note == "メトロ 六本木一丁目 → メトロ 後楽園"
        assert zaim_row_data.amount_payment == expected_amount
Beispiel #4
0
 def test_success(
     yaml_config_load,
     database_session_with_schema,
     zaim_row_converter_class,
     input_row: Type[WaonRow],
     waon_row_data: WaonRowData,
     expected,
 ):
     """Factory should create appropriate type of Zaim row."""
     assert isinstance(ZaimRowFactory.create(zaim_row_converter_class(input_row(waon_row_data))), expected)
Beispiel #5
0
 def test(waon_row_data, expected_date, expected_amount_payment,
          yaml_config_load, database_session_basic_store_waon):
     """Arguments should set into properties."""
     waon_row = WaonRow(waon_row_data)
     zaim_row = ZaimRowFactory.create(
         WaonZaimTransferRowConverter(waon_row))
     assert isinstance(zaim_row, ZaimTransferRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == expected_date
     assert zaim_row_data.cash_flow_source == "イオン銀行"
     assert zaim_row_data.cash_flow_target == "WAON"
     assert zaim_row_data.amount_transfer == expected_amount_payment
Beispiel #6
0
 def test_transfer_payment_row(yaml_config_load, database_session_stores_mufg):
     """Arguments should set into properties."""
     expected_amount = 3628
     config_account_name = "三菱UFJ銀行"
     # Reason: Pylint's bug. pylint: disable=no-member
     mufg_row = MufgPaymentToSomeoneRow(InstanceResource.ROW_DATA_MUFG_TRANSFER_PAYMENT_TOKYO_WATERWORKS)
     zaim_row = ZaimRowFactory.create(MufgTransferPaymentZaimTransferRowConverter(mufg_row))
     assert isinstance(zaim_row, ZaimTransferRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == "2018-11-28"
     assert zaim_row_data.store_name == ""
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.cash_flow_source == config_account_name
     assert zaim_row_data.cash_flow_target is None
     assert zaim_row_data.amount_transfer == expected_amount
Beispiel #7
0
 def test_transfer_income_row(yaml_config_load, database_session_stores_mufg):
     """Arguments should set into properties."""
     expected_amount = 20
     transfer_target = "三菱UFJ銀行"
     # Reason: Pylint's bug. pylint: disable=no-member
     mufg_row = MufgIncomeFromOthersRow(InstanceResource.ROW_DATA_MUFG_TRANSFER_INCOME_NOT_OWN_ACCOUNT)
     zaim_row = ZaimRowFactory.create(MufgTransferIncomeZaimTransferRowConverter(mufg_row))
     assert isinstance(zaim_row, ZaimTransferRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == "2018-08-20"
     assert zaim_row_data.store_name == ""
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.cash_flow_source is None
     assert zaim_row_data.cash_flow_target == transfer_target
     assert zaim_row_data.amount_transfer == expected_amount
 def test(yaml_config_load, database_session_item):
     """Arguments should set into properties."""
     expected_amount = 4980
     config_account_name = "ヨドバシゴールドポイントカード・プラス"
     store_name = "Amazon Japan G.K."
     item_name = "Echo Dot (エコードット) 第2世代 - スマートスピーカー with Alexa、ホワイト"
     amazon_row = Amazon201911PaymentRow(InstanceResource.ROW_DATA_AMAZON_201911_ECHO_DOT)
     # Reason: Pylint's bug. pylint: disable=no-member
     zaim_row = ZaimRowFactory.create(Amazon201911PaymentZaimPaymentRowConverter(amazon_row))
     assert isinstance(zaim_row, ZaimPaymentRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == "2019-11-09"
     assert zaim_row_data.store_name == store_name
     assert zaim_row_data.item_name == item_name
     assert zaim_row_data.cash_flow_source == config_account_name
     assert zaim_row_data.note == ""
     assert zaim_row_data.amount_payment == expected_amount
Beispiel #9
0
 def test(
     waon_row_data,
     expected_date,
     expected_store,
     expected_amount_payment,
     yaml_config_load,
     database_session_basic_store_waon,
 ):
     """Arguments should set into properties."""
     waon_row = WaonRow(waon_row_data)
     # Reason: Pylint's bug. pylint: disable=no-member
     zaim_row = ZaimRowFactory.create(WaonZaimPaymentRowConverter(waon_row))
     assert isinstance(zaim_row, ZaimPaymentRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == expected_date
     assert zaim_row_data.store_name == expected_store
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.cash_flow_source == "WAON"
     assert zaim_row_data.amount_payment == expected_amount_payment
Beispiel #10
0
 def test(
     view_card_row_data,
     expected_date,
     expected_store_name_zaim,
     expected_use_amount,
     yaml_config_load,
     database_session_stores_view_card,
 ):
     """Arguments should set into properties."""
     row = ViewCardRow(view_card_row_data)
     # Reason: Pylint's bug. pylint: disable=no-member
     zaim_row = ZaimRowFactory.create(ViewCardZaimPaymentRowConverter(row))
     assert isinstance(zaim_row, ZaimPaymentRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == expected_date
     assert zaim_row_data.store_name == expected_store_name_zaim
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.cash_flow_source == "ビューカード"
     assert zaim_row_data.amount_payment == expected_use_amount
 def test(
     gold_point_card_plus_row_data,
     expected_date,
     expected_store_name_zaim,
     expected_use_amount,
     yaml_config_load,
     database_session_stores_gold_point_card_plus,
 ):
     """Arguments should set into properties."""
     row = GoldPointCardPlusRow(gold_point_card_plus_row_data)
     # Reason: Pylint's bug. pylint: disable=no-member
     zaim_row = ZaimRowFactory.create(
         GoldPointCardPlusZaimPaymentRowConverter(row))
     assert isinstance(zaim_row, ZaimPaymentRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == expected_date
     assert zaim_row_data.store_name == expected_store_name_zaim
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.cash_flow_source == "ヨドバシゴールドポイントカード・プラス"
     assert zaim_row_data.amount_payment == expected_use_amount
Beispiel #12
0
 def test(
     mufg_row_data: MufgRowData,
     expected_date,
     expected_store,
     config_transfer_account_name,
     expect_cash_flow_target,
     expected_amount,
     yaml_config_load,
     database_session_stores_mufg,
 ):
     """Arguments should set into properties."""
     mufg_row = MufgIncomeFromOthersRow(mufg_row_data)
     # Reason: Pylint's bug. pylint: disable=no-member
     zaim_row = ZaimRowFactory.create(MufgZaimIncomeRowConverter(mufg_row))
     assert isinstance(zaim_row, ZaimIncomeRow)
     list_zaim_row = zaim_row.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)  # type: ignore
     assert zaim_row_data.date == expected_date
     assert zaim_row_data.store_name == expected_store
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.cash_flow_target == expect_cash_flow_target
     assert zaim_row_data.amount_income == expected_amount
Beispiel #13
0
 def test_all(yaml_config_load, database_session_stores_item):
     """Argument should set into properties."""
     waon_auto_charge_row = WaonRow(InstanceResource.ROW_DATA_WAON_AUTO_CHARGE_ITABASHIMAENOCHO)
     zaim_low = ZaimRowFactory.create(WaonZaimTransferRowConverter(waon_auto_charge_row))
     list_zaim_row = zaim_low.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == "2018-11-11"
     assert zaim_row_data.method == "transfer"
     assert zaim_row_data.category_large == "-"
     assert zaim_row_data.category_small == "-"
     assert zaim_row_data.cash_flow_source == "イオン銀行"
     assert zaim_row_data.cash_flow_target == "WAON"
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.note == ""
     assert zaim_row_data.store_name == ""
     assert zaim_row_data.currency == ""
     assert zaim_row_data.amount_income == 0
     assert zaim_row_data.amount_payment == 0
     assert zaim_row_data.amount_transfer == 5000
     assert zaim_row_data.balance_adjustment == ""
     assert zaim_row_data.amount_before_currency_conversion == ""
     assert zaim_row_data.setting_aggregate == ""
Beispiel #14
0
 def test_all(yaml_config_load, database_session_stores_item):
     """Argument should set into properties."""
     mufg_row = MufgIncomeFromOthersRow(InstanceResource.ROW_DATA_MUFG_TRANSFER_INCOME_NOT_OWN_ACCOUNT)
     # Reason: Pylint's bug. pylint: disable=no-member
     zaim_low = ZaimRowFactory.create(MufgZaimIncomeRowConverter(mufg_row))
     list_zaim_row = zaim_low.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == "2018-08-20"
     assert zaim_row_data.method == "income"
     assert zaim_row_data.category_large == "臨時収入"
     assert zaim_row_data.category_small == "-"
     assert zaim_row_data.cash_flow_source == ""
     assert zaim_row_data.cash_flow_target == "三菱UFJ銀行"
     assert zaim_row_data.item_name == ""
     assert zaim_row_data.note == ""
     assert zaim_row_data.store_name == "三菱UFJ銀行"
     assert zaim_row_data.currency == ""
     assert zaim_row_data.amount_income == 20
     assert zaim_row_data.amount_payment == 0
     assert zaim_row_data.amount_transfer == 0
     assert zaim_row_data.balance_adjustment == ""
     assert zaim_row_data.amount_before_currency_conversion == ""
     assert zaim_row_data.setting_aggregate == ""
Beispiel #15
0
 def test_all(
     yaml_config_load,
     database_session_stores_item,
     input_row_factory,
     input_row_data: SFCardViewerRowData,
     zaim_row_converter_selector,
     expected_date,
     expected_category_large,
     expected_category_small,
     expected_cash_flow_source,
     expected_item_name,
     expected_note,
     expected_store_name,
     expected_amount_payment,
 ):
     """Argument should set into properties."""
     input_row = input_row_factory.create(input_row_data)
     zaim_low = ZaimRowFactory.create(zaim_row_converter_selector.create(input_row))
     list_zaim_row = zaim_low.convert_to_list()
     zaim_row_data = ZaimRowData(*list_zaim_row)
     assert zaim_row_data.date == expected_date
     assert zaim_row_data.method == "payment"
     assert zaim_row_data.category_large == expected_category_large
     assert zaim_row_data.category_small == expected_category_small
     assert zaim_row_data.cash_flow_source == expected_cash_flow_source
     assert zaim_row_data.cash_flow_target == ""
     assert zaim_row_data.item_name == expected_item_name
     assert zaim_row_data.note == expected_note
     assert zaim_row_data.store_name == expected_store_name
     assert zaim_row_data.currency == ""
     assert zaim_row_data.amount_income == 0
     assert zaim_row_data.amount_payment == expected_amount_payment
     assert zaim_row_data.amount_transfer == 0
     assert zaim_row_data.balance_adjustment == ""
     assert zaim_row_data.amount_before_currency_conversion == ""
     assert zaim_row_data.setting_aggregate == ""
Beispiel #16
0
 def convert_input_row_to_zaim_row(self,
                                   input_row: TypeVarInputRow) -> ZaimRow:
     """This method converts input row into zaim row."""
     converter = self.zaim_row_converter_selector.create(input_row)
     return ZaimRowFactory.create(converter)