def test_pattern_cache(): convoluted_pat_text = ",".join([str(x) for x in range(0, 1000, 2)]) _compile_pattern.cache_clear() assert _compile_pattern.cache_info().currsize == 0 assert pattern_matches(convoluted_pat_text, "32") assert _compile_pattern.cache_info().currsize == 1 assert _compile_pattern.cache_info().misses == 1 assert not pattern_matches(convoluted_pat_text, "31") assert _compile_pattern.cache_info().currsize == 1 assert _compile_pattern.cache_info().misses == 1 assert _compile_pattern.cache_info().hits == 1
def matches(self, taxing_context): if self.country_codes_pattern: if not pattern_matches(self.country_codes_pattern, taxing_context.country_code): return False if self.region_codes_pattern: if not pattern_matches(self.region_codes_pattern, taxing_context.region_code): return False if self.postal_codes_pattern: if not pattern_matches(self.postal_codes_pattern, taxing_context.postal_code): return False return True
def matches(self, taxing_context): """ Check if this tax rule matches given taxing context. :type taxing_context: shoop.core.taxing.TaxingContext """ if taxing_context.customer_tax_group: tax_groups = set(self.customer_tax_groups.all()) if tax_groups: if taxing_context.customer_tax_group not in tax_groups: return False if self.country_codes_pattern: if not pattern_matches(self.country_codes_pattern, taxing_context.country_code): return False if self.region_codes_pattern: if not pattern_matches(self.region_codes_pattern, taxing_context.region_code): return False if self.postal_codes_pattern: if not pattern_matches(self.postal_codes_pattern, taxing_context.postal_code): return False return True