|
1 | 1 | import pytest
|
2 |
| -import requests_mock |
3 | 2 | from requests.exceptions import HTTPError
|
4 | 3 |
|
5 | 4 | from commercetools.platform import models
|
@@ -42,12 +41,12 @@ def test_product_types_get_by_key(old_client):
|
42 | 41 |
|
43 | 42 |
|
44 | 43 | def test_product_type_query(old_client):
|
45 |
| - product_type = old_client.product_types.create( |
| 44 | + old_client.product_types.create( |
46 | 45 | models.ProductTypeDraft(
|
47 | 46 | key="test-product-type1", name="test-1", description="something"
|
48 | 47 | )
|
49 | 48 | )
|
50 |
| - product_type = old_client.product_types.create( |
| 49 | + old_client.product_types.create( |
51 | 50 | models.ProductTypeDraft(
|
52 | 51 | key="test-product-type2", name="test-2", description="something"
|
53 | 52 | )
|
@@ -88,3 +87,47 @@ def test_product_update(old_client):
|
88 | 87 | key="test-product-type", version=product_type.version, actions=[]
|
89 | 88 | )
|
90 | 89 | assert product_type.key == "test-product-type"
|
| 90 | + |
| 91 | + |
| 92 | +def test_product_update_attribute_constraint_change(old_client): |
| 93 | + attribute_name = "testConstraint" |
| 94 | + product_type = old_client.product_types.create( |
| 95 | + models.ProductTypeDraft( |
| 96 | + key="test-product-type", |
| 97 | + name="test", |
| 98 | + description="something", |
| 99 | + attributes=[ |
| 100 | + models.AttributeDefinitionDraft( |
| 101 | + type=models.AttributeTextType(), |
| 102 | + name=attribute_name, |
| 103 | + label=models.LocalizedString({"en": "testConstraint"}), |
| 104 | + is_required=False, |
| 105 | + attribute_constraint=models.AttributeConstraintEnum.SAME_FOR_ALL, |
| 106 | + ) |
| 107 | + ], |
| 108 | + ) |
| 109 | + ) |
| 110 | + |
| 111 | + assert product_type.id |
| 112 | + assert product_type.key == "test-product-type" |
| 113 | + assert ( |
| 114 | + product_type.attributes[0].attribute_constraint |
| 115 | + == models.AttributeConstraintEnum.SAME_FOR_ALL |
| 116 | + ) |
| 117 | + |
| 118 | + product_type = old_client.product_types.update_by_id( |
| 119 | + id=product_type.id, |
| 120 | + version=product_type.version, |
| 121 | + actions=[ |
| 122 | + models.ProductTypeChangeAttributeConstraintAction( |
| 123 | + attribute_name=attribute_name, |
| 124 | + new_value=models.AttributeConstraintEnumDraft.NONE, |
| 125 | + ) |
| 126 | + ], |
| 127 | + ) |
| 128 | + |
| 129 | + assert product_type.key == "test-product-type" |
| 130 | + assert ( |
| 131 | + product_type.attributes[0].attribute_constraint |
| 132 | + == models.AttributeConstraintEnum.NONE |
| 133 | + ) |
0 commit comments