Enable dummy mode

This commit is contained in:
Mark Veidemanis 2023-04-19 10:12:16 +01:00
parent 2b7e83dc0d
commit da5d1badd8
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 107 additions and 41 deletions

View File

@ -41,6 +41,8 @@ ELASTICSEARCH_INDEX_ADS = getenv("ELASTICSEARCH_INDEX_ADS", "ads")
DEBUG = getenv("DEBUG", "false").lower() in trues
PROFILER = getenv("PROFILER", "false").lower() in trues
DUMMY = getenv("DUMMY", "false").lower() in trues
if DEBUG:
import socket # only if you haven't already imported this

View File

@ -28,6 +28,10 @@ class LocalPlatformClient(ABC):
async def connect(self):
self.api = AgoraDesk(self.instance.token)
if settings.DUMMY:
log.info(
"DUMMY: Dummy mode is enabled. Destructive commands will be printed."
)
async def call_method(self, method, *args, **kwargs):
"""
@ -471,7 +475,11 @@ class LocalPlatformClient(ABC):
assets.add(asset)
currencies.add(currency)
if not actioned:
if not settings.DUMMY:
rtrn = await self.api.ad_equation(ad_id, new_formula)
else:
log.debug(f"DUMMY: ad_equation({ad_id}, {new_formula})")
rtrn = {"success": True}
if rtrn["success"]:
ads[ad_index][4] = True
throttled = 0
@ -511,7 +519,11 @@ class LocalPlatformClient(ABC):
if ads is False:
return False
for ad_id in ads:
if not settings.DUMMY:
rtrn = await self.api.ad_delete(ad_id)
else:
log.debug(f"DUMMY: ad_delete({ad_id})")
rtrn = {"success": True}
return_ids.append(rtrn["success"])
return all(return_ids)
@ -589,12 +601,20 @@ class LocalPlatformClient(ABC):
form["max_amount"] = round(max_amount, 2)
if edit:
if not settings.DUMMY:
ad_response = await self.api.ad(ad_id=ad_id, **form)
else:
log.debug(f"DUMMY: ad({ad_id}, {form})")
ad_response = {"success": True}
if ad_response["success"]:
self.instance.platform_ad_ids[ad_id] = str(ad.id)
self.instance.save()
else:
if not settings.DUMMY:
ad_response = await self.api.ad_create(**form)
else:
log.debug(f"DUMMY: ad_create({form})")
ad_response = {"success": True}
if ad_response["success"]:
ad_id = ad_response["response"]["data"]["ad_id"]
self.instance.platform_ad_ids[ad_id] = str(ad.id)
@ -630,6 +650,7 @@ class LocalPlatformClient(ABC):
if currency not in supported_currencies:
continue
# Create the actual ad and pass in all the stuff
if not settings.DUMMY:
rtrn = await self.create_ad(
asset,
countrycode,
@ -638,6 +659,12 @@ class LocalPlatformClient(ABC):
payment_details=account_info[currency],
ad=ad,
)
else:
log.debug(
f"DUMMY: create_ad({asset}, {countrycode}, {currency}, "
f"{provider}, {account_info[currency]}, {ad})"
)
rtrn = {"success": True}
# Bail on first error, let's not continue
if rtrn is False:
return False
@ -671,6 +698,7 @@ class LocalPlatformClient(ABC):
if currency in supported_currencies:
if currency not in account_info:
continue
if not settings.DUMMY:
rtrn = await self.create_ad(
asset,
countrycode,
@ -682,6 +710,13 @@ class LocalPlatformClient(ABC):
edit=True,
ad_id=ad_id,
)
else:
log.debug(
f"DUMMY: create_ad({asset}, {countrycode}, {currency}, "
f"{provider}, {account_info[currency]}, {ad}, "
f"{ad.visible}, True, {ad_id})"
)
rtrn = {"success": True}
# Bail on first error, let's not continue
if rtrn is False:
return False
@ -711,7 +746,11 @@ class LocalPlatformClient(ABC):
actioned = []
print("repeated", repeated)
for ad_id, country, currency in repeated:
if not settings.DUMMY:
rtrn = await self.api.ad_delete(ad_id)
else:
log.debug(f"DUMMY: ad_delete({ad_id})")
rtrn = {"success": True}
actioned.append(rtrn["success"])
print("actioned", actioned)
@ -723,9 +762,18 @@ class LocalPlatformClient(ABC):
title = "Releasing escrow"
await notify.sendmsg(self.instance.user, logmessage, title=title)
if not settings.DUMMY:
rtrn = await self.release_funds(trade_id)
else:
log.debug(f"DUMMY: release_funds({trade_id})")
rtrn = {"message": "OK"}
if rtrn["message"] == "OK":
await self.api.contact_message_post(trade_id, "Thanks! Releasing now :)")
if not settings.DUMMY:
await self.api.contact_message_post(
trade_id, "Thanks! Releasing now :)"
)
else:
log.debug(f"DUMMY: contact_message_post({trade_id}, 'Thanks!')")
return True
else:
logmessage = f"Release funds unsuccessful: {rtrn['message']}"
@ -925,6 +973,9 @@ class LocalPlatformClient(ABC):
"""
Send the reference to a customer.
"""
if settings.DUMMY:
log.debug(f"DUMMY: Sending reference {reference} to {trade_id}")
return
if self.instance.send is True:
await self.api.contact_message_post(
trade_id,
@ -944,10 +995,15 @@ class LocalPlatformClient(ABC):
if not formatted_account_info:
log.error(f"Payment info invalid: {formatted_account_info}")
return
if not settings.DUMMY:
await self.api.contact_message_post(
trade_id,
f"Payment details: \n{formatted_account_info}",
)
else:
log.debug(
f"DUMMY: contact_message_post({trade_id}, {formatted_account_info})"
)
def get_all_assets(self, platform):
raise Exception
@ -1225,6 +1281,7 @@ class LocalPlatformClient(ABC):
currency = ad[3]
provider = ad[4]
ad_id = ad[1]
if not settings.DUMMY:
await self.create_ad(
asset,
countrycode,
@ -1236,6 +1293,13 @@ class LocalPlatformClient(ABC):
edit=True,
ad_id=ad_id,
)
else:
log.debug(
(
f"DUMMY: create_ad({ad_id}, {asset}, {countrycode}, {currency},"
f" {provider}, False, None, False, True, {ad_id})"
)
)
def format_ad(self, asset, currency, payment_details_text, ad):
"""