Skip to content

Commit

Permalink
Alchemer: Update Class Name (move-coop#470)
Browse files Browse the repository at this point in the history
* Update class name.

* Lint.

* Change class construction.

* Little lint.
  • Loading branch information
jburchard authored Jan 4, 2021
1 parent fbab22f commit b3539ed
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 39 deletions.
25 changes: 25 additions & 0 deletions docs/alchemer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Alchemer
========

********
Overview
********

`Alchemer <https://www.alchemer.com/>`_ is an online research tool that allows users to field surveys. This Parsons
class allows users to retrieve surveys and survey results.

.. note::
Alchemer was formerly known as SurveyGizmo.

.. note::
Authentication
To use the class, you need to provide an Alchemer API token and API token secret. For more information,
see Alchemer API `authentication documentation <https://apihelp.alchemer.com/help/authentication>`_.

***********
Quick Start
***********

To instantiate the ``Alchemer`` class, you can either store your API token and API secret
token as environmental variables (``SURVEYGIZMO_API_TOKEN`` and ``SURVEYGIZMO_API_TOKEN_SECRET``,
respectively) or pass in the tokens arguments:
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Indices and tables
action_kit
action_network
airtable
alchemer
aws
azure
bill_com
Expand Down
5 changes: 3 additions & 2 deletions parsons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from parsons.bloomerang.bloomerang import Bloomerang
from parsons.box.box import Box
from parsons.sisense.sisense import Sisense
from parsons.surveygizmo.surveygizmo import SurveyGizmo
from parsons.alchemer.alchemer import SurveyGizmo, Alchemer

__all__ = [
'VAN',
Expand Down Expand Up @@ -95,7 +95,8 @@
'Bloomerang',
'Box',
'Sisense',
'SurveyGizmo'
'SurveyGizmo',
'Alchemer'
]

# Define the default logging config for Parsons and its submodules. For now the
Expand Down
3 changes: 3 additions & 0 deletions parsons/alchemer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from parsons.alchemer.alchemer import Alchemer, SurveyGizmo

__all__ = ['SurveyGizmo', 'Alchemer']
43 changes: 32 additions & 11 deletions parsons/surveygizmo/surveygizmo.py → parsons/alchemer/alchemer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,49 @@
logger = logging.getLogger(__name__)


class SurveyGizmo(object):
def sg_compatibility():
# Create backwards compatibility with SurveyGizmo class

import os
if os.getenv('SURVEYGIZMO_API_TOKEN'):
os.environ['ALCHEMER_API_TOKEN'] = os.getenv('SURVEYGIZMO_API_TOKEN')

if os.getenv('SURVEYGIZMO_API_TOKEN_SECRET'):
os.environ['ALCHEMER_API_TOKEN_SECRET'] = os.getenv('SURVEYGIZMO_API_TOKEN_SECRET')

if os.getenv('SURVEYGIZMO_API_VERSION'):
os.environ['ALCHEMER_API_VERSION'] = os.getenv('SURVEYGIZMO_API_VERSION')


class Alchemer(object):
"""
Instantiate SurveyGizmo Class
Instantiate Alchemer Class
`Args:`
api_token:
The SurveyGizmo-provided application token. Not required if
``SURVEYGIZMO_API_TOKEN`` env variable set.
The Alchemer-provided application token. Not required if
``ALCHEMER_API_TOKEN`` env variable set.
api_token:
The SurveyGizmo-provided application token. Not required if
``SURVEYGIZMO_API_TOKEN_SECRET`` env variable set.
The Alchemer-provided application token. Not required if
``ALCHEMER_API_TOKEN_SECRET`` env variable set.
api_version:
The version of the API that you would like to use. Not required if
``SURVEYGIZMO_API_VERSION`` env variable set.
``ALCHEMER_API_VERSION`` env variable set.
Default v5
`Returns:`
SurveyGizmo Class
Alchemer Class
"""

def __init__(self, api_token=None, api_token_secret=None, api_version='v5'):
self.api_token = check_env.check('SURVEYGIZMO_API_TOKEN', api_token)
self.api_token_secret = check_env.check('SURVEYGIZMO_API_TOKEN_SECRET', api_token_secret)
self.api_version = check_env.check('SURVEYGIZMO_API_VERSION', api_version)

sg_compatibility()

self.api_token = check_env.check('ALCHEMER_API_TOKEN', api_token)
self.api_token_secret = check_env.check('ALCHEMER_API_TOKEN_SECRET', api_token_secret)
self.api_version = check_env.check('ALCHEMER_API_VERSION', api_version)

self._client = surveygizmo.SurveyGizmo(
api_version=self.api_version,
Expand Down Expand Up @@ -97,3 +114,7 @@ def get_survey_responses(self, survey_id, page=None):
logger.info(f"Found #{tbl.num_rows} responses.")

return tbl


# Backwards compatibility for old SurveyGizmo class.
SurveyGizmo = Alchemer
3 changes: 0 additions & 3 deletions parsons/surveygizmo/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import os
import unittest
import unittest.mock as mock
from parsons.surveygizmo.surveygizmo import SurveyGizmo
from parsons.alchemer.alchemer import Alchemer
import logging

logger = logging.getLogger(__name__)


class TestSurveyGizmoGetResponses(unittest.TestCase):
class TestAlchemErGetResponses(unittest.TestCase):
def setUp(self):
os.environ['SURVEYGIZMO_API_TOKEN'] = 'MYFAKEAPITOKEN'
os.environ['SURVEYGIZMO_API_TOKEN_SECRET'] = 'MYFAKETOKENSECRET'
os.environ['SURVEYGIZMO_API_VERSION'] = 'MYFAKEVERSION'
os.environ['ALCHEMER_API_TOKEN'] = 'MYFAKEAPITOKEN'
os.environ['ALCHEMER_API_TOKEN_SECRET'] = 'MYFAKETOKENSECRET'
os.environ['ALCHEMER_API_VERSION'] = 'MYFAKEVERSION'

self.surveygizmo = SurveyGizmo()
self.surveygizmo._client = mock.MagicMock()
self.alchemer = Alchemer()
self.alchemer._client = mock.MagicMock()

self.test_survey_id = "1234567"

def test_adds_survey_id(self):
api_return = self._get_responses_return_single_page()
self.surveygizmo._client.api.surveyresponse.list.return_value = api_return
self.alchemer._client.api.surveyresponse.list.return_value = api_return

actual_responses = self.surveygizmo.get_survey_responses(self.test_survey_id)
actual_responses = self.alchemer.get_survey_responses(self.test_survey_id)

assert self.test_survey_id, actual_responses["survey_id"]

def test_get_responses_single_page(self):
api_return = self._get_responses_return_single_page()
self.surveygizmo._client.api.surveyresponse.list.return_value = api_return
self.alchemer._client.api.surveyresponse.list.return_value = api_return

actual_responses = self.surveygizmo.get_survey_responses(self.test_survey_id)
actual_responses = self.alchemer.get_survey_responses(self.test_survey_id)

self.assertEqual(2, actual_responses.num_rows)
for i in range(0, 1):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import os
import unittest
import unittest.mock as mock
from parsons.surveygizmo.surveygizmo import SurveyGizmo
from parsons.alchemer.alchemer import Alchemer
import logging

logger = logging.getLogger(__name__)

# Relevant links
# V5 API Documentation https://apihelp.surveygizmo.com/help/version-5
# V5 API Documentation https://apihelp.alchemer.com/help/version-5


class TestSurveyGizmoGetSurveys(unittest.TestCase):
class TestAlchemErGetSurveys(unittest.TestCase):
def setUp(self):
os.environ['SURVEYGIZMO_API_TOKEN'] = 'MYFAKEAPITOKEN'
os.environ['SURVEYGIZMO_API_TOKEN_SECRET'] = 'MYFAKETOKENSECRET'
os.environ['SURVEYGIZMO_API_VERSION'] = 'MYFAKEVERSION'
os.environ['ALCHEMER_API_TOKEN'] = 'MYFAKEAPITOKEN'
os.environ['ALCHEMER_API_TOKEN_SECRET'] = 'MYFAKETOKENSECRET'
os.environ['ALCHEMER_API_VERSION'] = 'MYFAKEVERSION'

self.surveygizmo = SurveyGizmo()
self.surveygizmo._client = mock.MagicMock()
self.alchemer = Alchemer()
self.alchemer._client = mock.MagicMock()

def test_get_surveys_single_page(self):
api_return = self._get_surveys_return_single_page()
self.surveygizmo._client.api.survey.list.return_value = api_return
self.alchemer._client.api.survey.list.return_value = api_return

actual_surveys = self.surveygizmo.get_surveys()
actual_surveys = self.alchemer.get_surveys()

self.assertEqual(2, actual_surveys.num_rows)
for i in range(0, 1):
self.assertEqual(api_return["data"][i]["title"], actual_surveys[i]["title"])

def test_removes_links_field(self):
api_return = self._get_surveys_return_single_page()
self.surveygizmo._client.api.survey.list.return_value = api_return
self.alchemer._client.api.survey.list.return_value = api_return

actual_surveys = self.surveygizmo.get_surveys()
actual_surveys = self.alchemer.get_surveys()

assert "links" not in actual_surveys.columns

Expand Down

0 comments on commit b3539ed

Please sign in to comment.