Esempio n. 1
0
    def test_creds(self, mock_requests):
        """Ensure the token and secret are passed correctly."""
        mock_requests.get.return_value.content = SURVEY_GIZMO_EMPTY_RESPONSE

        with self.settings(SURVEYGIZMO_API_TOKEN='mytoken',
                           SURVEYGIZMO_API_TOKEN_SECRET='mysecret'):
            get_email_addresses('general', datetime(2016, 1, 1), datetime(2016, 1, 2))

            url = mock_requests.get.call_args[0][0]
            ok_('api_token=mytoken' in url)
            ok_('api_token_secret=mysecret' in url)
Esempio n. 2
0
    def test_creds(self, mock_requests):
        """Ensure the token and secret are passed correctly."""
        mock_requests.get.return_value.content = SURVEY_GIZMO_EMPTY_RESPONSE

        with self.settings(SURVEYGIZMO_API_TOKEN='mytoken',
                           SURVEYGIZMO_API_TOKEN_SECRET='mysecret'):
            get_email_addresses('general', datetime(2016, 1, 1, 12, 0),
                                datetime(2016, 1, 2, 13, 0))

            url = mock_requests.get.call_args[0][0]
            ok_('api_token=mytoken' in url)
            ok_('api_token_secret=mysecret' in url)
Esempio n. 3
0
def process_exit_surveys():
    """Exit survey handling.

    * Collect new exit survey results.
    * Save results to our metrics table.
    * Add new emails collected to the exit survey.
    """

    _process_exit_survey_results()

    # Get the email addresses from two days ago and add them to the survey
    # campaign (skip this on stage).
    if settings.STAGE:
        # Only run this on prod, it doesn't need to be running multiple times
        # from different places.
        return

    startdate = date.today() - timedelta(days=2)
    enddate = date.today() - timedelta(days=1)

    for survey in SURVEYS.keys():
        if 'email_collection_survey_id' not in SURVEYS[survey]:
            # Some surveys don't have email collection on the site
            # (the askers survey, for example).
            continue

        emails = get_email_addresses(survey, startdate, enddate)
        for email in emails:
            add_email_to_campaign(survey, email)

        statsd.gauge('survey.{0}'.format(survey), len(emails))
Esempio n. 4
0
def process_exit_surveys():
    """Exit survey handling.

    * Collect new exit survey results.
    * Save results to our metrics table.
    * Add new emails collected to the exit survey.
    """

    _process_exit_survey_results()

    # Get the email addresses from 4-5 hours ago and add them to the survey
    # campaign (skip this on stage).

    # The cron associated with this process is set to run every hour,
    # with the intent of providing a 4-5 hour wait period between when a
    # visitor enters their email address and is then sent a follow-up
    # survey.
    # The range here is set between 4 and 8 hours to be sure no emails are
    # missed should a particular cron run be skipped (e.g. during a deployment)
    startdatetime = datetime.now() - timedelta(hours=8)
    enddatetime = datetime.now() - timedelta(hours=4)

    for survey in SURVEYS.keys():
        if not SURVEYS[survey][
                'active'] or 'email_collection_survey_id' not in SURVEYS[
                    survey]:
            # Some surveys don't have email collection on the site
            # (the askers survey, for example).
            continue

        emails = get_email_addresses(survey, startdatetime, enddatetime)
        for email in emails:
            add_email_to_campaign(survey, email)

        statsd.gauge('survey.{0}'.format(survey), len(emails))
Esempio n. 5
0
def process_exit_surveys():
    """Exit survey handling.

    * Collect new exit survey results.
    * Save results to our metrics table.
    * Add new emails collected to the exit survey.
    """

    _process_exit_survey_results()

    # Get the email addresses from two days ago and add them to the survey
    # campaign (skip this on stage).
    if settings.STAGE:
        # Only run this on prod, it doesn't need to be running multiple times
        # from different places.
        return

    startdate = date.today() - timedelta(days=2)
    enddate = date.today() - timedelta(days=1)

    for survey in SURVEYS.keys():
        if 'email_collection_survey_id' not in SURVEYS[survey]:
            # Some surveys don't have email collection on the site
            # (the askers survey, for example).
            continue

        emails = get_email_addresses(survey, startdate, enddate)
        for email in emails:
            add_email_to_campaign(survey, email)

        statsd.gauge('survey.{0}'.format(survey), len(emails))
Esempio n. 6
0
def process_exit_surveys():
    """Exit survey handling.

    * Collect new exit survey results.
    * Save results to our metrics table.
    * Add new emails collected to the exit survey.
    """

    _process_exit_survey_results()

    # Get the email addresses from two days ago and add them to the survey
    # campaign (skip this on stage).
    if settings.STAGE:
        # Only run this on prod, it doesn't need to be running multiple times
        # from different places.
        print ('Skipped email address processing in process_exit_surveys(). '
               'Set settings.STAGE to False to run it for real.')
        return

    startdate = date.today() - timedelta(days=2)
    enddate = date.today() - timedelta(days=1)

    for survey in SURVEYS.keys():
        emails = get_email_addresses(survey, startdate, enddate)
        for email in emails:
            add_email_to_campaign(survey, email)

        print '%s emails processed for %s...' % (len(emails), survey)
Esempio n. 7
0
    def handle(self, **options):
        """
        * Collect new exit survey results.
        * Save results to our metrics table.
        * Add new emails collected to the exit survey.
        """

        utils._process_exit_survey_results()

        # Get the email addresses from 4-5 hours ago and add them to the survey
        # campaign (skip this on stage).

        # The cron associated with this process is set to run every hour,
        # with the intent of providing a 4-5 hour wait period between when a
        # visitor enters their email address and is then sent a follow-up
        # survey.
        # The range here is set between 4 and 8 hours to be sure no emails are
        # missed should a particular cron run be skipped (e.g. during a deployment)
        startdatetime = datetime.now() - timedelta(hours=8)
        enddatetime = datetime.now() - timedelta(hours=4)

        for survey in SURVEYS.keys():
            if (
                not SURVEYS[survey]["active"] or
                "email_collection_survey_id" not in SURVEYS[survey]
            ):
                # Some surveys don't have email collection on the site
                # (the askers survey, for example).
                continue

            emails = get_email_addresses(survey, startdatetime, enddatetime)
            for email in emails:
                add_email_to_campaign(survey, email)

            statsd.gauge("survey.{0}".format(survey), len(emails))
Esempio n. 8
0
def process_exit_surveys():
    """Exit survey handling.

    * Collect new exit survey results.
    * Save results to our metrics table.
    * Add new emails collected to the exit survey.
    """

    _process_exit_survey_results()

    # Get the email addresses from two days ago and add them to the survey
    # campaign (skip this on stage).
    if settings.STAGE:
        # Only run this on prod, it doesn't need to be running multiple times
        # from different places.
        print ('Skipped email address processing in process_exit_surveys(). '
               'Set settings.STAGE to False to run it for real.')
        return

    startdate = date.today() - timedelta(days=2)
    enddate = date.today() - timedelta(days=1)

    emails = get_email_addresses(startdate, enddate)
    for email in emails:
        add_email_to_campaign(email)

    print '%s emails processed...' % len(emails)
Esempio n. 9
0
    def test_early_exit(self, mock_requests):
        """
        If there are no creds, don't hit the API and return an empty
        list.
        """
        with self.settings(SURVEYGIZMO_API_TOKEN=None,
                           SURVEYGIZMO_API_TOKEN_SECRET=None):
            emails = get_email_addresses('general', datetime(2016, 1, 1),
                                         datetime(2016, 1, 2))

            eq_(emails, [])
            ok_(not mock_requests.get.called)
Esempio n. 10
0
    def test_early_exit(self, mock_requests):
        """
        If there are no creds, don't hit the API and return an empty
        list.
        """
        with self.settings(SURVEYGIZMO_API_TOKEN=None,
                           SURVEYGIZMO_API_TOKEN_SECRET=None):
            emails = get_email_addresses(
                'general',
                datetime(2016, 1, 1),
                datetime(2016, 1, 2)
            )

            eq_(emails, [])
            ok_(not mock_requests.get.called)