Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Updated the automations saga schema! #57

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion automation/automation_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pybars import Compiler
from tc_messageBroker.rabbit_mq.event import Event
from tc_messageBroker.rabbit_mq.queue import Queue
from utils.get_guild_utils import get_guild_platform_id


class AutomationWorkflow(AutomationBase):
Expand Down Expand Up @@ -194,8 +195,9 @@ def _prepare_saga_data(
message : str
the message to send the user
"""
platform_id = get_guild_platform_id(guild_id)
data = {
"guildId": guild_id,
"platformId": platform_id,
"created": False,
"discordId": user_id,
"message": message,
Expand Down
2 changes: 1 addition & 1 deletion discord_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from automation.automation_workflow import AutomationWorkflow
from tc_messageBroker.rabbit_mq.saga.saga_base import get_saga
from utils.daolytics_uitls import get_mongo_credentials, get_saga_db_location
from utils.get_guild_community_ids import get_guild_community_ids
from utils.get_guild_utils import get_guild_community_ids
from utils.get_rabbitmq import prepare_rabbit_mq
from utils.transactions_ordering import sort_transactions

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_get_guild_community_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest import TestCase

from bson.objectid import ObjectId
from utils.get_guild_community_ids import get_guild_community_ids
from utils.get_guild_utils import get_guild_community_ids
from utils.get_mongo_client import MongoSingleton


Expand Down
55 changes: 55 additions & 0 deletions tests/integration/test_get_guild_platform_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from datetime import datetime
from unittest import TestCase

from bson.objectid import ObjectId
from utils.get_guild_utils import get_guild_platform_id
from utils.get_mongo_client import MongoSingleton


class TestGetGuildId(TestCase):
def test_get_avalable_guild(self):
client = MongoSingleton.get_instance().client
platform_id = ObjectId("515151515151515151515151")
guild_id = "999888877766655"

client.drop_database("Core")
client["Core"]["platforms"].insert_one(
{
"_id": ObjectId(platform_id),
"name": "discord",
"metadata": {
"id": guild_id,
"icon": "111111111111111111111111",
"name": "A guild",
"selectedChannels": [
"11111111",
"22222222",
"33333333",
"44444444",
"55555555",
"66666666",
"77777777",
],
"period": datetime(2023, 6, 1),
},
"community": ObjectId("aabbccddeeff001122334455"),
"disconnectedAt": None,
"connectedAt": datetime(2023, 11, 1),
"isInProgress": True,
"createdAt": datetime(2023, 11, 1),
"updatedAt": datetime(2023, 11, 1),
"__v": 0,
}
)

platform_id = get_guild_platform_id(guild_id)
self.assertEqual(platform_id, "515151515151515151515151")

def test_no_document_raise_error(self):
client = MongoSingleton.get_instance().client
guild_id = "999888877766655"

client.drop_database("Core")

with self.assertRaises(ValueError):
get_guild_platform_id(guild_id)
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ def test_analyzer_member_activities_from_start_empty_memberactivities():
# testing whether any data is available
assert memberactivities_data is not None
assert heatmaps_data is not None
assert guild_document["isInProgress"] is False
assert guild_document["metadata"]["isInProgress"] is False
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def test_analyzer_member_activities_from_start_available_heatmaps():
# testing whether any data is available
assert memberactivities_data is not None
assert heatmaps_data is not None
assert guild_document["isInProgress"] is False
assert guild_document["metadata"]["isInProgress"] is False
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def test_analyzer_member_activities_from_start_available_member_activity():
# testing whether any data is available
assert memberactivities_data is not None
assert heatmaps_data is not None
assert guild_document["isInProgress"] is False
assert guild_document["metadata"]["isInProgress"] is False
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def test_analyzer_from_start_one_interval():
# testing whether any data is available
assert memberactivities_data is not None
assert heatmaps_data is not None
assert guild_document["isInProgress"] is False
assert guild_document["metadata"]["isInProgress"] is False
27 changes: 27 additions & 0 deletions utils/get_guild_community_ids.py → utils/get_guild_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,30 @@ def get_guild_community_ids(platform_id: str) -> tuple[str, str]:
guild_id = platform["metadata"]["id"]
community_id = str(platform["community"])
return guild_id, community_id


def get_guild_platform_id(guild_id: str) -> str:
"""
get the guild platform id using the given guild id

Parameters
------------
guild_id : str
the id for the specified guild

Returns
--------
platform_id : str
the platform id related to the given guild
"""
mongo_client = MongoSingleton.get_instance().client

guild_info = mongo_client["Core"]["platforms"].find_one(
{"metadata.id": guild_id}, {"_id": 1}
)
if guild_info is not None:
platform_id = str(guild_info["_id"])
else:
raise ValueError(f"No available guild with id {guild_id}")

return platform_id