def test_form_submission_serializer(user, rf): request = rf.get('/') request.user = user input_data = { 'data': { 'title': 'hello' }, 'meta': { 'action_name': 'email', 'recipients': ['*****@*****.**'], 'form_url': '/the/form/', 'reply_to': '*****@*****.**' } } serializer = serializers.SubmissionModelSerializer( data=input_data, context={'request': request}) assert serializer.is_valid() assert serializer.validated_data == { 'data': { 'title': 'hello' }, 'meta': { 'action_name': 'email', 'recipients': ['*****@*****.**'], 'reply_to': '*****@*****.**' }, 'form_url': '/the/form/', 'client': user, }
def test_form_submission_serializer_old_gov_notify_email(user, rf): # This can be remove when all clients are using the new gov-notify-action request = rf.get('/') request.user = user input_data = { 'data': { 'title': 'hello', }, 'meta': { 'action_name': 'gov-notify', 'template_id': '213123', 'email_address': '*****@*****.**', } } serializer = serializers.SubmissionModelSerializer( data=input_data, context={'request': request}) assert serializer.is_valid() assert serializer.validated_data == { 'data': { 'title': 'hello', }, 'meta': { 'action_name': 'gov-notify-email', 'template_id': '213123', 'email_address': '*****@*****.**', }, 'form_url': '', 'client': user, }
def pardot_submission(pardot_action_payload, rf, user): request = rf.get('/') request.user = user serializer = serializers.SubmissionModelSerializer( data=pardot_action_payload, context={'request': request}) assert serializer.is_valid() return serializer.save()
def gov_notify_letter_submission(gov_notify_letter_action_payload, rf, user): request = rf.get('/') request.user = user serializer = serializers.SubmissionModelSerializer( data=gov_notify_letter_action_payload, context={'request': request}) assert serializer.is_valid() return serializer.save()
def test_gov_notify_email_action_serializer_from_submission_reply_email( gov_notify_email_action_payload, rf, user): request = rf.get('/') request.user = user data = {**gov_notify_email_action_payload} data['meta']['email_reply_to_id'] = '123' serializer = serializers.SubmissionModelSerializer( data=data, context={'request': request}) assert serializer.is_valid() gov_notify_email_submission = serializer.save() serializer = serializers.GovNotifyEmailSerializer.from_submission( gov_notify_email_submission) assert serializer.is_valid() assert serializer.validated_data == { 'template_id': gov_notify_email_submission.meta['template_id'], 'email_address': gov_notify_email_submission.meta['email_address'], 'personalisation': { 'title': gov_notify_email_submission.data['title'], }, 'email_reply_to_id': '123', }