Skip to content

Commit

Permalink
Merge pull request #796 from IATI/get-support-form
Browse files Browse the repository at this point in the history
Get support form, check referer page.
  • Loading branch information
odscjames authored Nov 15, 2024
2 parents 1367313 + 716fdc2 commit 333f28b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 25 additions & 2 deletions guidance_and_support/tests/test_zendesk.py
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
Expand All @@ -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': '',
Expand All @@ -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'
}
Expand All @@ -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']
6 changes: 5 additions & 1 deletion guidance_and_support/zendeskhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ def generate_ticket(request, form, score=None, suspicious=False):
spam_settings = SpamSettings.for_request(request)
if score <= spam_settings.spam_threshold:
return False
path = request.path
email = form.cleaned_data.get('email')
query = form.cleaned_data.get('query')
name = form.cleaned_data.get('name', 'Anonymous requester')
path = request.path
referer_path = request.META.get('HTTP_REFERER', None)
if referer_path is not None:
path = "{}. The sender was previously on {}".format(path, referer_path)

if email and query:
request_obj = {
"request": {
Expand Down

0 comments on commit 333f28b

Please sign in to comment.