Skip to content

Commit

Permalink
with metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dantavori committed Feb 1, 2024
1 parent 1d07421 commit e1b9936
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Packs/EmailHippo/Integrations/EmailHippo/EmailHippo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ def get_email_reputation(self, email: str) -> dict[str, Any]:
dict: dict containing the Email reputation as returned from the API
"""

return self._http_request(method='GET',
full_url=f'{self._more_server_url}/v3/more/json/{self._more_api_key}/{email}')
return self._http_request(
method='GET',
full_url=f'{self._more_server_url}/v3/more/json/{self._more_api_key}/{email}',
with_metrics=True,
)

def get_domain_reputation(self, domain: str) -> dict[str, Any]:
"""
Expand All @@ -61,16 +64,23 @@ def get_domain_reputation(self, domain: str) -> dict[str, Any]:
dict: dict containing the domain reputation as returned from the API.
"""

return self._http_request(method='GET', full_url=f'{self._whois_server_url}/{domain}')
return self._http_request(
method='GET',
full_url=f'{self._whois_server_url}/{domain}',
with_metrics=True,
)

def get_email_quota(self) -> dict[str, Any]:
"""
Get the email quota remaining for the API key
"""
return self._http_request(method='GET',
full_url=f'{self._more_server_url}/customer/reports/v3/quota/{self._more_api_key}')
return self._http_request(
method='GET',
full_url=f'{self._more_server_url}/customer/reports/v3/quota/{self._more_api_key}',
with_metrics=True,
)

def determine_error_type(self, res: Response) -> ErrorTypes:
def determine_error_type(self, res: Response):
""" Determines the error type based on response.
Args:
Expand Down
38 changes: 38 additions & 0 deletions Packs/EmailHippo/Integrations/EmailHippo/EmailHippo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,41 @@ def test_get_email_reputation_failure_quota_limit(self, requests_mock, client: C
with pytest.raises(DemistoException):
client.get_email_reputation('[email protected]')
assert client.execution_metrics.quota_error == 1

def test_get_email_reputation_failure_auth_error(self, requests_mock, client: Client):
"""
Given:
a Client instance and a mocked failed auth limit API response
When:
get_email_reputation is called with a valid email address
Then:
- a DemistoException is raised
- matrix auth_error increased
"""
requests_mock.get(
'https://test.com/v3/more/json/test/[email protected]',
status_code=401,
)

with pytest.raises(DemistoException):
client.get_email_reputation('[email protected]')
assert client.execution_metrics.auth_error == 1

def test_get_email_reputation_failure_general_error(self, requests_mock, client: Client):
"""
Given:
a Client instance and a mocked 400 API response
When:
get_email_reputation is called with a valid email address
Then:
- a DemistoException is raised
- matrix general_error increased
"""
requests_mock.get(
'https://test.com/v3/more/json/test/[email protected]',
status_code=400,
)

with pytest.raises(DemistoException):
client.get_email_reputation('[email protected]')
assert client.execution_metrics.general_error == 1

0 comments on commit e1b9936

Please sign in to comment.