Skip to content

Commit

Permalink
Added functionality and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacarmina committed Jan 17, 2024
1 parent 84a560e commit 7629d95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions aquarius/events/purgatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, es_instance):

def retrieve_new_list(self, env_var):
"""
:param env_var: Url of the file containing purgatory list.
:param env_var: Environment variable name of the file URL containing purgatory list.
:return: Object as follows: {...('<did>', '<reason>'),...}
"""
response = requests.get(os.getenv(env_var), timeout=5)
Expand All @@ -31,9 +31,17 @@ def retrieve_new_list(self, env_var):
logger.info(
f"PURGATORY: Successfully retrieved new purgatory list from {env_var} env var."
)
return {
(a["did"], a["reason"]) for a in response.json() if a and "did" in a
}
if env_var == "ASSET_PURGATORY_URL":
return {
(a["did"], a["reason"]) for a in response.json() if a and "did" in a
}
elif env_var == "ACCOUNT_PURGATORY_URL":
logger.info(f"response.json(): {response.json()}")
return {
(a["address"], a["reason"])
for a in response.json()
if a and "address" in a
}

logger.info(
f"PURGATORY: Failed to retrieve purgatory list from {env_var} env var."
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ env =
D:SUBGRAPH_URLS={{"8996": "http://localhost:9000"}}
D:AQUARIUS_URL=http://localhost:5000
D:EVENTS_MONITOR_SLEEP_TIME=10
D:ACCOUNT_PURGATORY_URL='https://raw.githubusercontent.com/oceanprotocol/list-purgatory/main/list-accounts.json'
8 changes: 8 additions & 0 deletions tests/test_purgatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import os
from unittest.mock import Mock, patch

from freezegun import freeze_time
Expand Down Expand Up @@ -132,6 +133,13 @@ def test_purgatory_retrieve_new_list(events_object):
assert purgatory.retrieve_new_list("env") == set()


def test_purgatory_retrieve_account_list(events_object):
purgatory = Purgatory(events_object._es_instance)
result = purgatory.retrieve_new_list("ACCOUNT_PURGATORY_URL")
print(f"result from retrieve new list: {result}")
assert result


def test_failures(events_object):
purgatory = Purgatory(events_object._es_instance)
with patch("aquarius.app.es_instance.ElasticsearchInstance.update") as mock:
Expand Down

0 comments on commit 7629d95

Please sign in to comment.