-fixed tests

This commit is contained in:
Ayub khan
2019-07-30 13:35:27 +05:00
parent 9b3960ed90
commit c9080e257e
5 changed files with 88 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ from xblock.fields import Scope, String
import courseware.views.views as views
import shoppingcart
from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
from course_modes.models import CourseMode
from course_modes.tests.factories import CourseModeFactory
@@ -846,8 +847,8 @@ class ViewsTestCase(ModuleStoreTestCase):
url = reverse('submit_financial_assistance_request')
return self.client.post(url, json.dumps(data), content_type='application/json')
@patch.object(views, '_record_feedback_in_zendesk')
def test_submit_financial_assistance_request(self, mock_record_feedback):
@patch.object(views, 'create_zendesk_ticket', return_value=200)
def test_submit_financial_assistance_request(self, mock_create_zendesk_ticket):
username = self.user.username
course = six.text_type(self.course_key)
legal_name = 'Jesse Pinkman'
@@ -871,10 +872,12 @@ class ViewsTestCase(ModuleStoreTestCase):
response = self._submit_financial_assistance_form(data)
self.assertEqual(response.status_code, 204)
__, __, ticket_subject, __, tags, additional_info = mock_record_feedback.call_args[0]
mocked_kwargs = mock_record_feedback.call_args[1]
group_name = mocked_kwargs['group_name']
require_update = mocked_kwargs['require_update']
__, __, ticket_subject, __ = mock_create_zendesk_ticket.call_args[0]
mocked_kwargs = mock_create_zendesk_ticket.call_args[1]
group_name = mocked_kwargs['group']
tags = mocked_kwargs['tags']
additional_info = mocked_kwargs['additional_info']
private_comment = '\n'.join(list(additional_info.values()))
for info in (country, income, reason_for_applying, goals, effort, username, legal_name, course):
self.assertIn(info, private_comment)
@@ -891,10 +894,9 @@ class ViewsTestCase(ModuleStoreTestCase):
self.assertDictContainsSubset({'course_id': course}, tags)
self.assertIn('Client IP', additional_info)
self.assertEqual(group_name, 'Financial Assistance')
self.assertTrue(require_update)
@patch.object(views, '_record_feedback_in_zendesk', return_value=False)
def test_zendesk_submission_failed(self, _mock_record_feedback):
@patch.object(views, 'create_zendesk_ticket', return_value=500)
def test_zendesk_submission_failed(self, _mock_create_zendesk_ticket):
response = self._submit_financial_assistance_form({
'username': self.user.username,
'course': six.text_type(self.course.id),

View File

@@ -1653,8 +1653,7 @@ def financial_assistance_request(request):
)),
group='Financial Assistance',
)
if not zendesk_submitted:
if not (zendesk_submitted >= 200 and zendesk_submitted < 300):
# The call to Zendesk failed. The frontend will display a
# message to the user.
return HttpResponse(status=status.HTTP_500_INTERNAL_SERVER_ERROR)