<commit_before><commit_msg>Add unit tests for Strategy and Selector classes<commit_after>import unittest
from decimal import Decimal as D
from oscar_vat_moss.partner.strategy import *  # noqa

from mock import Mock


class DeferredVATSelectorTest(unittest.TestCase):

    def test_selector(self):
        selector = DeferredVATSelector()
        strategy = selector.strategy()
        self.assertEqual(strategy.__class__,
                         DeferredVATStrategy)
        with self.assertRaises(AttributeError):
            strategy.getRate(None, None)


class PerUserVATSelectorTest(unittest.TestCase):

    def test_selector(self):
        selector = PerUserVATSelector()
        strategy = selector.strategy()
        self.assertEqual(strategy.__class__,
                         PerUserVATStrategy)
        self.assertTrue(hasattr(strategy, 'get_rate'))


class PerUserVATStrategyTest(unittest.TestCase):

    def test_valid_user(self):
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''

        request = Mock()
        request.user = Mock()
        request.user.addresses = Mock()
        request.user.addresses.order_by = Mock(return_value=[address])
        request.user.is_authenticated = Mock(return_value=True)

        selector = PerUserVATSelector()
        strategy = selector.strategy(request=request)

        result_rate = strategy.get_rate(None, None)
        self.assertEqual(result_rate,
                         D('0.20'))

        address.vatin = 'ATU66688202'
        result_rate = strategy.get_rate(None, None)
        self.assertEqual(result_rate,
                         D('0.00'))
{'fraction_non_alphanumeric': 0.09198493813878429, 'fraction_numerical': 0.01613770844540075, 'mean_word_length': 2.536121673003802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5180372', 'n_tokens_mistral': 545, 'n_tokens_neox': 512, 'n_words': 100}