-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resourse DB+ Upload check validations+ (#42)
* Resourse DB+ Upload check validations+ * Update src/regps/app/fastapi_app.py --------- Co-authored-by: Lance <lance.byrd@gleif.org>
- Loading branch information
Showing
4 changed files
with
179 additions
and
10 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
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,33 @@ | ||
from collections import defaultdict | ||
|
||
|
||
class ReportsDB: | ||
def __init__(self): | ||
self.aid_reports = defaultdict(list) | ||
self.lei_reports = defaultdict(list) | ||
self.aid_to_lei_mapping = dict() | ||
self.lei_digests = defaultdict(set) | ||
|
||
def register_aid(self, aid, lei): | ||
self.aid_to_lei_mapping[aid] = lei | ||
|
||
def add_report(self, aid, dig, report): | ||
lei = self.aid_to_lei_mapping[aid] or "-" | ||
self.aid_reports[aid].append(report) | ||
self.lei_reports[lei].append(report) | ||
self.lei_digests[lei].add(dig) | ||
|
||
def drop_status(self, aid): | ||
self.aid_reports[aid] = [] | ||
return True | ||
|
||
def get_reports_for_aid(self, aid): | ||
return self.aid_reports[aid] | ||
|
||
def get_reports_for_lei(self, aid): | ||
lei = self.aid_to_lei_mapping[aid] or "-" | ||
return self.lei_reports[lei] | ||
|
||
def authorized_to_check_status(self, aid, dig): | ||
lei = self.aid_to_lei_mapping[aid] or "-" | ||
return dig in self.lei_digests[lei] |
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,65 @@ | ||
from regps.app.api.utils.reports_db import ReportsDB | ||
|
||
|
||
def test_check_report_status_authorization(): | ||
aid = "jnhh8f7h79nufb97hbw3fieBHJBgg7uhn" | ||
lei = "j9h7ufehhcWBUTDVWYH98h9bfyaebgGBFfsa3wFf" | ||
report_1 = "report 1" | ||
dig_1 = "sha256_moiuhLFBf9afnHJDfaffg4ehgh" | ||
report_2 = "report 2" | ||
dig_2 = "sha256_fer4grniuojnfaNHBBcaaUh89h" | ||
reports_db = ReportsDB() | ||
reports_db.register_aid(aid, lei) | ||
reports_db.add_report(aid, dig_1, report_1) | ||
reports_db.add_report(aid, dig_2, report_2) | ||
assert reports_db.authorized_to_check_status(aid, dig_1) | ||
assert reports_db.authorized_to_check_status(aid, dig_2) | ||
assert len(reports_db.get_reports_for_aid(aid)) == 2 | ||
assert len(reports_db.get_reports_for_lei(aid)) == 2 | ||
|
||
|
||
def test_check_report_status_authorization_2_aids_from_the_same_lei(): | ||
aid_1 = "jnhh8f7h79nufb97hbw3fieBHJBgg7uhn" | ||
aid_2 = "UNBOUb8dadh98hnansudHD0jndbuh8hnd" | ||
lei = "j9h7ufehhcWBUTDVWYH98h9bfyaebgGBFfsa3wFf" | ||
report_1 = "report 1" | ||
dig_1 = "sha256_moiuhLFBf9afnHJDfaffg4ehgh" | ||
report_2 = "report 2" | ||
dig_2 = "sha256_fer4grniuojnfaNHBBcaaUh89h" | ||
reports_db = ReportsDB() | ||
reports_db.register_aid(aid_1, lei) | ||
reports_db.register_aid(aid_2, lei) | ||
reports_db.add_report(aid_1, dig_1, report_1) | ||
reports_db.add_report(aid_2, dig_2, report_2) | ||
assert reports_db.authorized_to_check_status(aid_1, dig_1) | ||
assert reports_db.authorized_to_check_status(aid_1, dig_2) | ||
assert reports_db.authorized_to_check_status(aid_2, dig_1) | ||
assert reports_db.authorized_to_check_status(aid_2, dig_2) | ||
assert len(reports_db.get_reports_for_aid(aid_1)) == 1 | ||
assert len(reports_db.get_reports_for_aid(aid_2)) == 1 | ||
assert len(reports_db.get_reports_for_lei(aid_1)) == 2 | ||
assert len(reports_db.get_reports_for_lei(aid_2)) == 2 | ||
|
||
|
||
def test_check_report_status_authorization_2_aids_from_different_lei(): | ||
aid_1 = "jnhh8f7h79nufb97hbw3fieBHJBgg7uhn" | ||
aid_2 = "UNBOUb8dadh98hnansudHD0jndbuh8hnd" | ||
lei_1 = "j9h7ufehhcWBUTDVWYH98h9bfyaebgGBFfsa3wFf" | ||
lei_2 = "mOI8hbsah80hihSHFIHh8h3r8hf8h08hfaiffha0" | ||
report_1 = "report 1" | ||
dig_1 = "sha256_moiuhLFBf9afnHJDfaffg4ehgh" | ||
report_2 = "report 2" | ||
dig_2 = "sha256_fer4grniuojnfaNHBBcaaUh89h" | ||
reports_db = ReportsDB() | ||
reports_db.register_aid(aid_1, lei_1) | ||
reports_db.register_aid(aid_2, lei_2) | ||
reports_db.add_report(aid_1, dig_1, report_1) | ||
reports_db.add_report(aid_2, dig_2, report_2) | ||
assert reports_db.authorized_to_check_status(aid_1, dig_1) | ||
assert not reports_db.authorized_to_check_status(aid_1, dig_2) | ||
assert not reports_db.authorized_to_check_status(aid_2, dig_1) | ||
assert reports_db.authorized_to_check_status(aid_2, dig_2) | ||
assert len(reports_db.get_reports_for_aid(aid_1)) == 1 | ||
assert len(reports_db.get_reports_for_aid(aid_2)) == 1 | ||
assert len(reports_db.get_reports_for_lei(aid_1)) == 1 | ||
assert len(reports_db.get_reports_for_lei(aid_2)) == 1 |