-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add an api for to send other category to freshdesk * fix * fix --------- Co-authored-by: William B <[email protected]>
- Loading branch information
Showing
5 changed files
with
123 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -181,6 +181,54 @@ def match_json(request): | |
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
|
||
def test_send_ticket_other_category(self, email_freshdesk_ticket_mock, notify_api: Flask): | ||
def match_json(request): | ||
expected = { | ||
"product_id": 42, | ||
"subject": "New template category request", | ||
"description": "New template category request from name ([email protected]):<br>" | ||
"- Service id: 8624bd36-b70b-4d4b-a459-13e1f4770b92<br>" | ||
"- New Template Category Request name: test category name<br>" | ||
"- Template id request: http://localhost:6012/services/8624bd36-b70b-4d4b-a459-13e1f4770b92/templates/3ed1f07a-1b20-4f83-9a3e-158ab9b00103<br>" | ||
"<hr><br>" | ||
"Demande de nouvelle catégorie de modèle de name ([email protected]):<br>" | ||
"- Identifiant du service: 8624bd36-b70b-4d4b-a459-13e1f4770b92<br>" | ||
"- Nom de la nouvelle catégorie de modèle demandée: test category name<br>" | ||
"- Demande d'identifiant de modèle: http://localhost:6012/services/8624bd36-b70b-4d4b-a459-13e1f4770b92/templates/3ed1f07a-1b20-4f83-9a3e-158ab9b00103", | ||
"email": "[email protected]", | ||
"priority": 1, | ||
"status": 2, | ||
"tags": [], | ||
} | ||
|
||
encoded_auth = base64.b64encode(b"freshdesk-api-key:x").decode("ascii") | ||
json_matches = request.json() == expected | ||
basic_auth_header = request.headers.get("Authorization") == f"Basic {encoded_auth}" | ||
|
||
return json_matches and basic_auth_header | ||
|
||
with requests_mock.mock() as rmock: | ||
rmock.request( | ||
"POST", | ||
"https://freshdesk-test.com/api/v2/tickets", | ||
additional_matcher=match_json, | ||
status_code=201, | ||
) | ||
data: Dict[str, Any] = { | ||
"email_address": "[email protected]", | ||
"name": "name", | ||
"friendly_support_type": "New template category request", | ||
"support_type": "new_template_category_request", | ||
"service_id": "8624bd36-b70b-4d4b-a459-13e1f4770b92", | ||
"template_category_name_en": "test category name", | ||
"template_category_name_fr": "test category name", | ||
"template_id_link": "http://localhost:6012/services/8624bd36-b70b-4d4b-a459-13e1f4770b92/templates/3ed1f07a-1b20-4f83-9a3e-158ab9b00103", | ||
} | ||
with notify_api.app_context(): | ||
response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() | ||
assert response == 201 | ||
assert email_freshdesk_ticket_mock.not_called() | ||
|
||
def test_send_ticket_other(self, email_freshdesk_ticket_mock, notify_api: Flask): | ||
def match_json(request): | ||
expected = { | ||
|
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 |
---|---|---|
|
@@ -980,6 +980,31 @@ def test_send_branding_request(client, sample_service, sample_organisation, mock | |
mocked_salesforce_client.engagement_update.assert_not_called() | ||
|
||
|
||
class TestFreshDeskRequestTickets: | ||
def test_send_request_for_new_category(self, client, sample_service, sample_organisation, mocker): | ||
sample_user = sample_service.users[0] | ||
sample_service.organisation = sample_organisation | ||
post_data = { | ||
"service_name": sample_service.name, | ||
"email_address": sample_user.email_address, | ||
"service_id": str(sample_service.id), | ||
"template_category_name_en": "test", | ||
"template_category_name_fr": "test", | ||
"template_id": "1234", | ||
} | ||
mocked_freshdesk = mocker.patch("app.user.rest.Freshdesk.send_ticket", return_value=201) | ||
mocked_salesforce_client = mocker.patch("app.user.rest.salesforce_client") | ||
|
||
resp = client.post( | ||
url_for("user.send_new_template_category_request", user_id=str(sample_user.id)), | ||
data=json.dumps(post_data), | ||
headers=[("Content-Type", "application/json"), create_authorization_header()], | ||
) | ||
assert resp.status_code == 204 | ||
mocked_freshdesk.assert_called_once_with() | ||
mocked_salesforce_client.engagement_update.assert_not_called() | ||
|
||
|
||
def test_send_user_confirm_new_email_returns_204(client, sample_user, change_email_confirmation_template, mocker): | ||
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async") | ||
new_email = "[email protected]" | ||
|