def __init__(self, start_date, credentials, **kwargs): self._start_date = start_date self._api = API(credentials=credentials) common_params = dict(api=self._api, start_date=self._start_date) self._apis = { "campaigns": CampaignStream(**common_params), "companies": CRMObjectStream(entity="company", associations=["contacts"], **common_params), "contact_lists": ContactListStream(**common_params), "contacts": CRMObjectStream(entity="contact", **common_params), "deal_pipelines": DealPipelineStream(**common_params), "deals": CRMObjectStream(entity="deal", **common_params), "email_events": EmailEventStream(**common_params), "engagements": EngagementStream(**common_params), "forms": FormStream(**common_params), "line_items": CRMObjectStream(entity="line_item", **common_params), "owners": OwnerStream(**common_params), "products": CRMObjectStream(entity="product", **common_params), "quotes": CRMObjectStream(entity="quote", **common_params), "subscription_changes": SubscriptionChangeStream(**common_params), "tickets": CRMObjectStream(entity="ticket", **common_params), "workflows": WorkflowStream(**common_params), } super().__init__(**kwargs)
def test_wrong_permissions_api_key(requests_mock, creds_with_wrong_permissions): """ Error with API Key Permissions to particular stream, typically this issue raises along with calling `workflows` stream with API Key that doesn't have required permissions to read the stream. """ # Define stream name stream_name = "workflows" # Mapping tipical response for mocker responses = [{ "json": { "status": "error", "message": f'This hapikey ({creds_with_wrong_permissions.get("api_key")}) does not have proper permissions! (requires any of [automation-access])', "correlationId": "2fe0a9af-3609-45c9-a4d7-83a1774121aa", } }] # We expect something like this expected_warining_message = { "type": "LOG", "log": { "level": "WARN", "message": f'Stream `workflows` cannot be procced. This hapikey ({creds_with_wrong_permissions.get("api_key")}) does not have proper permissions! (requires any of [automation-access])', }, } # create base parent instances client = Client(start_date="2021-02-01T00:00:00Z", credentials=creds_with_wrong_permissions) api = API(creds_with_wrong_permissions) # Create test_stream instance test_stream = client._apis.get(stream_name) # Mocking Request requests_mock.register_uri("GET", test_stream.url, responses) # Mock the getter method that handles requests. def get(url=test_stream.url, params=None): response = api._session.get(api.BASE_URL + url, params=params) return api._parse_and_handle_errors(response) # Define request params value params = {"limit": 100, "properties": ""} # Read preudo-output from generator object _read(), based on real scenario list(test_stream._read(getter=get, params=params)) # match logged expected logged warning message with output given from preudo-output assert expected_warining_message
def __init__(self, start_date, credentials, **kwargs): self._start_date = start_date self._api = API(credentials=credentials) common_params = dict(api=self._api, start_date=self._start_date) self._apis = { "campaigns": CampaignStream(**common_params), "companies": CRMObjectIncrementalStream(entity="company", associations=["contacts"], **common_params), "contact_lists": ContactListStream(**common_params), "contacts": CRMObjectIncrementalStream(entity="contact", **common_params), "contacts_list_memberships": ContactsListMembershipsStream(**common_params), "deal_pipelines": DealPipelineStream(**common_params), "deals": DealStream(associations=["contacts"], **common_params), "email_events": EmailEventStream(**common_params), "engagements": EngagementStream(**common_params), "forms": FormStream(**common_params), "form_submissions": FormSubmissionStream(**common_params), "line_items": CRMObjectIncrementalStream(entity="line_item", **common_params), "marketing_emails": MarketingEmailStream(**common_params), "owners": OwnerStream(**common_params), "products": CRMObjectIncrementalStream(entity="product", **common_params), "subscription_changes": SubscriptionChangeStream(**common_params), "tickets": CRMObjectIncrementalStream(entity="ticket", **common_params), "workflows": WorkflowStream(**common_params), } credentials_title = credentials.get("credentials_title") if credentials_title == "API Key Credentials": self._apis["quotes"] = CRMObjectIncrementalStream(entity="quote", **common_params) super().__init__(**kwargs)
def api(self, some_credentials): return API(some_credentials)