Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
    def matches(self, taxing_context):
        """
        Check if this tax rule matches given taxing context.

        :type taxing_context: shuup.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
Exemple #4
0
    def matches(self, taxing_context):
        """
        Check if this tax rule matches given taxing context.

        :type taxing_context: shuup.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