def test_should_query_only_fields(): ''' The feature "only_fields" is deprecated now in favor of "fields" in Types.py ''' with raises(Exception): class ProductType(DjangoObjectType): class Meta: model = Product fields = ( 'id', 'sku', 'name', 'quantity', 'price' ) schema = graphene.Schema(query=ProductType) query = """ query Product { 'id', 'sku', 'name', 'quantity', 'price' } """ result = schema.execute(query) assert not result.errors
def test_should_query_properly(): class ProductType(DjangoObjectType): class Meta: model = Product class Query(graphene.ObjectType): product = graphene.Field(ProductType) def resolve_product(self, info): return Product(sku='BLU-TOWEL-M', name='Blue Towel Medium Size') query = """ query { product { sku, name, quantity, price } } """ expected = { 'product': { 'sku': 'BLU-TOWEL-M', 'name': 'Blue Towel Medium Size', 'quantity': 0, 'price': 0 } } schema = graphene.Schema(query=Query) result = schema.execute(query) assert not result.errors assert result.data == expected
def test_users(user): query_string = ''' query getUserInfo { allUsers { edges { node { annotations { edges { node { text } } } } } } } ''' response = schema.execute(query_string, op_name='getUserInfo') assert not response.errors first_node = get_nth_node(response.data['allUsers']) first_annotation = get_nth_node(first_node['annotations']) assert first_annotation['text'] == user.annotations.all()[0].text
async def ping(request): # pylint: disable=unused-variable """ Ping function checks if Ax is running. Used with monit """ del request from backend.schema import schema result = schema.execute("query { ping }") test_str = json.dumps(result.data, sort_keys=True, indent=4) return response.text(test_str)
def test_user_no_password(user): query_string = ''' query getUserInfo { allUsers { edges { node { password } } } } ''' response = schema.execute(query_string, op_name='getUserInfo') assert response.errors assert response.errors[ 0].message == 'Cannot query field "password" on type "UserNode".'
def test_foods(food): query_string = ''' query getFoodInfo { allFoods { edges { node { name } } } } ''' response = schema.execute(query_string, op_name='getFoodInfo') assert not response.errors first_node = get_nth_node(response.data['allFoods']) assert first_node['name'] == food.name
def test_images(image): query_string = ''' query getImageInfo { allImages { edges { node { filesize } } } } ''' response = schema.execute(query_string, op_name='getImageInfo') assert not response.errors first_node = get_nth_node(response.data['allImages']) assert first_node['filesize'] == image.filesize
def test_create_image(user): query_string = ''' mutation ($someFile: Upload!){ createImage(picture: $someFile, longitude:10, latitude:30) { image { id filesize cloudUrl } } } ''' variable_files = {'someFile': open("TODO.txt")} response = schema.execute(query_string, op_name='createImage', variables=variable_files) assert not response.errors assert response.data['createImage']['image']['filesize'] == 50
def test_user_no_base_access(user): query_string = ''' query getUserInfo { allUsers { edges { node { user { id } } } } } ''' response = schema.execute(query_string, op_name='getUserInfo') assert response.errors message = response.errors[0].message assert message == 'Cannot query field "user" on type "UserNode".'