def test_get_cached_tax_codes_or_fetch_wrong_response(monkeypatch): monkeypatch.setattr("saleor.plugins.avatax.cache.get", lambda x, y: {}) config = AvataxConfiguration( username_or_account="wrong_data", password_or_license="wrong_data" ) tax_codes = get_cached_tax_codes_or_fetch(config) assert len(tax_codes) == 0
def test_checkout_needs_new_fetch(monkeypatch, checkout_with_item, address): monkeypatch.setattr("saleor.plugins.avatax.cache.get", lambda x: None) checkout_with_item.shipping_address = address config = AvataxConfiguration( username_or_account="wrong_data", password_or_license="wrong_data" ) checkout_data = generate_request_data_from_checkout(checkout_with_item, config) assert checkout_needs_new_fetch(checkout_data, str(checkout_with_item.token))
def test_api_post_request_handles_json_errors(product, monkeypatch): mocked_response = Mock(side_effect=JSONDecodeError("", "", 0)) monkeypatch.setattr("saleor.plugins.avatax.excise.utils.requests.post", mocked_response) config = AvataxConfiguration(username_or_account="test", password_or_license="test", use_sandbox=False) url = "https://www.avatax.api.com/some-get-path" response = api_post_request(url, {}, config) assert mocked_response.called assert response == {}
def test_get_cached_tax_codes_or_fetch(monkeypatch, settings): monkeypatch.setattr("saleor.plugins.avatax.cache.get", lambda x, y: {}) config = AvataxConfiguration(username_or_account="test", password_or_license="test") tax_codes = get_cached_tax_codes_or_fetch(config) assert len(tax_codes) > 0