Skip to content

Commit c75f6b1

Browse files
committed
Update API to handle nationality and departure city
1 parent 8152d53 commit c75f6b1

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

backend/api/grants/mutations.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class _GrantErrors:
4545
why: list[str] = strawberry.field(default_factory=list)
4646
notes: list[str] = strawberry.field(default_factory=list)
4747
travelling_from: list[str] = strawberry.field(default_factory=list)
48+
nationality: list[str] = strawberry.field(default_factory=list)
49+
departure_city: list[str] = strawberry.field(default_factory=list)
4850
non_field_errors: list[str] = strawberry.field(default_factory=list)
4951
participant_bio: list[str] = strawberry.field(default_factory=list)
5052
participant_website: list[str] = strawberry.field(default_factory=list)
@@ -68,11 +70,11 @@ def validate(self, conference: Conference, user: User) -> GrantErrors:
6870
errors.add_error("non_field_errors", "The grants form is not open!")
6971

7072
max_length_fields = {
71-
"name": 300,
7273
"full_name": 300,
73-
"travelling_from": 200,
74-
"twitter_handle": 15,
75-
"github_handle": 39,
74+
"name": 300,
75+
"travelling_from": 100,
76+
"nationality": 100,
77+
"departure_city": 100,
7678
}
7779
for field, max_length in max_length_fields.items():
7880
value = getattr(self, field, "")
@@ -119,6 +121,8 @@ class SendGrantInput(BaseGrantInput):
119121
why: str
120122
notes: str
121123
travelling_from: str
124+
nationality: str
125+
departure_city: str
122126

123127
participant_bio: str
124128
participant_website: str
@@ -156,6 +160,8 @@ class UpdateGrantInput(BaseGrantInput):
156160
why: str
157161
notes: str
158162
travelling_from: str
163+
nationality: str
164+
departure_city: str
159165

160166
participant_bio: str
161167
participant_website: str
@@ -234,6 +240,8 @@ def send_grant(self, info: Info, input: SendGrantInput) -> SendGrantResult:
234240
"why": input.why,
235241
"notes": input.notes,
236242
"travelling_from": input.travelling_from,
243+
"nationality": input.nationality,
244+
"departure_city": input.departure_city,
237245
}
238246
)
239247

backend/api/grants/tests/test_send_grant.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def _send_grant(client, conference, conference_code=None, **kwargs):
3939
validationWhy: why
4040
validationNotes: notes
4141
validationTravellingFrom: travellingFrom
42+
validationNationality: nationality
43+
validationDepartureCity: departureCity
4244
validationParticipantBio: participantBio
4345
validationParticipantWebsite: participantWebsite
4446
validationParticipantTwitterHandle: participantTwitterHandle
@@ -70,6 +72,8 @@ def _send_grant(client, conference, conference_code=None, **kwargs):
7072
"why": grant.why,
7173
"notes": grant.notes,
7274
"travellingFrom": grant.travelling_from,
75+
"nationality": grant.nationality,
76+
"departureCity": grant.departure_city,
7377
"participantBio": "my bio",
7478
"participantWebsite": "http://website.it",
7579
"participantTwitterHandle": "handle",
@@ -215,14 +219,22 @@ def test_cannot_send_grant_outside_allowed_values(
215219
conference,
216220
name="Marcotte" * 50,
217221
travellingFrom="Very long location" * 50,
222+
nationality="Freedonia" * 50,
223+
departureCity="Emerald City " * 50,
218224
)
219225

220226
assert response["data"]["sendGrant"]["__typename"] == "GrantErrors"
221227
assert response["data"]["sendGrant"]["errors"]["validationName"] == [
222228
"name: Cannot be more than 300 chars"
223229
]
224230
assert response["data"]["sendGrant"]["errors"]["validationTravellingFrom"] == [
225-
"travelling_from: Cannot be more than 200 chars"
231+
"travelling_from: Cannot be more than 100 chars"
232+
]
233+
assert response["data"]["sendGrant"]["errors"]["validationNationality"] == [
234+
"nationality: Cannot be more than 100 chars"
235+
]
236+
assert response["data"]["sendGrant"]["errors"]["validationDepartureCity"] == [
237+
"departure_city: Cannot be more than 100 chars"
226238
]
227239

228240

backend/api/grants/tests/test_update_grant.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def _update_grant(graphql_client, grant, **kwargs):
3535
validationWhy: why
3636
validationNotes: notes
3737
validationTravellingFrom: travellingFrom
38+
validationNationality: nationality
39+
validationDepartureCity: departureCity
3840
validationParticipantBio: participantBio
3941
validationParticipantWebsite: participantWebsite
4042
validationParticipantTwitterHandle: participantTwitterHandle
@@ -66,6 +68,8 @@ def _update_grant(graphql_client, grant, **kwargs):
6668
"why": grant.why,
6769
"notes": grant.notes,
6870
"travellingFrom": grant.travelling_from,
71+
"nationality": grant.nationality,
72+
"departureCity": grant.departure_city,
6973
"participantBio": "bio",
7074
"participantWebsite": "http://website.it",
7175
"participantTwitterHandle": "handle",
@@ -110,6 +114,8 @@ def test_update_grant(graphql_client, user):
110114
why="why not",
111115
notes="🧸",
112116
travellingFrom="GB",
117+
nationality="Italian",
118+
departureCity="Rome",
113119
participantFacebookUrl="http://facebook.com/pythonpizza",
114120
participantLinkedinUrl="http://linkedin.com/company/pythonpizza",
115121
)
@@ -206,12 +212,20 @@ def test_cannot_update_submission_with_lang_outside_allowed_values(
206212
grant=grant,
207213
name="Marcotte" * 50,
208214
travellingFrom="Very long location" * 50,
215+
nationality="Freedonia" * 50,
216+
departureCity="Emerald City " * 50,
209217
)
210218

211219
assert response["data"]["updateGrant"]["__typename"] == "GrantErrors"
212220
assert response["data"]["updateGrant"]["errors"]["validationName"] == [
213221
"name: Cannot be more than 300 chars"
214222
]
215223
assert response["data"]["updateGrant"]["errors"]["validationTravellingFrom"] == [
216-
"travelling_from: Cannot be more than 200 chars"
224+
"travelling_from: Cannot be more than 100 chars"
225+
]
226+
assert response["data"]["updateGrant"]["errors"]["validationNationality"] == [
227+
"nationality: Cannot be more than 100 chars"
228+
]
229+
assert response["data"]["updateGrant"]["errors"]["validationDepartureCity"] == [
230+
"departure_city: Cannot be more than 100 chars"
217231
]

backend/api/grants/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Grant:
3232
why: str
3333
notes: str
3434
travelling_from: Optional[str]
35+
nationality: Optional[str]
36+
departure_city: Optional[str]
3537
applicant_reply_deadline: Optional[datetime]
3638

3739
@classmethod
@@ -54,5 +56,7 @@ def from_model(cls, grant: GrantModel) -> Grant:
5456
why=grant.why,
5557
notes=grant.notes,
5658
travelling_from=grant.travelling_from,
59+
nationality=grant.nationality,
60+
departure_city=grant.departure_city,
5761
applicant_reply_deadline=grant.applicant_reply_deadline,
5862
)

backend/grants/tests/factories.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Meta:
3131
why = factory.Faker("text")
3232
notes = factory.Faker("text")
3333
travelling_from = factory.fuzzy.FuzzyChoice([country.code for country in countries])
34+
nationality = factory.Faker("country")
35+
departure_city = factory.Faker("city")
3436
website = factory.Faker("url")
3537
twitter_handle = "@handle"
3638
github_handle = factory.Faker("user_name")

0 commit comments

Comments
 (0)