本文整理汇总了Python中assembl.graphql.schema.Schema类的典型用法代码示例。如果您正苦于以下问题:Python Schema类的具体用法?Python Schema怎么用?Python Schema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mutation_delete_template_also_deletes_associated_vote_specifications
def test_mutation_delete_template_also_deletes_associated_vote_specifications(graphql_request, vote_session, vote_proposal, graphql_registry, test_session):
mutation = graphql_registry['createTokenVoteSpecification']
vote_session_id = to_global_id("VoteSession", vote_session.id)
from assembl.graphql.schema import Schema as schema
res = schema.execute(mutation, context_value=graphql_request, variable_values={
"voteSessionId": vote_session_id,
"titleEntries": [],
"instructionsEntries":
[
{"value": u"Try to copy the TCP feed, maybe it will navigate the mobile system!", "localeCode": "en"}
],
"isCustom": False,
"exclusiveCategories": False,
"tokenCategories": [
{
"titleEntries": [{"value": u"In favor", "localeCode": "en"}],
"typename": "positive",
"totalNumber": 9,
"color": 'green'
}
]
})
assert res.errors is None
template_id = res.data['createTokenVoteSpecification']['voteSpecification']['id']
proposal_id = to_global_id("Idea", vote_proposal.id)
res = schema.execute(mutation, context_value=graphql_request, variable_values={
"voteSessionId": vote_session_id,
"proposalId": proposal_id,
"voteSpecTemplateId": template_id,
"titleEntries": [],
"instructionsEntries":
[
{"value": u"I'll compress the multi-byte THX protocol, that should panel the SDD monitor!", "localeCode": "en"}
],
"isCustom": True,
"exclusiveCategories": False,
"tokenCategories": []
})
assert res.errors is None
# delete the template
mutation = graphql_registry['deleteVoteSpecification']
vote_spec_id = res.data['createTokenVoteSpecification']['voteSpecification']['id']
res = schema.execute(mutation, context_value=graphql_request, variable_values={
"id": template_id
})
assert res.errors is None
assert res.data['deleteVoteSpecification']['success'] is True
# the template and the vote spec have been deleted
assert test_session.query(models.TokenVoteSpecification).count() == 0
示例2: thematic_with_image
def thematic_with_image(phases, graphql_request):
from assembl.graphql.schema import Schema as schema
import os
from io import BytesIO
class FieldStorage(object):
file = BytesIO(os.urandom(16))
filename = u'path/to/image.png'
type = 'image/png'
graphql_request.POST['variables.file'] = FieldStorage()
res = schema.execute(u"""
mutation createThematicWithImage($file: String!) {
createThematic(
messageViewOverride: "survey",
titleEntries:[
{value:"You can't program the card without transmitting the wireless AGP card!", localeCode:"en"}
],
discussionPhaseId: """+unicode(phases['survey'].id)+u""",
image: $file
) {
thematic {
... on Idea {
id,
img { externalUrl }
}
}
}
}
""", context_value=graphql_request, variable_values={ "file": "variables.file" })
thematic_id = res.data['createThematic']['thematic']['id']
return thematic_id
示例3: number_gauge_vote_specification_associated_to_proposal
def number_gauge_vote_specification_associated_to_proposal(request, test_session, discussion, graphql_request, vote_session, number_gauge_vote_specification, vote_proposal, graphql_registry):
mutation = graphql_registry['createNumberGaugeVoteSpecification']
vote_session_id = to_global_id("VoteSession", vote_session.id)
proposal_id = to_global_id("Idea", vote_proposal.id)
template_gauge_vote_spec_id = to_global_id("NumberGaugeVoteSpecification", number_gauge_vote_specification.id)
from assembl.graphql.schema import Schema as schema
res = schema.execute(mutation, context_value=graphql_request, variable_values={
"voteSessionId": vote_session_id,
"proposalId": proposal_id,
"voteSpecTemplateId": template_gauge_vote_spec_id,
"titleEntries": [
{"value": u"Comprendre les dynamiques et les enjeux", "localeCode": "fr"},
{"value": u"Understanding the dynamics and issues", "localeCode": "en"}
],
"instructionsEntries":
[
{"value": u"Instructions : Comprendre les dynamiques et les enjeux", "localeCode": "fr"},
{"value": u"Instructions: Understanding the dynamics and issues", "localeCode": "en"}
],
"isCustom": True,
"minimum": 0.0,
"maximum": 60.0,
"nbTicks": 7,
"unit": u"M€"
})
assert res.errors is None
vote_spec = vote_session.vote_specifications[-1]
def fin():
print "finalizer number_gauge_vote_specification_associated_to_proposal"
test_session.delete(vote_spec)
test_session.flush()
request.addfinalizer(fin)
return vote_spec
示例4: vote_proposal
def vote_proposal(request, test_session, discussion, graphql_request, vote_session, graphql_registry):
mutation = graphql_registry['createProposal']
vote_session_id = to_global_id("VoteSession", vote_session.id)
from assembl.graphql.schema import Schema as schema
res = schema.execute(mutation, context_value=graphql_request, variable_values={
"voteSessionId": vote_session_id,
"titleEntries": [
{"value": u"Comprendre les dynamiques et les enjeux", "localeCode": "fr"},
{"value": u"Understanding the dynamics and issues", "localeCode": "en"}
],
"descriptionEntries": [
{"value": u"Description: Comprendre les dynamiques et les enjeux", "localeCode": "fr"},
{"value": u"Description: Understanding the dynamics and issues", "localeCode": "en"}
]
})
assert res.errors is None
proposal = vote_session.idea.children[0]
def fin():
print "finalizer vote_proposal"
test_session.delete(proposal)
test_session.flush()
request.addfinalizer(fin)
return proposal
示例5: create_proposal_x
def create_proposal_x(graphql_request, first_question_id, idx, publication_state):
from assembl.graphql.schema import Schema as schema
from assembl.models import PublicationStates
body = "une proposition {}".format(idx)
if publication_state == PublicationStates.SUBMITTED_AWAITING_MODERATION.value:
body = "une proposition en attente de validation {}".format(idx)
res = schema.execute(u"""
mutation myFirstMutation {
createPost(
ideaId:"%s",
body:"%s"
publicationState:%s
) {
post {
... on Post {
id,
body,
creator { name },
}
}
}
}
""" % (first_question_id, body, publication_state),
context_value=graphql_request)
return res.data['createPost']['post']['id']
示例6: test_mutation_add_extracts
def test_mutation_add_extracts(graphql_request, top_post_in_thread_phase):
post_db_id = int(from_global_id(top_post_in_thread_phase)[1])
extract_body = u"manger des choux à la crème"
xpathStart = u"//div[@id='message-body-local:Content/%s']/" % post_db_id
xpathEnd = xpathStart
offsetStart = 17
offsetEnd = 44
variable_values = {
"extracts": [
{
"postId": top_post_in_thread_phase,
"body": extract_body,
"xpathStart": xpathStart,
"xpathEnd": xpathEnd,
"offsetStart": offsetStart,
"offsetEnd": offsetEnd,
"lang": "fr"
}
],
"extractState": "SUBMITTED",
"extractNature": "actionable_solution"
}
post = models.AssemblPost.get(post_db_id)
db = post.db
def get_extracts():
return db.query(
models.Extract
).join(
models.Content, models.Extract.content == post
).options(joinedload(models.Extract.text_fragment_identifiers)).all()
assert len(get_extracts()) == 0
res = schema.execute(u"""
mutation AddPostsExtract($extracts: [PostExtractEntryInput]!, $extractState: ExtractStates, $extractNature: ExtractNatures) {
addPostsExtract(extracts: $extracts, extractState: $extractState, extractNature: $extractNature) {
status
}
}
""", context_value=graphql_request, variable_values=variable_values)
assert json.loads(json.dumps(res.data)) == {
u'addPostsExtract': {
u'status': True
}
}
assert len(get_extracts()) == 1
# add the same extract
res = schema.execute(u"""
mutation AddPostsExtract($extracts: [PostExtractEntryInput]!, $extractState: ExtractStates, $extractNature: ExtractNatures) {
addPostsExtract(extracts: $extracts, extractState: $extractState, extractNature: $extractNature) {
status
}
}
""", context_value=graphql_request, variable_values=variable_values)
# The extract must be ignored
assert len(get_extracts()) == 1
示例7: test_delete_resource
def test_delete_resource(graphql_registry, graphql_request, resource):
resource_id = to_global_id('Resource', resource.id)
res = schema.execute(
graphql_registry['deleteResource'],
variable_values={
"resourceId": resource_id
},
context_value=graphql_request)
assert res.data['deleteResource']['success'] is True
res = schema.execute(
u'query { resources { id } }', context_value=graphql_request)
assert json.loads(json.dumps(res.data)) == {u'resources': []}
示例8: test_query_associate_vote_spec_to_proposal
def test_query_associate_vote_spec_to_proposal(graphql_request, timeline_vote_session, vote_session, vote_proposal, token_vote_specification, graphql_registry):
mutation = graphql_registry['createTokenVoteSpecification']
vote_session_id = to_global_id("VoteSession", vote_session.id)
proposal_id = to_global_id("Idea", vote_proposal.id)
# token vote spec similar to token_vote_specification fixture, but with exclusiveCategories set to False
template_token_vote_spec_id = to_global_id("TokenVoteSpecification", token_vote_specification.id)
res = schema.execute(mutation, context_value=graphql_request, variable_values={
"voteSessionId": vote_session_id,
"proposalId": proposal_id,
"voteSpecTemplateId": template_token_vote_spec_id,
"titleEntries": [
{"value": u"Comprendre les dynamiques et les enjeux", "localeCode": "fr"},
{"value": u"Understanding the dynamics and issues", "localeCode": "en"}
],
"instructionsEntries":
[
{"value": u"Comprendre les dynamiques et les enjeux", "localeCode": "fr"},
{"value": u"Understanding the dynamics and issues", "localeCode": "en"}
],
"isCustom": True,
"exclusiveCategories": False,
"tokenCategories": [
{"titleEntries": [
{"value": u"Comprendre les dynamiques et les enjeux", "localeCode": "fr"},
{"value": u"Understanding the dynamics and issues", "localeCode": "en"}
],
"typename": "positive",
"totalNumber": 10,
"color": 'red'
}
]
})
query = graphql_registry['VoteSession']
res = schema.execute(query, context_value=graphql_request, variable_values={
"ideaId": to_global_id('Idea',vote_session.idea_id),
"lang": "en"
})
assert res.errors is None
proposal_id = to_global_id("Idea", vote_proposal.id)
assert len(res.data['voteSession']['modules']) == 1 # only vote spec not associated to a proposal
assert res.data['voteSession']['modules'][0]['exclusiveCategories'] == True
assert len(res.data['voteSession']['proposals'][0]['modules']) == 1
assert res.data['voteSession']['proposals'][0]['modules'][0]['exclusiveCategories'] == False
assert res.data['voteSession']['proposals'][0]['modules'][0]['voteSpecTemplateId'] == template_token_vote_spec_id
assert res.data['voteSession']['proposals'][0]['modules'][0]['isCustom'] is True
# clean up
vote_session.vote_specifications[-1].delete()
vote_session.db.flush()
示例9: test_query_tags
def test_query_tags(graphql_request, extract_post_1_to_subidea_1_1):
variable_values = {
"filter": ''
}
res = schema.execute(u"""
query tags($filter: String) {
tags(filter: $filter) {
value
}
}
""", context_value=graphql_request, variable_values=variable_values)
assert json.loads(json.dumps(res.data)) == {
u'tags': [{u'value': u'foo'}, {u'value': u'bar'}]
}
variable_values = {
"filter": 'f'
}
res = schema.execute(u"""
query tags($filter: String) {
tags(filter: $filter) {
value
}
}
""", context_value=graphql_request, variable_values=variable_values)
assert json.loads(json.dumps(res.data)) == {
u'tags': [{u'value': u'foo'}]
}
variable_values = {
"filter": 'test'
}
res = schema.execute(u"""
query tags($filter: String) {
tags(filter: $filter) {
value
}
}
""", context_value=graphql_request, variable_values=variable_values)
assert json.loads(json.dumps(res.data)) == {
u'tags': []
}
示例10: test_mutation_update_text_field
def test_mutation_update_text_field(graphql_request, graphql_registry, text_field):
text_field_id = to_global_id('TextField', text_field.id)
res = schema.execute(
graphql_registry['updateTextField'],
context_value=graphql_request,
variable_values={
"id": text_field_id,
"lang": u"en",
"titleEntries": [
{ "localeCode": "en", "value": u"My new title" },
{ "localeCode": "be", "value": u"Mon nouveau titre" },
],
"order": 8.0,
"required": False,
"hidden": False
})
assert res.errors is None
assert 'updateTextField' in res.data
field = res.data['updateTextField']['field']
assert field[u'required'] is False
assert field[u'hidden'] is False
assert field[u'order'] == 8.0
title_entries = field['titleEntries']
assert title_entries[0]['localeCode'] == u'be'
assert title_entries[0]['value'] == u'Mon nouveau titre'
assert title_entries[1]['localeCode'] == u'en'
assert title_entries[1]['value'] == u'My new title'
示例11: test_mutation_create_text_field
def test_mutation_create_text_field(graphql_request, graphql_registry, test_session):
from assembl.models.configurable_fields import TextField
res = schema.execute(
graphql_registry['createTextField'],
context_value=graphql_request,
variable_values={
"lang": u"en",
"titleEntries": [
{ "localeCode": "en", "value": u"My new field" }
],
"order": 4.0,
"required": False,
"hidden": False
})
assert res.errors is None
assert 'createTextField' in res.data
new_field = res.data['createTextField']['field']
assert new_field[u'required'] is False
assert new_field[u'hidden'] is False
assert new_field[u'order'] == 4.0
title_entries = new_field['titleEntries']
assert title_entries[0]['localeCode'] == u'en'
assert title_entries[0]['value'] == u'My new field'
saobj = TextField.get(from_global_id(new_field[u'id'])[1])
test_session.delete(saobj)
示例12: test_query_landing_page_module_types
def test_query_landing_page_module_types(graphql_request):
query = u"""query LandingPageModuleTypes($lang: String!) {
landingPageModuleTypes {
titleEntries {
localeCode
value
}
title(lang: $lang)
defaultOrder
editableOrder
identifier
required
}
}
"""
res = schema.execute(
query,
context_value=graphql_request,
variable_values={"lang": u"en"})
assert res.errors is None
assert len(res.data['landingPageModuleTypes']) == MODULES_COUNT
for module_type in res.data['landingPageModuleTypes']:
if module_type['identifier'] == 'INTRODUCTION':
assert module_type['title'] == u'Text & Multimedia'
assert module_type['defaultOrder'] == 2.0
assert module_type['editableOrder'] is True
assert module_type['required'] is False
示例13: test_query_vote_session_proposals
def test_query_vote_session_proposals(graphql_request, timeline_vote_session, vote_session, vote_proposal, graphql_registry):
query = graphql_registry['VoteSession']
res = schema.execute(query, context_value=graphql_request, variable_values={
"ideaId": to_global_id('Idea', vote_session.idea_id),
"lang": "en"
})
assert res.errors is None
proposal_id = to_global_id("Idea", vote_proposal.id)
assert json.loads(json.dumps(res.data['voteSession']['proposals'])) == [{
u'id': proposal_id,
u'order': 1.0,
u'title': u'Understanding the dynamics and issues',
u'description': u'Description: Understanding the dynamics and issues',
u'titleEntries': [
{u'localeCode': u'en',
u'value': u'Understanding the dynamics and issues'},
{u'localeCode': u'fr',
u'value': u'Comprendre les dynamiques et les enjeux'}],
u'descriptionEntries': [
{u'localeCode': u'en',
u'value': u'Description: Understanding the dynamics and issues'},
{u'localeCode': u'fr',
u'value': u'Description: Comprendre les dynamiques et les enjeux'}],
u'modules': [],
u'voteResults': {u'numParticipants': 0, u'participants': []}
}]
示例14: test_graphql_get_profile
def test_graphql_get_profile(graphql_request, participant1_user):
res = schema.execute(u"""
query User($id: ID!) {
user: node(id: $id) {
... on AgentProfile {
id
name
username
displayName
email
creationDate
image { externalUrl }
hasPassword
}
}
}
""", context_value=graphql_request, variable_values={
"id": to_global_id('AgentProfile', participant1_user.id)
})
assert res.errors is None
assert res.data['user']['name'] == u'A. Barking Loon'
assert res.data['user']['username'] is None
assert res.data['user']['displayName'] == u'A. Barking Loon'
assert res.data['user']['email'] == u'[email protected]'
# 2018-01-04T12:08:44.735489+00:00
assert u'T' in res.data['user']['creationDate']
assert res.data['user']['image'] is None
assert res.data['user']['hasPassword']
示例15: test_query_resources
def test_query_resources(graphql_registry, discussion, resource, resource_with_image_and_doc, graphql_request):
res = schema.execute(
graphql_registry['ResourcesQuery'],
variable_values={
"lang": u"en"
},
context_value=graphql_request)
assert res.data['resources'][0]['order'] == 1.0
assert res.data['resources'][1]['order'] == 2.0
first_resource = res.data['resources'][0]
second_resource = res.data['resources'][1]
assert first_resource['title'] == u'another resource'
assert second_resource['title'] == u'a resource'
assert second_resource['text'] == u'Lorem ipsum dolor sit amet'
assert second_resource['embedCode'] == u'<iframe ...>'
assert second_resource['doc'] == None
assert second_resource['image'] == None
assert '/documents/' in first_resource['image']['externalUrl']
assert '/documents/' in first_resource['doc']['externalUrl']
# this is the title of the File object, not the title of the ResourceAttachment object
assert first_resource['doc']['title'] == "mydocument.pdf"