Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
voucher {
code
discountValueType
applyOncePerOrder
minCheckoutItemsQuantity
}
}
}
"""
apply_once_per_order = not voucher.apply_once_per_order
# Set discount value type to 'fixed' and change it in mutation
voucher.discount_value_type = DiscountValueType.FIXED
voucher.save()
assert voucher.code != "testcode123"
variables = {
"id": graphene.Node.to_global_id("Voucher", voucher.id),
"code": "testcode123",
"discountValueType": DiscountValueTypeEnum.PERCENTAGE.name,
"applyOncePerOrder": apply_once_per_order,
"minCheckoutItemsQuantity": 10,
}
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_discounts]
)
content = get_graphql_content(response)
data = content["data"]["voucherUpdate"]["voucher"]
assert data["code"] == "testcode123"
assert data["discountValueType"] == DiscountValueType.PERCENTAGE.upper()
assert data["applyOncePerOrder"] == apply_once_per_order
assert data["minCheckoutItemsQuantity"] == 10
}
stop {
amount
}
}
margin {
start
stop
}
}
}
}
}
}
""" % {
"category_id": graphene.Node.to_global_id("Category", category.id)
}
staff_api_client.user.user_permissions.add(permission_manage_products)
response = staff_api_client.post_graphql(query)
content = get_graphql_content(response)
assert content["data"]["category"] is not None
product_edges_data = content["data"]["category"]["products"]["edges"]
assert len(product_edges_data) == category.products.count()
product_data = product_edges_data[0]["node"]
assert product_data["name"] == product.name
assert product_data["url"] == product.get_absolute_url()
assert product_data["slug"] == product.get_slug()
gross = product_data["pricing"]["priceRange"]["start"]["gross"]
assert float(gross["amount"]) == float(product.price.amount)
from saleor.product.utils.costs import get_product_costs_data
purchase_cost, margin = get_product_costs_data(product)
def test_homepage_collection_update(
staff_api_client, collection, permission_manage_settings
):
query = """
mutation homepageCollectionUpdate($collection: ID!) {
homepageCollectionUpdate(collection: $collection) {
shop {
homepageCollection {
id,
name
}
}
}
}
"""
collection_id = graphene.Node.to_global_id("Collection", collection.id)
variables = {"collection": collection_id}
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_settings]
)
content = get_graphql_content(response)
data = content["data"]["homepageCollectionUpdate"]["shop"]
assert data["homepageCollection"]["id"] == collection_id
assert data["homepageCollection"]["name"] == collection.name
site = Site.objects.get_current()
assert site.settings.homepage_collection == collection
def test_clear_silently_metadata_from_nonexistent_client(
staff_api_client, permission_manage_users, customer_with_meta
):
user_id = graphene.Node.to_global_id("User", customer_with_meta.id)
WRONG_CLIENT = "WONG"
variables = {
"id": user_id,
"input": {
"namespace": PUBLIC_META_NAMESPACE,
"clientName": WRONG_CLIENT,
"key": PUBLIC_KEY,
},
}
response = staff_api_client.post_graphql(CLEAR_METADATA_MUTATION, variables)
meta = get_graphql_content(response)["data"]["userClearStoredMetadata"]["user"][
"meta"
][0]
assert meta["namespace"] == PUBLIC_META_NAMESPACE
assert meta["clients"] == [
def test_query_gift_card_with_premissions(
staff_api_client, gift_card, permission_manage_gift_card
):
query = """
query giftCard($id: ID!) {
giftCard(id: $id){
id
displayCode
user {
email
}
}
}
"""
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)
variables = {"id": gift_card_id}
staff_api_client.user.user_permissions.add(permission_manage_gift_card)
response = staff_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["giftCard"]
assert data["id"] == gift_card_id
assert data["displayCode"] == gift_card.display_code
assert data["user"]["email"] == gift_card.user.email
class Planet(DjangoObjectType):
'''A large mass, planet or planetoid in the Star Wars Universe,
at the time of 0 ABY.'''
climates = graphene.List(graphene.String)
terrains = graphene.List(graphene.String)
def resolve_climates(self, info):
return [c.strip() for c in self.climate.split(',')]
def resolve_terrains(self, info):
return [c.strip() for c in self.terrain.split(',')]
class Meta:
model = models.Planet
interfaces = (Node, )
exclude_fields = ('created', 'edited', 'climate', 'terrain')
filter_fields = ('name', )
connection_class = Connection
class Film(DjangoObjectType):
'''A single film.'''
producers = graphene.List(graphene.String)
def resolve_producers(self, info):
return [c.strip() for c in self.producer.split(',')]
class Meta:
model = models.Film
interfaces = (Node, )
exclude_fields = ('created', 'edited', 'producer')
filter_fields = {'name': {'startswith', 'contains'}}
connection_class = Connection
class Query(graphene.ObjectType):
all_films = DjangoFilterConnectionField(Film)
all_species = DjangoFilterConnectionField(Specie)
all_characters = DjangoFilterConnectionField(Person)
all_vehicles = DjangoFilterConnectionField(Vehicle)
all_planets = DjangoFilterConnectionField(Planet)
all_starships = DjangoFilterConnectionField(Starship)
all_heroes = DjangoFilterConnectionField(Hero)
film = Node.Field(Film)
specie = Node.Field(Specie)
character = Node.Field(Person)
vehicle = Node.Field(Vehicle)
planet = Node.Field(Planet)
starship = Node.Field(Starship)
hero = Node.Field(Hero)
node = Node.Field()
viewer = graphene.Field(lambda: Query)
debug = graphene.Field(DjangoDebug, name='__debug')
def resolve_viewer(self, info):
return self
class CreateHero(graphene.ClientIDMutation):
class Input:
name = graphene.String(required=True)
from graphene import AbstractType, Field, Node, ClientIDMutation, AbstractType
from graphene import ID, Boolean, Float, Int, List, String
from graphql_relay.node.node import from_global_id
from .custom_filter_fields import date_types, string_types, number_types
from .helper_methods import not_none, set_and_save
from virtualization.models import ClusterType, ClusterGroup, Cluster, VirtualMachine
from tenancy.models import Tenant
from dcim.models import Site, Interface, Platform, DeviceRole
from ipam.models import IPAddress
# Nodes
class ClusterTypeNode(DjangoObjectType):
class Meta:
model = ClusterType
interfaces = (Node, )
filter_fields = {
'id': ['exact'],
'name': string_types,
'slug': ['exact'],
}
class ClusterGroupNode(DjangoObjectType):
class Meta:
model = ClusterGroup
interfaces = (Node, )
filter_fields = {
'id': ['exact'],
'name': string_types,
'slug': ['exact'],
}
from graphene_django import DjangoObjectType
from graphene_django.filter.fields import DjangoFilterConnectionField
from graphene import Schema, Node, ObjectType
from core.models import Event
class EventNode(DjangoObjectType):
class Meta:
model = Event
interfaces = (Node, )
filter_fields = {
"start_time": ["gte"],
"end_time": ["lt"],
}
class Query(ObjectType):
event = Node.Field(EventNode)
all_events = DjangoFilterConnectionField(EventNode)
schema = Schema(query=Query)
**kwargs) -> Promise[List[Passage]]:
return info.context.loaders.passage_from_pov_character.load(root.id)
@classmethod
def is_type_of(cls, root: Any, info: graphene.ResolveInfo) -> bool:
return isinstance(root, Character)
@classmethod
def get_node(cls, info: graphene.ResolveInfo, decoded_id: str) -> Promise[Optional[Character]]:
key = int(decoded_id)
return info.context.loaders.character.load(key)
class Query(graphene.ObjectType):
node = graphene.Node.Field()