Ejemplo n.º 1
0
    def test_select_account(self, mock_list_acs, mock_option_sel):
        """
        Test account selection logic
        """
        test_class = YNAB_API(self.cp)
        test_class.budget_id = "Test Budget ID"
        test_banks = [
            ("test_api_existing_bank", "Test Account ID"),
            ("New Bank", "ID #2"),
        ]
        test_class.config_path = self.TEMPCONFPATH
        test_class.config = configparser.RawConfigParser()
        test_class.config.read(test_class.config_path)

        mock_ids = [
            ("Account 1", "ID #1"),
            ("Account 2", "ID #2"),
            ("Account 3", "ID #3"),
        ]
        mock_list_acs.return_value = mock_ids
        mock_option_sel.return_value = "ID #2"

        for bank, target_id in test_banks:
            id = test_class.select_account(bank)
            self.assertEqual(id, target_id)
Ejemplo n.º 2
0
    def test_save_account_selection(self):
        """
        Test that account info is saved under the correct bank and
        in the correct file.
        """
        test_class = YNAB_API(self.cp)
        test_class.budget_id = "Test Budget ID"
        test_account_id = "Test Account ID"
        test_banks = ["New Bank", "Existing Bank"]
        test_class.config_path = self.TEMPCONFPATH
        test_class.config = configparser.RawConfigParser()
        test_class.config.read(test_class.config_path)

        # save test bank details to test config
        for test_bank in test_banks:
            test_class.save_account_selection(test_bank, test_account_id)
        # check test config for test bank details & make sure ID matches
        config = configparser.RawConfigParser()
        config.read(test_class.user_config_path)
        for test_bank in test_banks:
            test_id = config.get(test_bank, "YNAB Account ID")
            self.assertEqual(
                test_id, "{}||{}".format(test_class.budget_id,
                                         test_account_id))