Skip to content

Commit

Permalink
Adds single filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
calina-c committed Apr 6, 2022
1 parent 282a4ae commit 971d26a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions aquarius/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from json import JSONDecodeError
import logging
import os
import requests
from web3.main import Web3

from aquarius.app.auth_util import sanitize_addresses
Expand All @@ -23,6 +24,15 @@ def sanitize_record(data_record):
if "_id" in data_record:
data_record.pop("_id")

if os.getenv("RBAC_SERVER_URL"):
payload = {
"eventType": "filter_single_result",
"component": "metadatacache",
"ddo": data_record,
}

return requests.post(os.getenv("RBAC_SERVER_URL"), json=payload).json()

return json.dumps(data_record, default=datetime_converter)


Expand Down
15 changes: 14 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import json
import logging
import os
from requests.models import Response
from datetime import datetime
from unittest.mock import patch
from unittest.mock import patch, Mock

import pytest

Expand Down Expand Up @@ -112,6 +113,18 @@ def test_sanitize_record():
assert result["other_value"] == "something else"


def test_sanitize_record_through_rbac(monkeypatch):
monkeypatch.setenv("RBAC_SERVER_URL", "test")

with patch("requests.post") as mock:
response = Mock(spec=Response)
response.json.return_value = {"this_is": "SPARTAAA!"}
mock.return_value = response

result = sanitize_record({})
assert result["this_is"] == "SPARTAAA!"


class BlockProcessingClassChild(BlockProcessingClass):
def get_last_processed_block(self):
raise Exception("BAD!")
Expand Down

0 comments on commit 971d26a

Please sign in to comment.