-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for whatsapp in SecretSanta
- Loading branch information
Showing
4 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ def setUp(self): | |
"participants": [ | ||
{"name": "First Name", "email": "[email protected]"}, | ||
{"name": "Second Name", "email": "[email protected]"}, | ||
{"name": "Third Name", "email": "[email protected]"}, | ||
{"name": "Third Name", "phone_number": "+34123456789"}, | ||
], | ||
} | ||
boto_patcher = mock.patch("eas.api.amazonsqs.boto3") | ||
|
@@ -33,6 +33,9 @@ def test_create_secret_santa(self): | |
response.status_code, status.HTTP_201_CREATED, response.content | ||
) | ||
assert response.json() == {"id": mock.ANY} | ||
assert self.sqs.send_message.call_count == 1 | ||
assert "[email protected]" in self.sqs.send_message.call_args[1]["MessageBody"] | ||
assert "+34123456789" in self.sqs.send_message.call_args[1]["MessageBody"] | ||
|
||
def test_create_with_exclusions(self): | ||
self.secret_santa_data = { | ||
|
@@ -110,8 +113,8 @@ def test_retrieve(self): | |
self.assertEqual(response.data, {"source": "From name", "target": "To Name"}) | ||
|
||
def test_missing_fields(self): | ||
secret_santa_data = {} | ||
response = self.client.post(self.list_url, secret_santa_data) | ||
self.secret_santa_data = {} | ||
response = self.client.post(self.list_url, self.secret_santa_data) | ||
self.assertEqual( | ||
response.status_code, status.HTTP_400_BAD_REQUEST, response.content | ||
) | ||
|
@@ -126,6 +129,39 @@ def test_missing_fields(self): | |
} | ||
} | ||
|
||
def test_missing_target_create(self): | ||
self.secret_santa_data = { | ||
"language": "en", | ||
"participants": [ | ||
{ | ||
"name": "First Name", | ||
}, | ||
{ | ||
"name": "Second Name", | ||
"email": "[email protected]", | ||
}, | ||
{ | ||
"name": "Third Name", | ||
"email": "[email protected]", | ||
}, | ||
], | ||
} | ||
response = self.client.post(self.list_url, self.secret_santa_data) | ||
self.assertEqual( | ||
response.status_code, status.HTTP_400_BAD_REQUEST, response.content | ||
) | ||
assert response.json() == { | ||
"schema": { | ||
"participants": { | ||
"0": { | ||
"non_field_errors": [ | ||
{"code": "invalid", "message": "phone_or_email_required"} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
|
||
def test_fecth_secret_santa_admin(self): | ||
# Create draw | ||
response = self.client.post(self.list_url, self.secret_santa_data) | ||
|
@@ -191,6 +227,44 @@ def test_resend_email_success(self): | |
self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) | ||
assert self.sqs.send_message.call_count == 1 | ||
|
||
def test_resend_whatsapp_success(self): | ||
draw = models.SecretSanta() | ||
draw.save() | ||
result = models.SecretSantaResult( | ||
source="From name", target="To Name", draw=draw | ||
) | ||
result.save() | ||
assert self.sqs.send_message.call_count == 0 | ||
|
||
url = reverse( | ||
"secret-santa-resend-email", | ||
kwargs=dict(draw_pk=draw.id, result_pk=result.id), | ||
) | ||
with freezegun.freeze_time(NOW + dt.timedelta(days=1)): | ||
response = self.client.post( | ||
url, {"language": "en", "phone_number": "+34123456789"} | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) | ||
assert self.sqs.send_message.call_count == 1 | ||
|
||
def test_resend_missing_target(self): | ||
draw = models.SecretSanta() | ||
draw.save() | ||
result = models.SecretSantaResult( | ||
source="From name", target="To Name", draw=draw | ||
) | ||
result.save() | ||
assert self.sqs.send_message.call_count == 0 | ||
|
||
url = reverse( | ||
"secret-santa-resend-email", | ||
kwargs=dict(draw_pk=draw.id, result_pk=result.id), | ||
) | ||
with freezegun.freeze_time(NOW + dt.timedelta(days=1)): | ||
response = self.client.post(url, {"language": "en"}) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
assert self.sqs.send_message.call_count == 0 | ||
|
||
def test_resend_email_unlinked_result_fails(self): | ||
draw = models.SecretSanta() | ||
draw.save() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters