Esempio n. 1
0
    def test_set_api_token_from_file(self):
        # set a pointer to a file so that exactly one line will be read to get
        # an API token
        test_token = "This is a test token! :)"
        test_fp = StringIO(test_token)

        # initialize a QualtricsAccount object
        test_account = QualtricsAccount()
        test_account.set_api_token_from_file(test_fp)
        self.assertEqual(test_token, test_account.api_token)
Esempio n. 2
0
    def test_mailing_list_init(self):
        # initialize a QualtricsAccount object
        test_api_token = test_config.API_TOKEN
        test_data_center = test_config.DATA_CENTER
        test_account = QualtricsAccount(test_api_token, test_data_center)

        # initialize a QualtricsMailingList object
        test_library_id = test_config.LIBRARY_ID
        test_mailing_list_name = test_config.MAILING_LIST_NAME
        test_category_name = test_config.CATEGORY_NAME_FOR_UNIT_TESTS
        test_mailing_list = QualtricsMailingList(
            test_account,
            test_library_id,
            test_mailing_list_name,
            category_name=test_category_name,
        )
        test_mailing_list_id = test_mailing_list.id

        # verify mailing list with created id exists
        request_response = requests.request(
            "GET",
            f"https://{test_account.data_center}.qualtrics.com"
            f"/API/v3/mailinglists/{test_mailing_list_id}",
            headers={"x-api-token": test_account.api_token},
        )

        # verify mailing list exists with specified id by checking HTTP response
        self.assertEqual(request_response.status_code, 200)
Esempio n. 3
0
    def test_contact_list_property(self):
        # initialize a QualtricsAccount object
        test_api_token = test_config.API_TOKEN
        test_data_center = test_config.DATA_CENTER
        test_account = QualtricsAccount(test_api_token, test_data_center)

        # initialize a QualtricsMailingList object
        test_library_id = test_config.LIBRARY_ID
        test_mailing_list_name = test_config.MAILING_LIST_NAME
        test_category_name = test_config.CATEGORY_NAME_FOR_UNIT_TESTS
        test_mailing_list = QualtricsMailingList(
            test_account,
            test_library_id,
            test_mailing_list_name,
            category_name=test_category_name,
        )

        # import test contact file
        test_contact_list = [
            "firstName,lastName,email",
            "first,user1,[email protected]",
            "second,user2,[email protected]",
        ]
        test_fp = StringIO("\n".join(test_contact_list))
        test_mailing_list.import_contact_list_from_csv_file(test_fp)

        # verify contact list of specified list exists and is accessible using
        # the contact_list property
        self.assertEqual(len(test_mailing_list.contact_list),
                         len(test_contact_list) - 1)
Esempio n. 4
0
    def test_distribution_init(self):
        # initialize a QualtricsAccount object
        test_api_token = test_config.API_TOKEN
        test_data_center = test_config.DATA_CENTER
        test_account = QualtricsAccount(test_api_token, test_data_center)

        # initialize a QualtricsMailingList object
        test_library_id = test_config.LIBRARY_ID
        test_mailing_list_name = test_config.MAILING_LIST_NAME
        test_category_name = test_config.CATEGORY_NAME_FOR_UNIT_TESTS
        test_mailing_list = QualtricsMailingList(
            test_account,
            test_library_id,
            test_mailing_list_name,
            category_name=test_category_name,
        )

        # initialize a QualtricsDistribution object
        test_message_id = test_config.MESSAGE_ID
        test_survey_id = test_config.SURVEY_ID
        test_send_date = test_config.SEND_DATE
        test_from_name = test_config.FROM_NAME
        test_reply_email = test_config.REPLY_EMAIL
        test_subject = test_config.SUBJECT
        test_distribution = QualtricsDistribution(
            test_mailing_list,
            test_message_id,
            test_survey_id,
            test_send_date,
            test_from_name,
            test_reply_email,
            test_subject,
        )
        test_distribution_id = test_distribution.id

        # verify distribution exists
        request_response = requests.request(
            "GET",
            f"https://{test_account.data_center}.qualtrics.com/API/v3/"
            f"distributions/{test_distribution_id}?surveyId={test_survey_id}",
            headers={"x-api-token": test_account.api_token},
        )

        # verify distribution exists with specified id by checking HTTP response
        self.assertEqual(request_response.status_code, 200)
Esempio n. 5
0
    def test_import_contact_list_from_csv_file(self):
        # initialize a QualtricsAccount object
        test_api_token = test_config.API_TOKEN
        test_data_center = test_config.DATA_CENTER
        test_account = QualtricsAccount(test_api_token, test_data_center)

        # initialize a QualtricsMailingList object
        test_library_id = test_config.LIBRARY_ID
        test_mailing_list_name = test_config.MAILING_LIST_NAME
        test_category_name = test_config.CATEGORY_NAME_FOR_UNIT_TESTS
        test_mailing_list = QualtricsMailingList(
            test_account,
            test_library_id,
            test_mailing_list_name,
            category_name=test_category_name,
        )

        # import test contact file
        test_contact_list = [
            "firstName,lastName,email",
            "first,user1,[email protected]",
            "second,user2,[email protected]",
        ]
        test_fp = StringIO("\n".join(test_contact_list))
        test_mailing_list.import_contact_list_from_csv_file(test_fp)

        # verify contact list has been imported
        request_response = requests.request(
            "GET",
            f"https://{test_account.data_center}.qualtrics.com"
            f"/API/v3/mailinglists/{test_mailing_list.id}/contacts",
            headers={
                "x-api-token": test_account.api_token,
            },
        )

        # verify mailing list has specified length by checking HTTP response
        contact_list_results = request_response.json()["result"]["elements"]
        self.assertEqual(len(contact_list_results), len(test_contact_list) - 1)
Esempio n. 6
0
    def test_distribution_details_property(self):
        # initialize a QualtricsAccount object
        test_api_token = test_config.API_TOKEN
        test_data_center = test_config.DATA_CENTER
        test_account = QualtricsAccount(test_api_token, test_data_center)

        # initialize a QualtricsMailingList object
        test_library_id = test_config.LIBRARY_ID
        test_mailing_list_name = test_config.MAILING_LIST_NAME
        test_category_name = test_config.CATEGORY_NAME_FOR_UNIT_TESTS
        test_mailing_list = QualtricsMailingList(
            test_account,
            test_library_id,
            test_mailing_list_name,
            category_name=test_category_name,
        )

        # initialize a QualtricsDistribution object
        test_message_id = test_config.MESSAGE_ID
        test_survey_id = test_config.SURVEY_ID
        test_send_date = test_config.SEND_DATE
        test_from_name = test_config.FROM_NAME
        test_reply_email = test_config.REPLY_EMAIL
        test_subject = test_config.SUBJECT
        test_distribution = QualtricsDistribution(
            test_mailing_list,
            test_message_id,
            test_survey_id,
            test_send_date,
            test_from_name,
            test_reply_email,
            test_subject,
        )

        # verify distribution list was successfully created and had properly
        # formatted id accessible from details property
        self.assertRegex(test_distribution.details["id"], 'EMD_\w+')
Esempio n. 7
0
    def test_schedule_distribution_with_csv_import(self):
        # BOBBY'S EXPERIENCE

        # Bobby follows the instructions at
        # https://www.qualtrics.com/support/integrations/api-integration
        # /overview/#GeneratingAnAPIToken to generate an API Token

        # Bobby then follows the instructions at
        # https://api.qualtrics.com/docs/root-url to get their data center name

        # Bobby then creates a Qualtrics account object by specifying a data
        # center name and API token
        test_data_center = test_config.DATA_CENTER
        test_api_token = test_config.API_TOKEN
        test_account = QualtricsAccount(test_api_token, test_data_center)

        # Bobby then follows the instructions at
        # https://api.qualtrics.com/docs/finding-qualtrics-ids to find the
        # library/group they want to work in

        # Bobby then creates a new mailing list object by specifying a Qualtrics
        # Account object, library id, mailing list name, and category name
        test_library_id = test_config.LIBRARY_ID
        test_mailing_list_name = test_config.MAILING_LIST_NAME
        test_category_name = test_config.CATEGORY_NAME_FOR_FUNCTIONAL_TESTS
        test_mailing_list = QualtricsMailingList(
            test_account,
            test_library_id,
            test_mailing_list_name,
            test_category_name
        )

        # The mailing list object makes an API call to get its mailing list id
        self.assertRegex(test_mailing_list.id, 'ML_\w+')

        # Bobby then imports their contact list into the mailing list object
        # by passing a file pointer to a CSV file having columns
        # - firstName
        # - lastName
        # - email
        with open('tests/test_contact_list.csv') as fp:
            test_mailing_list.import_contact_list_from_csv_file(fp)

        # Bobby then prints out the contents of the contact list to make sure
        # it was created as expected
        pprint(test_mailing_list.contact_list)

        # Bobby then follows the instructions at
        # https://api.qualtrics.com/docs/finding-qualtrics-ids to determine the
        # id for a survey they would like to distribute

        # Bobby then follows the instructions at
        # https://api.qualtrics.com/docs/finding-qualtrics-ids to determine the
        # id for a message they would like to use to distribute the survey

        # Bobby then creates a distribution object by specifying a mailing list
        # object, a message id, survey id, and email settings for send datetime
        # is ISO 8601 format, from name, reply email address, and subject
        test_message_id = test_config.MESSAGE_ID
        test_survey_id = test_config.SURVEY_ID
        test_send_date = test_config.SEND_DATE
        test_from_name = test_config.FROM_NAME
        test_reply_email = test_config.REPLY_EMAIL
        test_subject = test_config.SUBJECT
        test_distribution = QualtricsDistribution(
            test_mailing_list,
            test_message_id,
            test_survey_id,
            test_send_date,
            test_from_name,
            test_reply_email,
            test_subject,
        )

        # Bobby then prints out the contents of the distribution to make sure it
        # was created as expected
        pprint(test_distribution.details)
Esempio n. 8
0
from datetime import datetime
from pprint import pprint

from qualtrics_mailer import (QualtricsAccount, QualtricsDistribution,
                              QualtricsMailingList)

# set data center and API token
api_token = '[your account API token]'
data_center = '[your account data center name]'

# initialize Qualtrics Account object
account = QualtricsAccount(api_token, data_center)

# set library id, mailing list, and category name
library_id = '[valid library id for your account]'
mailing_list_name = 'Example Usage List Name'
category_name = 'Example Usage Category Name'

# initialize Qualtrics Mailing List object
mailing_list = QualtricsMailingList(account, library_id, mailing_list_name,
                                    category_name)

# import example contact list from test folder
with open('example_mailing_list.csv') as fp:
    mailing_list.import_contact_list_from_csv_file(fp)

# print mailing list's contact list to confirm proper import
pprint(mailing_list.contact_list)

# set message id, survey id, and email settings
message_id = '[valid message id for your account]'