Skip to content

Commit 04a013b

Browse files
committed
add tests to author name and email
1 parent 713d90e commit 04a013b

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

sowing/models_graphql.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Sowing(DjangoObjectType, DocumentBase):
1919
author = graphene.Field(User)
2020
species = DjangoConnectionField(lambda: LifeNode)
2121
images = DjangoConnectionField(lambda: Image)
22+
authorName = graphene.String()
23+
authorEmail = graphene.String()
2224

2325
class Meta:
2426
model = SowingModel
@@ -44,6 +46,12 @@ def resolve_species(self, info, **kwargs):
4446
return LifeNode._meta.model.objects.filter(
4547
document__sowing_species=self)
4648

49+
def resolve_authorName(self, info):
50+
return getattr(self, 'author_name', None)
51+
52+
def resolve_authorEmail(self, info):
53+
return getattr(self, 'author_email', None)
54+
4755

4856
class BoundBoxFilter(django_filters.CharFilter):
4957
description = "4 numbers separated by comma that represents a polygon object from the given bounding-box, e.g.: xmin,ymin,xmax,ymax)"
@@ -61,4 +69,3 @@ class SowingFilter(django_filters.FilterSet):
6169
class Meta:
6270
model = SowingModel
6371
fields = ['author']
64-

sowing/tests.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,69 @@ def test_create_sowing(self):
116116
}
117117
self.assertEqual(response.json(), expected)
118118

119+
def test_create_sowing_guest_with_name_email(self):
120+
# ensure we are logged out for a guest submission
121+
self.client.logout()
122+
123+
with open('public/default_user_avatar.jpg', 'rb') as image1:
124+
response = self.graphql({
125+
'query': """
126+
mutation M($input_0: SowingCreateInput!) {
127+
sowingCreate(input: $input_0) {
128+
clientMutationId,
129+
sowing {
130+
node {
131+
id
132+
where
133+
notes
134+
author { username }
135+
authorName
136+
authorEmail
137+
images { edges { node { id } } }
138+
}
139+
}
140+
errors { code location message }
141+
}
142+
}
143+
""",
144+
'variables': {
145+
'input_0': {
146+
'clientMutationId': '1',
147+
'where': 'bairro central',
148+
'notes': 'semeadura comunitária',
149+
'species': [self.species['id']],
150+
'name': 'Convidado',
151+
'email': 'convidado@example.com',
152+
}
153+
},
154+
'images': [image1],
155+
}, content_type=MULTIPART_CONTENT)
156+
157+
sowing = response.json()['data']['sowingCreate']['sowing']['node']
158+
159+
expected = {
160+
'data': {
161+
'sowingCreate': {
162+
'sowing': {
163+
'node': {
164+
'id': sowing['id'],
165+
'where': 'bairro central',
166+
'notes': 'semeadura comunitária',
167+
'author': None,
168+
'authorName': 'Convidado',
169+
'authorEmail': 'convidado@example.com',
170+
'images': {
171+
'edges': [sowing['images']['edges'][0]],
172+
},
173+
}
174+
},
175+
'clientMutationId': '1',
176+
'errors': None,
177+
}
178+
}
179+
}
180+
self.assertEqual(response.json(), expected)
181+
119182
def _do_create_life_node(self, client, node):
120183
return self.graphql({
121184
'query': """

0 commit comments

Comments
 (0)