コード例 #1
0
    def test_categorize_with_uncertainty_keyword_calls_uncertainty(
        self, mock_uncertainty
    ):
        mock_transaction = mock.MagicMock()
        mock_category = mock.MagicMock()
        mock_transaction.text.lower.return_value = "A string with test in it."
        mock_category.keywords = ["test?"]
        categorize(mock_transaction, [mock_category])

        mock_uncertainty.assert_called_once()
コード例 #2
0
    def test_categorize_with_star_keyword_return_category_name(self):
        mock_transaction = mock.MagicMock()
        mock_category = mock.MagicMock()
        mock_transaction.text.lower.return_value = "A string without keyword in it."
        mock_category.keywords = ["*"]
        test_name = "test-name"
        mock_category.name = test_name
        actual = categorize(mock_transaction, [mock_category])

        self.assertEqual(actual, test_name)
コード例 #3
0
    def test_categorize_with_no_keyword_in_text_return_none(self):
        mock_transaction = mock.MagicMock()
        mock_category = mock.MagicMock()
        mock_transaction.text.lower.return_value = "A string without keyword in it."
        mock_category.keywords = ["test"]
        test_name = "test-name"
        mock_category.name = test_name
        actual = categorize(mock_transaction, [mock_category])

        self.assertIsNone(actual)
コード例 #4
0
    def test_categorize_with_uncertainty_keyword_returns_category_name_if_uncertainty_true(
        self, mock_uncertainty
    ):
        mock_transaction = mock.MagicMock()
        mock_category = mock.MagicMock()
        mock_transaction.text.lower.return_value = "A string with test in it."
        mock_category.keywords = ["test?"]
        test_name = "test-name"
        mock_category.name = test_name
        mock_uncertainty.return_value = True
        actual = categorize(mock_transaction, [mock_category])

        self.assertEqual(actual, test_name)
コード例 #5
0
    def test_categorize_with_multiple_keywords_and_star_returns_ordinary_keyword_category_first(
        self
    ):
        mock_transaction = mock.MagicMock()
        mock_transaction.text.lower.return_value = "A string with test in it."

        mock_category_star = mock.MagicMock()
        mock_category_star.keywords = ["*"]
        test_name_star = "wrong-name"
        mock_category_star.name = test_name_star

        mock_category_ordinary = mock.MagicMock()
        mock_category_ordinary.keywords = ["test", "keywords"]
        test_name_ordinary = "correct-name"
        mock_category_ordinary.name = test_name_ordinary

        actual = categorize(
            mock_transaction, [mock_category_star, mock_category_ordinary]
        )

        self.assertEqual(actual, test_name_ordinary)