Skip to content

Commit

Permalink
feat: add logger in identity and authz methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cowan-macady committed Feb 10, 2023
1 parent 5ba11fc commit f3039bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
17 changes: 8 additions & 9 deletions indykite_sdk/identity/consent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from indykite_sdk.indykite.identity.v1beta2 import identity_management_api_pb2 as pb2
from indykite_sdk.model.consent import CreateConsentResponse
import sys
import indykite_sdk.utils.logger as logger


def create_consent(self, pii_processor_id, pii_principal_id, properties=[]):

sys.excepthook = logger.handle_excepthook
try:
response = self.stub.CreateConsent(
pb2.CreateConsentRequest(
Expand All @@ -13,8 +15,7 @@ def create_consent(self, pii_processor_id, pii_principal_id, properties=[]):
)
)
except Exception as exception:
print(exception)
return None
return logger.logger_error(exception)

if not response:
return None
Expand All @@ -23,7 +24,7 @@ def create_consent(self, pii_processor_id, pii_principal_id, properties=[]):


def list_consents(self, pii_principal_id):

sys.excepthook = logger.handle_excepthook
try:
streams = self.stub.ListConsents(
pb2.ListConsentsRequest(
Expand All @@ -42,23 +43,21 @@ def list_consents(self, pii_principal_id):
for response in streams:
responses.append(response)
except Exception as exception:
print(exception)
return None
return logger.logger_error(exception)

return responses


def revoke_consent(self, pii_principal_id, consent_ids=[]):

sys.excepthook = logger.handle_excepthook
try:
response = self.stub.RevokeConsent(
pb2.RevokeConsentRequest(
pii_principal_id=pii_principal_id, consent_ids=consent_ids
)
)
except Exception as exception:
print(exception)
return None
return logger.logger_error(exception)

if not response:
return None
Expand Down
20 changes: 8 additions & 12 deletions tests/test_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def test_create_consent_already_exists(capsys):

response = client.create_consent(pii_processor_id, pii_principal_id, properties)
captured = capsys.readouterr()

assert response is None
assert "consent for this PiiProcessor and PiiPrincipal combination already exist" in captured.out
assert "consent for this PiiProcessor and PiiPrincipal combination already exist" in captured.err


def test_create_consent_fail_invalid_pii_processor_id(capsys):
Expand All @@ -68,9 +66,7 @@ def test_create_consent_fail_invalid_pii_processor_id(capsys):

consent = client.create_consent(pii_processor_id, pii_principal_id, properties)
captured = capsys.readouterr()

assert consent is None
assert "invalid pii processor identifier" in captured.out
assert "invalid pii processor identifier" in captured.err


def test_consent_list_success():
Expand All @@ -86,11 +82,12 @@ def test_consent_list_success():
assert isinstance(c.consent_receipt, consent_pb2.ConsentReceipt)


def test_consent_list_no_pii():
def test_consent_list_no_pii(capsys):
client = IdentityClient()
assert client is not None

consent = client.list_consents(["bbbb"])
captured = capsys.readouterr()
assert consent is None


Expand All @@ -102,9 +99,7 @@ def test_consent_list_wrong_pii(capsys):

consent = client.list_consents(pii_principal_id)
captured = capsys.readouterr()

assert consent is None
assert "invalid pii principal" in captured.out
assert "invalid pii principal" in captured.err


def test_consent_list_empty():
Expand Down Expand Up @@ -140,14 +135,15 @@ def mocked_revoke_consent(request: pb2.RevokeConsentRequest):
assert consent_response is not None


def test_revoke_consent_wrong_consent_id():
def test_revoke_consent_wrong_consent_id(capsys):
client = IdentityClient()
assert client is not None

pii_principal_id = data.get_digital_twin()
consent_ids = ["f414b2b3-b9ed-49c3-b754e-5077d2dcdda2"]
consent_response = client.revoke_consent(pii_principal_id, consent_ids)
assert consent_response is None
captured = capsys.readouterr()
assert "invalid RevokeConsentRequest.ConsentIds" in captured.err


def test_revoke_consent_empty():
Expand Down

0 comments on commit f3039bb

Please sign in to comment.