Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Change name of buyer field to user in gift card model

fowczarek5ceaa88b39f2
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index aa22be5284..ee5cd5983b 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -811,7 +811,7 @@ def create_gift_card():
[User.objects.filter(is_superuser=False).order_by("?").first()]
)
gift_card, created = GiftCard.objects.get_or_create(
- code="Gift_card_10", buyer=user, initial_balance=10, current_balance=10
+ code="Gift_card_10", user=user, initial_balance=10, current_balance=10
)
if created:
yield "Gift card #%d" % gift_card.id
diff --git a/saleor/giftcard/models.py b/saleor/giftcard/models.py
index 89c8911562..e440cab8ae 100644
--- a/saleor/giftcard/models.py
+++ b/saleor/giftcard/models.py
@@ -18,7 +18,7 @@ class GiftCardQueryset(models.QuerySet):
class GiftCard(models.Model):
code = models.CharField(max_length=16, unique=True, db_index=True)
- buyer = models.ForeignKey(
+ user = models.ForeignKey(
settings.AUTH_USER_MODEL,
blank=True,
null=True,
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.py
index 07ea02421a..45ff4df43d 100644
--- a/saleor/graphql/giftcard/mutations.py
+++ b/saleor/graphql/giftcard/mutations.py
@@ -20,7 +20,7 @@ class GiftCardInput(graphene.InputObjectType):
description="End date of the gift card in ISO 8601 format."
)
balance = Decimal(description="Value of the gift card.")
- buyer_email = graphene.String(
+ user_email = graphene.String(
required=False, description="The customer's email of the gift card buyer."
)
@@ -48,10 +48,10 @@ class GiftCardCreate(ModelMutation):
if balance:
cleaned_input["current_balance"] = balance
cleaned_input["initial_balance"] = balance
- buyer_email = data.get("buyer_email", None)
- if buyer_email:
+ user_email = data.get("user_email", None)
+ if user_email:
try:
- cleaned_input["buyer"] = User.objects.get(email=buyer_email)
+ cleaned_input["user"] = User.objects.get(email=user_email)
except ObjectDoesNotExist:
raise ValidationError(
{"email": "Customer with this email doesn't exist."}
diff --git a/saleor/graphql/giftcard/resolvers.py b/saleor/graphql/giftcard/resolvers.py
index 473b9d15da..11085969dc 100644
--- a/saleor/graphql/giftcard/resolvers.py
+++ b/saleor/graphql/giftcard/resolvers.py
@@ -15,5 +15,5 @@ def resolve_gift_card(info, gift_card_global_id):
)
gift_card_id = from_global_id_strict_type(info, gift_card_global_id, GiftCard)
return get_node_optimized(
- models.GiftCard.objects, {"pk": gift_card_id, "buyer": user}, info
+ models.GiftCard.objects, {"pk": gift_card_id, "user": user}, info
)
diff --git a/saleor/graphql/giftcard/types.py b/saleor/graphql/giftcard/types.py
index 39857cd36d..5b4747b803 100644
--- a/saleor/graphql/giftcard/types.py
+++ b/saleor/graphql/giftcard/types.py
@@ -11,7 +11,7 @@ class GiftCard(CountableDjangoObjectType):
display_code = graphene.String(
description="Code in format with allows displaying in a user interface."
)
- buyer = graphene.Field(
+ user = graphene.Field(
"saleor.graphql.account.types.User",
description="The customer who bought a gift card.",
)
@@ -25,7 +25,7 @@ class GiftCard(CountableDjangoObjectType):
)
only_fields = [
"code",
- "buyer",
+ "user",
"created",
"start_date",
"end_date",
@@ -41,5 +41,5 @@ class GiftCard(CountableDjangoObjectType):
return self.display_code
@permission_required("giftcard.manage_gift_card")
- def resolve_buyer(self, _info):
- return self.buyer
+ def resolve_user(self, _info):
+ return self.user
diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.py
index 0caa260693..ff016a5935 100644
--- a/tests/api/test_gift_card.py
+++ b/tests/api/test_gift_card.py
@@ -46,7 +46,7 @@ def test_query_gift_card_with_premissions(
query giftCard($id: ID!) {
giftCard(id: $id){
code
- buyer {
+ user {
email
}
}
@@ -59,7 +59,7 @@ def test_query_gift_card_with_premissions(
content = get_graphql_content(response)
data = content["data"]["giftCard"]
assert data["code"] == gift_card.code
- assert data["buyer"]["email"] == gift_card.buyer.email
+ assert data["user"]["email"] == gift_card.user.email
def test_query_gift_card_without_premissions(
@@ -127,18 +127,18 @@ def test_query_own_gift_cards(user_api_client, gift_card, gift_card_created_by_s
CREATE_GIFT_CARD_MUTATION = """
mutation giftCardCreate(
$code: String, $startDate: Date, $endDate: Date,
- $balance: Decimal!, $buyerEmail: String) {
+ $balance: Decimal!, $userEmail: String) {
giftCardCreate(input: {
code: $code, startDate: $startDate,
endDate: $endDate,
- balance: $balance, buyerEmail: $buyerEmail }) {
+ balance: $balance, userEmail: $userEmail }) {
errors {
field
message
}
giftCard {
code
- buyer {
+ user {
email
}
created
@@ -168,7 +168,7 @@ def test_create_gift_card(staff_api_client, customer_user, permission_manage_gif
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
"balance": initial_balance,
- "buyerEmail": customer_user.email,
+ "userEmail": customer_user.email,
}
response = staff_api_client.post_graphql(
CREATE_GIFT_CARD_MUTATION, variables, permissions=[permission_manage_gift_card]
@@ -176,7 +176,7 @@ def test_create_gift_card(staff_api_client, customer_user, permission_manage_gif
content = get_graphql_content(response)
data = content["data"]["giftCardCreate"]["giftCard"]
assert data["code"] == code
- assert data["buyer"]["email"] == customer_user.email
+ assert data["user"]["email"] == customer_user.email
assert data["startDate"] == start_date.isoformat()
assert data["endDate"] == end_date.isoformat()
assert not data["lastUsedOn"]
@@ -196,7 +196,7 @@ def test_create_gift_card_with_empty_code(
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
"balance": initial_balance,
- "buyerEmail": staff_api_client.user.email,
+ "userEmail": staff_api_client.user.email,
}
response = staff_api_client.post_graphql(
CREATE_GIFT_CARD_MUTATION, variables, permissions=[permission_manage_gift_card]
@@ -214,7 +214,7 @@ def test_create_gift_card_without_code(staff_api_client, permission_manage_gift_
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
"balance": initial_balance,
- "buyerEmail": staff_api_client.user.email,
+ "userEmail": staff_api_client.user.email,
}
response = staff_api_client.post_graphql(
CREATE_GIFT_CARD_MUTATION, variables, permissions=[permission_manage_gift_card]
@@ -256,7 +256,7 @@ def test_create_gift_card_with_existing_gift_card_code(
assert errors[0]["message"] == "Gift card with this code is not avaible."
-def test_create_gift_card_without_buyer(staff_api_client, permission_manage_gift_card):
+def test_create_gift_card_without_user(staff_api_client, permission_manage_gift_card):
code = "mirumee1"
start_date = date(day=1, month=1, year=2018)
end_date = date(day=1, month=1, year=2019)
@@ -266,7 +266,7 @@ def test_create_gift_card_without_buyer(staff_api_client, permission_manage_gift
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
"balance": initial_balance,
- "buyerEmail": "",
+ "userEmail": "",
}
response = staff_api_client.post_graphql(
CREATE_GIFT_CARD_MUTATION, variables, permissions=[permission_manage_gift_card]
@@ -274,10 +274,10 @@ def test_create_gift_card_without_buyer(staff_api_client, permission_manage_gift
content = get_graphql_content(response)
data = content["data"]["giftCardCreate"]["giftCard"]
assert data["code"] == code
- assert not data["buyer"]
+ assert not data["user"]
-def test_create_gift_card_with_incorrect_buyer_email(
+def test_create_gift_card_with_incorrect_user_email(
staff_api_client, permission_manage_gift_card
):
code = "mirumee1"
@@ -289,7 +289,7 @@ def test_create_gift_card_with_incorrect_buyer_email(
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
"balance": initial_balance,
- "buyerEmail": "[email protected]",
+ "userEmail": "[email protected]",
}
response = staff_api_client.post_graphql(
CREATE_GIFT_CARD_MUTATION, variables, permissions=[permission_manage_gift_card]
@@ -312,7 +312,7 @@ def test_create_gift_card_without_premissions(staff_api_client):
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
"balance": initial_balance,
- "buyerEmail": staff_api_client.user.email,
+ "userEmail": staff_api_client.user.email,
}
response = staff_api_client.post_graphql(CREATE_GIFT_CARD_MUTATION, variables)
assert_no_permission(response)
@@ -321,10 +321,10 @@ def test_create_gift_card_without_premissions(staff_api_client):
UPDATE_GIFT_CARD_MUTATION = """
mutation giftCardUpdate(
$id: ID!, $startDate: Date, $endDate: Date,
- $balance: Decimal, $buyerEmail: String!) {
+ $balance: Decimal, $userEmail: String!) {
giftCardUpdate(id: $id, input: {startDate: $startDate,
endDate: $endDate,
- balance: $balance, buyerEmail: $buyerEmail}) {
+ balance: $balance, userEmail: $userEmail}) {
errors {
field
message
@@ -334,7 +334,7 @@ mutation giftCardUpdate(
currentBalance {
amount
}
- buyer {
+ user {
email
}
}
@@ -346,11 +346,11 @@ mutation giftCardUpdate(
def test_update_gift_card(staff_api_client, gift_card, permission_manage_gift_card):
balance = 150
assert gift_card.current_balance != balance
- assert gift_card.buyer != staff_api_client.user
+ assert gift_card.user != staff_api_client.user
variables = {
"id": graphene.Node.to_global_id("GiftCard", gift_card.id),
"balance": balance,
- "buyerEmail": staff_api_client.user.email,
+ "userEmail": staff_api_client.user.email,
}
response = staff_api_client.post_graphql(
UPDATE_GIFT_CARD_MUTATION, variables, permissions=[permission_manage_gift_card]
@@ -359,7 +359,7 @@ def test_update_gift_card(staff_api_client, gift_card, permission_manage_gift_ca
data = content["data"]["giftCardUpdate"]["giftCard"]
assert data["code"] == gift_card.code
assert data["currentBalance"]["amount"] == balance
- assert data["buyer"]["email"] == staff_api_client.user.email
+ assert data["user"]["email"] == staff_api_client.user.email
def test_update_gift_card_without_premissions(staff_api_client, gift_card):
@@ -370,7 +370,7 @@ def test_update_gift_card_without_premissions(staff_api_client, gift_card):
variables = {
"id": graphene.Node.to_global_id("GiftCard", gift_card.id),
"balance": balance,
- "buyerEmail": staff_api_client.user.email,
+ "userEmail": staff_api_client.user.email,
}
response = staff_api_client.post_graphql(UPDATE_GIFT_CARD_MUTATION, variables)
@@ -392,7 +392,7 @@ def test_update_gift_card_update_code_error(
currentBalance {
amount
}
- buyer {
+ user {
email
}
}
diff --git a/tests/conftest.py b/tests/conftest.py
index 275313a470..6bb813815b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -627,7 +627,7 @@ def order_line(order, variant, vatlayer):
def gift_card(customer_user, staff_user):
return GiftCard.objects.create(
code="mirumee_giftcard",
- buyer=customer_user,
+ user=customer_user,
initial_balance=10,
current_balance=10,
)