Ejemplo n.º 1
0
 def test_post_to_service_now(self, mock_post, form_categories):
     form_categories.return_value = [('fake', 'Fake category')]
     # Test to make sure this method removes the `committee_name` field
     form = ContactRAD(self.form_data)
     form.post_to_service_now()
     call_data = mock_post.call_args[1]['data']
     self.assertFalse('committee_name' in call_data)
Ejemplo n.º 2
0
def contact_rad(request):
    page_context = {
        'title': 'Submit a question to the Reports Analysis Division (RAD)',
        'ancestors': [{
          'title': 'Help for candidates and committees',
          'url': '/help-candidates-and-committees/',
        }],
        'content_section': 'help'
    }

    if settings.FEATURES['radform']:
        # If it's a POST, post to the ServiceNow API
        if request.method == 'POST':
            form = ContactRAD(request.POST)
            response = form.post_to_service_now()
            if response == 201:
                return render(request, 'home/contact-form.html', {
                  'self': page_context,
                  'success': True
                })
            else:
                return render(request, 'home/contact-form.html', {
                  'self': page_context,
                  'form': form,
                  'server_error': True
                })
        else:
            form = ContactRAD()
    else:
        form = False

    return render(request, 'home/contact-form.html', {
        'self': page_context,
        'form': form
    })
Ejemplo n.º 3
0
def contact_rad(request):
    page_context = {
        "title":
        "Submit a question to the Reports Analysis Division (RAD)",
        "ancestors": [{
            "title": "Help for candidates and committees",
            "url": "/help-candidates-and-committees/",
        }],
        "content_section":
        "help",
    }

    if settings.FEATURES["radform"]:
        # If it's a POST, post to the ServiceNow API
        if request.method == "POST":
            form = ContactRAD(request.POST)
            response = form.post_to_service_now()
            if response == 201:
                return render(
                    request,
                    "home/contact-form.html",
                    {
                        "self": page_context,
                        "success": True
                    },
                )
            else:
                return render(
                    request,
                    "home/contact-form.html",
                    {
                        "self": page_context,
                        "form": form,
                        "server_error": True
                    },
                )
        else:
            form = ContactRAD()
    else:
        form = False

    return render(request, "home/contact-form.html", {
        "self": page_context,
        "form": form
    })
Ejemplo n.º 4
0
 def test_empty_submission(self):
     form = ContactRAD({})
     self.assertFalse(form.is_valid())
Ejemplo n.º 5
0
 def test_valid_submission(self, form_categories):
     form_categories.return_value = [('fake', 'Fake category')]
     form = ContactRAD(self.form_data)
     self.assertTrue(form.is_valid())
Ejemplo n.º 6
0
def contact_rad(request):
    page_context = {
        "title":
        "Submit a question to the Reports Analysis Division (RAD)",
        "ancestors": [{
            "title": "Help for candidates and committees",
            "url": "/help-candidates-and-committees/",
        }],
        "content_section":
        "help",
    }

    # Only show contact form if we can contact ServiceNow
    if fetch_categories():
        # If it's a POST, post to the ServiceNow API
        if request.method == "POST":
            form = ContactRAD(request.POST)
            # Get the captcha response from the post request and perform server-side verification
            capchaResponse = request.POST.get('g-recaptcha-response')
            verifyRecaptcha = requests.post(
                "https://www.google.com/recaptcha/api/siteverify",
                data={
                    "secret": settings.FEC_RECAPTCHA_SECRET_KEY,
                    "response": capchaResponse,
                },
            )
            recaptchaResponse = verifyRecaptcha.json()
            if not recaptchaResponse["success"]:
                # if captcha failed, return and log failure
                logger.error("Recaptcha failed - possible spam")
                return render(
                    request,
                    "home/contact-form.html",
                    {
                        "self": page_context,
                        "form": form,
                        "server_error": True
                    },
                )
            else:
                # If the captcha is good, go ahead and post it
                response = form.post_to_service_now()
                if response == 201:
                    return render(
                        request,
                        "home/contact-form.html",
                        {
                            "self": page_context,
                            "success": True
                        },
                    )
                else:
                    # This gets triggered when all the required fields are not entered into the POST request
                    logger.error("Error submitting RAD question")
                    return render(
                        request,
                        "home/contact-form.html",
                        {
                            "self": page_context,
                            "form": form,
                            "server_error": True
                        },
                    )
        else:
            form = ContactRAD()
    else:
        form = False

    return render(request, "home/contact-form.html", {
        "self": page_context,
        "form": form
    })