Skip to content

Commit a3c586c

Browse files
authored
Add changeMessagesEnabled & changeCountryTaxRateFallbackEnabled actions (#119)
1 parent b1ab04f commit a3c586c

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/commercetools/testing/project.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import copy
12
import uuid
23

4+
from commercetools.platform import models
35
from commercetools.platform.models._schemas.project import (
46
ProjectSchema,
57
ProjectUpdateSchema,
@@ -31,7 +33,10 @@ def __init__(self, storage):
3133
"languages": ["en", "nl", "de", "nl-BE"],
3234
"createdAt": "2018-10-04T11:32:12.603Z",
3335
"trialUntil": "2018-12",
34-
"carts": {},
36+
"carts": {
37+
"countryTaxRateFallbackEnabled": False,
38+
"deleteDaysAfterLastModification": 90,
39+
},
3540
"messages": {"enabled": False, "deleteDaysAfterCreation": 15},
3641
"externalOAuth": None,
3742
"version": 4,
@@ -52,11 +57,31 @@ def update(self, request):
5257
project_key = request.kwargs["project"]
5358
return self.update_by_key(request, project_key)
5459

60+
def change_messages_enabled(
61+
self, obj, action: models.ProjectChangeMessagesEnabledAction
62+
):
63+
# real API always increments version, so always apply new value.
64+
new = copy.deepcopy(obj)
65+
new["messages"]["enabled"] = action.messages_enabled
66+
return new
67+
68+
def change_country_tax_rate_fallback_enabled(
69+
self, obj, action: models.ProjectChangeCountryTaxRateFallbackEnabledAction
70+
):
71+
# real API always increments version, so always apply new value.
72+
new = copy.deepcopy(obj)
73+
new["carts"][
74+
"countryTaxRateFallbackEnabled"
75+
] = action.country_tax_rate_fallback_enabled
76+
return new
77+
5578
# Fixme: use decorator for this
5679
_actions = {
5780
"changeCountries": update_attribute("countries", "countries"),
5881
"changeCurrencies": update_attribute("currencies", "currencies"),
5982
"changeName": update_attribute("name", "name"),
6083
"changeLanguages": update_attribute("languages", "languages"),
6184
"setExternalOAuth": update_attribute("externalOAuth", "external_oauth"),
85+
"changeMessagesEnabled": change_messages_enabled,
86+
"changeCountryTaxRateFallbackEnabled": change_country_tax_rate_fallback_enabled,
6287
}
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
from commercetools.platform import models
22

33

4-
def test_project_update(old_client):
4+
def test_project_update_countries(old_client):
55
project = old_client.project.get()
66
project = old_client.project.update(
77
actions=[models.ProjectChangeCountriesAction(countries=["AT", "NL"])],
88
version=project.version,
99
)
1010
assert project.countries == ["AT", "NL"]
11+
12+
13+
def test_project_update_change_messages_enabled(old_client):
14+
project = old_client.project.get()
15+
project = old_client.project.update(
16+
actions=[models.ProjectChangeMessagesEnabledAction(messages_enabled=True)],
17+
version=project.version,
18+
)
19+
assert project.messages.enabled is True
20+
21+
22+
def test_project_update_change_country_tax_rate_fallback_enabled(old_client):
23+
project = old_client.project.get()
24+
project = old_client.project.update(
25+
actions=[
26+
models.ProjectChangeCountryTaxRateFallbackEnabledAction(
27+
country_tax_rate_fallback_enabled=True
28+
)
29+
],
30+
version=project.version,
31+
)
32+
assert project.carts.country_tax_rate_fallback_enabled is True

0 commit comments

Comments
 (0)