-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
guidance_and_support: zendesk: check referer path
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""A module of unit tests for guidance and support.""" | ||
import copy | ||
import pytest | ||
from django.http import HttpRequest | ||
from django import forms | ||
|
@@ -9,7 +10,8 @@ | |
LEGITIMATE_USER['request'] = HttpRequest() | ||
LEGITIMATE_USER['request'].META['SERVER_NAME'] = "iatistandard.org" | ||
LEGITIMATE_USER['request'].META['SERVER_PORT'] = 80 | ||
LEGITIMATE_USER['request'].path = "/en/a-test-path" | ||
LEGITIMATE_USER['request'].META['HTTP_REFERER'] = "/en/a-test-path" | ||
LEGITIMATE_USER['request'].path = "/en/guidance/get-support/" | ||
LEGITIMATE_USER['form'] = forms.Form() | ||
LEGITIMATE_USER['form'].cleaned_data = { | ||
'phone': '', | ||
|
@@ -25,7 +27,10 @@ | |
'email': '[email protected]' | ||
}, | ||
'comment': { | ||
'body': 'A request was sent from /en/a-test-path.\nA very serious matter.' | ||
'body': ( | ||
'A request was sent from /en/guidance/get-support/. The sender was previously on /en/a-test-path.' | ||
'\nA very serious matter.' | ||
) | ||
}, | ||
'subject': 'Automated request from A legitimate user' | ||
} | ||
|
@@ -52,3 +57,21 @@ def test_generate_ticket(user): | |
"""Test a ticket from a valid user and a spam bot.""" | ||
ticket = generate_ticket(user['request'], user['form'], score=user['score']) | ||
assert ticket == user['expected_output'] | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_generate_ticket_with_referer_path_false(): | ||
""" | ||
Test a ticket request sent from get-support page without referer page. | ||
""" | ||
user = copy.deepcopy(LEGITIMATE_USER) | ||
user['request'].META['HTTP_REFERER'] = None | ||
user['expected_output']['request']['comment']['body'] = ( | ||
'A request was sent from /en/guidance/get-support/.\nA very serious matter.' | ||
) | ||
ticket = generate_ticket( | ||
user['request'], | ||
user['form'], | ||
score=user['score'] | ||
) | ||
assert ticket == user['expected_output'] |
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