예제 #1
0
 def _get_api_call(self):
     super_ = super(CreateProperty, self)._get_api_call()
     api_call = SuccessfulAPICall.init_from_generalization(
         super_,
         response_body_deserialization=super_.request_body_deserialization,
     )
     return api_call
예제 #2
0
    def _get_api_call(self):
        super_ = super(CreatePropertyGroup, self)._get_api_call()

        response_body_deserialization = _format_response_data_for_property_group(self._property_group)
        api_call = SuccessfulAPICall.init_from_generalization(
            super_, response_body_deserialization=response_body_deserialization
        )
        return api_call
예제 #3
0
 def _get_api_call(self):
     super_ = super(CreateProperty, self)._get_api_call()
     api_call = SuccessfulAPICall.init_from_generalization(
         super_,
         response_body_deserialization=
             super_.request_body_deserialization,
         )
     return api_call
예제 #4
0
 def __call__(self):
     url_path = \
         CONTACTS_API_SCRIPT_NAME + '/groups/' + self._property_group_name
     api_call = SuccessfulAPICall(
         url_path,
         'DELETE',
         response_body_deserialization=None,
     )
     return [api_call]
예제 #5
0
    def _get_api_call(self):
        super_ = super(CreateStaticContactList, self)._get_api_call()

        response_body_deserialization = dict(super_.request_body_deserialization, listId=1)

        api_call = SuccessfulAPICall.init_from_generalization(
            super_, response_body_deserialization=response_body_deserialization
        )
        return api_call
예제 #6
0
 def __call__(self):
     response_body_deserialization = \
         _format_response_data_for_properties(self._properties)
     get_all_properties_api_call = SuccessfulAPICall(
         CONTACTS_API_SCRIPT_NAME + '/properties',
         'GET',
         response_body_deserialization=response_body_deserialization,
     )
     return [get_all_properties_api_call]
예제 #7
0
    def _get_api_call(self):
        super_ = super(CreatePropertyGroup, self)._get_api_call()

        response_body_deserialization = \
            _format_response_data_for_property_group(self._property_group)
        api_call = SuccessfulAPICall.init_from_generalization(
            super_,
            response_body_deserialization=response_body_deserialization,
        )
        return api_call
예제 #8
0
 def __call__(self):
     url_path = '{}/lists/{}'.format(
         CONTACTS_API_SCRIPT_NAME,
         self._contact_list_id,
     )
     api_call = SuccessfulAPICall(
         url_path,
         'DELETE',
         response_body_deserialization=None,
     )
     return [api_call]
예제 #9
0
 def _get_api_call_for_page(self, page_objects):
     query_string_args = self._get_query_string_args(page_objects)
     response_body_deserialization = \
         self._get_response_body_deserialization(page_objects)
     api_call = SuccessfulAPICall(
         CONTACTS_API_SCRIPT_NAME + self._API_CALL_PATH_INFO,
         'GET',
         query_string_args,
         response_body_deserialization=response_body_deserialization,
     )
     return api_call
예제 #10
0
    def _get_api_call(self):
        super_ = \
            super(CreateStaticContactList, self)._get_api_call()

        response_body_deserialization = \
            dict(super_.request_body_deserialization, listId=1)

        api_call = SuccessfulAPICall.init_from_generalization(
            super_,
            response_body_deserialization=response_body_deserialization,
        )
        return api_call
예제 #11
0
    def __call__(self):
        property_groups_data = []
        for property_group in self._property_groups:
            property_group_data = \
                _format_response_data_for_property_group(property_group)
            property_groups_data.append(property_group_data)

        api_call = SuccessfulAPICall(
            CONTACTS_API_SCRIPT_NAME + '/groups',
            'GET',
            response_body_deserialization=property_groups_data,
        )
        return [api_call]
예제 #12
0
    def test_delete_request(self):
        expected_api_call = SuccessfulAPICall(
            _STUB_URL_PATH,
            'DELETE',
            response_body_deserialization=_STUB_RESPONSE_BODY_DESERIALIZATION,
        )
        connection = \
            self._make_connection_for_expected_api_call(expected_api_call)

        response_body_deserialization = \
            connection.send_delete_request(_STUB_URL_PATH)

        self._assert_sole_api_call_equals(expected_api_call, connection)
        eq_(_STUB_RESPONSE_BODY_DESERIALIZATION, response_body_deserialization)
예제 #13
0
    def test_get_request_with_query_string_args(self):
        query_string_args = {'foo': 'bar'}
        expected_api_call = SuccessfulAPICall(
            _STUB_URL_PATH,
            'GET',
            query_string_args,
            response_body_deserialization=_STUB_RESPONSE_BODY_DESERIALIZATION,
        )
        connection = \
            self._make_connection_for_expected_api_call(expected_api_call)

        connection.send_get_request(_STUB_URL_PATH, query_string_args)

        self._assert_sole_api_call_equals(expected_api_call, connection)
예제 #14
0
    def __call__(self):
        api_calls = self._available_properties_simulator()

        request_body_deserialization = format_contact_properties_for_saving(
                self._contact.properties,
                self._property_type_by_property_name,
        )
        api_call = SuccessfulAPICall(
                CONTACTS_API_SCRIPT_NAME + '/contact/vid/' + str(self._contact.vid) + '/profile',
                'POST',
                request_body_deserialization=request_body_deserialization,
                response_body_deserialization=None,
                )
        api_calls.append(api_call)

        return api_calls
예제 #15
0
    def __call__(self):
        api_calls = self._available_properties_simulator()

        request_body_deserialization = format_contact_data_for_saving(
                self._contact,
                self._property_type_by_property_name,
                )
        api_call = SuccessfulAPICall(
                CONTACTS_API_SCRIPT_NAME + '/contact/',
                'POST',
                request_body_deserialization=request_body_deserialization,
                response_body_deserialization={'vid': self._vid },
                )
        api_calls.append(api_call)

        return api_calls
예제 #16
0
    def test_unexpected_request_body_deserialization(self):
        expected_api_call = SuccessfulAPICall(
            _STUB_URL_PATH,
            'PUT',
            response_body_deserialization=_STUB_RESPONSE_BODY_DESERIALIZATION,
        )
        connection = \
            self._make_connection_for_expected_api_call(expected_api_call)

        request_body_deserialization = {'a': 'b'}
        error_message = 'Expected request body deserialization {!r}, got {!r}' \
            .format(None, request_body_deserialization)
        with assert_raises_substring(AssertionError, error_message):
            connection.send_put_request(
                _STUB_URL_PATH,
                request_body_deserialization,
            )
예제 #17
0
    def test_put_request(self):
        request_body_deserialization = {'foo': 'bar'}
        expected_api_call = SuccessfulAPICall(
            _STUB_URL_PATH,
            'PUT',
            request_body_deserialization=request_body_deserialization,
            response_body_deserialization=_STUB_RESPONSE_BODY_DESERIALIZATION,
        )
        connection = \
            self._make_connection_for_expected_api_call(expected_api_call)

        response_body_deserialization = connection.send_put_request(
            _STUB_URL_PATH,
            request_body_deserialization,
        )

        self._assert_sole_api_call_equals(expected_api_call, connection)
        eq_(_STUB_RESPONSE_BODY_DESERIALIZATION, response_body_deserialization)
예제 #18
0
    def __call__(self):
        if not self._contacts_by_page:
            return []

        api_calls = self._available_properties_simulator()

        for batch_contacts in self._contacts_by_page:
            request_body_deserialization = format_contacts_data_for_saving(
                batch_contacts,
                self._property_type_by_property_name,
            )
            api_call = SuccessfulAPICall(
                CONTACTS_API_SCRIPT_NAME + '/contact/batch/',
                'POST',
                request_body_deserialization=request_body_deserialization,
                response_body_deserialization=None,
            )
            api_calls.append(api_call)

        return api_calls
예제 #19
0
    def __call__(self):
        api_calls = []

        for contacts_page in self._contacts_by_page:
            request_body_deserialization = \
                {'vids': self._get_contact_vids(contacts_page)}

            updated_contacts_in_page = \
                [c for c in self._updated_contacts if c in contacts_page]
            response_body_deserialization = \
                {'updated': self._get_contact_vids(updated_contacts_in_page)}
            path_info = '/lists/{}/{}'.format(
                self._contact_list.id,
                self.url_path_list_action,
            )
            api_call = SuccessfulAPICall(
                CONTACTS_API_SCRIPT_NAME + path_info,
                'POST',
                request_body_deserialization=request_body_deserialization,
                response_body_deserialization=response_body_deserialization,
            )
            api_calls.append(api_call)

        return api_calls
예제 #20
0
from hubspot.connection.exc import HubspotAuthenticationError
from hubspot.connection.testing import MockPortalConnection
from hubspot.connection.testing import SuccessfulAPICall
from hubspot.connection.testing import UnsuccessfulAPICall

from tests.utils import assert_raises_substring
from tests.utils import get_uuid4_str

_STUB_URL_PATH = '/foo'

_STUB_RESPONSE_BODY_DESERIALIZATION = {'foo': 'bar'}

_STUB_API_CALL_1 = SuccessfulAPICall(
    _STUB_URL_PATH,
    'GET',
    response_body_deserialization=_STUB_RESPONSE_BODY_DESERIALIZATION,
)

_STUB_API_CALL_2 = SuccessfulAPICall(
    _STUB_URL_PATH,
    'POST',
    response_body_deserialization=_STUB_RESPONSE_BODY_DESERIALIZATION,
)


class TestMockPortalConnection(object):
    def test_get_request(self):
        connection = \
            self._make_connection_for_expected_api_call(_STUB_API_CALL_1)