-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: initial code for db engine * fix: fixed tests and minor fix * fix: moved nonce and state * fix: implemented logger critical errors * feature: added method set and RetrieveStatus enum * fix: fixed cache * feat: implemented cache methods in DBEngine * fix: fixed mongo cache tests * Update pyeudiw/storage/db_engine.py Co-authored-by: Giuseppe De Marco <giuseppe.demarco@teamdigitale.governo.it> * Update pyeudiw/storage/db_engine.py Co-authored-by: Giuseppe De Marco <giuseppe.demarco@teamdigitale.governo.it> * Update pyeudiw/storage/db_engine.py Co-authored-by: Giuseppe De Marco <giuseppe.demarco@teamdigitale.governo.it> * Update pyeudiw/storage/db_engine.py Co-authored-by: Giuseppe De Marco <giuseppe.demarco@teamdigitale.governo.it> * fix: minor bug fix * fix: fixed bugs on storage side of DBEngine * test: added tests for the storage side of DBEngine * fix: setted state as nullable parameter * fix: added nullable state --------- Co-authored-by: Pasquale De Rose <pasquale.de.rose@it.ey.com> Co-authored-by: Giuseppe De Marco <giuseppe.demarco@teamdigitale.governo.it>
- Loading branch information
1 parent
ac42df1
commit dcec996
Showing
8 changed files
with
214 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
from enum import Enum | ||
from typing import Callable | ||
|
||
class RetrieveStatus(Enum): | ||
RETRIEVED = 0 | ||
ADDED = 1 | ||
|
||
class BaseCache(): | ||
def try_retrieve(self, object_name: str, on_not_found: Callable[[], str]) -> dict: | ||
def try_retrieve(self, object_name: str, on_not_found: Callable[[], str]) -> tuple[dict, RetrieveStatus]: | ||
raise NotImplementedError() | ||
|
||
def overwrite(self, object_name: str, value_gen_fn: Callable[[], str]) -> dict: | ||
raise NotImplementedError() | ||
|
||
def set(self, data: dict) -> dict: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import uuid | ||
import pytest | ||
|
||
from pyeudiw.storage.db_engine import DBEngine | ||
|
||
conf = { | ||
"mongo_db": { | ||
"cache": { | ||
"module": "pyeudiw.storage.mongo_cache", | ||
"class": "MongoCache", | ||
"init_params": { | ||
"url": "mongodb://localhost:27017/", | ||
"conf": { | ||
"db_name": "eudiw" | ||
}, | ||
"connection_params": {} | ||
} | ||
}, | ||
"storage": { | ||
"module": "pyeudiw.storage.mongo_storage", | ||
"class": "MongoStorage", | ||
"init_params": { | ||
"url": "mongodb://localhost:27017/", | ||
"conf": { | ||
"db_name": "eudiw", | ||
"db_collection": "sessions" | ||
}, | ||
"connection_params": {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
class TestMongoDBEngine: | ||
@pytest.fixture(autouse=True) | ||
def create_engine_instance(self): | ||
self.engine = DBEngine(conf) | ||
|
||
@pytest.fixture(autouse=True) | ||
def test_init_session(self): | ||
dpop_proof = {"dpop": "dpop"} | ||
attestation = {"attestation": "attestation"} | ||
|
||
document_id = self.engine.init_session(dpop_proof, attestation) | ||
|
||
assert document_id | ||
|
||
self.document_id = document_id | ||
|
||
@pytest.fixture(autouse=True) | ||
def test_update_request_object(self): | ||
self.nonce = str(uuid.uuid4()) | ||
self.state = str(uuid.uuid4()) | ||
request_object = {"request_object": "request_object"} | ||
|
||
r_nonce, r_state, _ = self.engine.update_request_object(self.document_id, self.nonce, self.state, request_object) | ||
|
||
assert self.nonce == r_nonce | ||
assert self.state == r_state | ||
|
||
def test_update_request_object_with_unexistent_id_object(self): | ||
nonce = str(uuid.uuid4()) | ||
state = str(uuid.uuid4()) | ||
unx_document_id = str(uuid.uuid4()) | ||
request_object = {"request_object": "request_object"} | ||
|
||
try: | ||
self.engine.update_request_object(unx_document_id, nonce, state, request_object) | ||
except: | ||
return | ||
|
||
def test_update_response_object(self): | ||
response_object = {"response_object": "response_object"} | ||
self.engine.update_response_object(self.nonce, self.state, response_object) | ||
|
||
def test_update_response_object_unexistent_id_object(self): | ||
response_object = {"response_object": "response_object"} | ||
|
||
try: | ||
replica_count = self.engine.update_response_object(str(uuid.uuid4()), str(uuid.uuid4()), response_object) | ||
except: | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.