-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added discord raw data channel filtering!
- Adjusted the codes to support channel filtering within Module database. - Note that we would have `Module` as database and `modules` as table name.
- Loading branch information
1 parent
4eea2bf
commit f5805b9
Showing
4 changed files
with
357 additions
and
31 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
117 changes: 117 additions & 0 deletions
117
dags/hivemind_etl_helpers/tests/integration/test_discord_fetch_modules_channels.py
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,117 @@ | ||
from unittest import TestCase | ||
from bson import ObjectId | ||
|
||
from datetime import datetime, timedelta | ||
from hivemind_etl_helpers.src.utils.mongo import MongoSingleton | ||
from hivemind_etl_helpers.src.db.discord.fetch_raw_messages import fetch_channels | ||
|
||
|
||
class TestDiscordFetchModulesChannels(TestCase): | ||
def setup_db( | ||
self, | ||
channels: list[str], | ||
create_modules: bool = True, | ||
create_platform: bool = True, | ||
guild_id: str = "1234", | ||
): | ||
client = MongoSingleton.get_instance().client | ||
|
||
community_id = ObjectId("9f59dd4f38f3474accdc8f24") | ||
platform_id = ObjectId("063a2a74282db2c00fbc2428") | ||
|
||
client["Module"].drop_collection("modules") | ||
client["Core"].drop_collection("platforms") | ||
|
||
if create_modules: | ||
data = { | ||
"name": "hivemind", | ||
"communityId": community_id, | ||
"options": { | ||
"platforms": [ | ||
{ | ||
"platformId": platform_id, | ||
"options": { | ||
"channels": channels, | ||
"roles": ["role_id"], | ||
"users": ["user_id"], | ||
}, | ||
} | ||
] | ||
}, | ||
} | ||
client["Module"]["modules"].insert_one(data) | ||
|
||
if create_platform: | ||
client["Core"]["platforms"].insert_one( | ||
{ | ||
"_id": platform_id, | ||
"name": "discord", | ||
"metadata": { | ||
"action": { | ||
"INT_THR": 1, | ||
"UW_DEG_THR": 1, | ||
"PAUSED_T_THR": 1, | ||
"CON_T_THR": 4, | ||
"CON_O_THR": 3, | ||
"EDGE_STR_THR": 5, | ||
"UW_THR_DEG_THR": 5, | ||
"VITAL_T_THR": 4, | ||
"VITAL_O_THR": 3, | ||
"STILL_T_THR": 2, | ||
"STILL_O_THR": 2, | ||
"DROP_H_THR": 2, | ||
"DROP_I_THR": 1, | ||
}, | ||
"window": {"period_size": 7, "step_size": 1}, | ||
"id": guild_id, | ||
"isInProgress": False, | ||
"period": datetime.now() - timedelta(days=35), | ||
"icon": "some_icon_hash", | ||
"selectedChannels": channels, | ||
"name": "GuildName", | ||
}, | ||
"community": community_id, | ||
"disconnectedAt": None, | ||
"connectedAt": datetime.now(), | ||
"createdAt": datetime.now(), | ||
"updatedAt": datetime.now(), | ||
} | ||
) | ||
|
||
def test_fetch_channels(self): | ||
guild_id = "1234" | ||
channels = ["111111", "22222"] | ||
self.setup_db( | ||
create_modules=True, | ||
create_platform=True, | ||
guild_id=guild_id, | ||
channels=channels, | ||
) | ||
channels = fetch_channels(guild_id="1234") | ||
|
||
self.assertEqual(channels, channels) | ||
|
||
def test_fetch_channels_no_modules_available(self): | ||
guild_id = "1234" | ||
channels = ["111111", "22222"] | ||
self.setup_db( | ||
create_modules=False, | ||
create_platform=True, | ||
guild_id=guild_id, | ||
channels=channels, | ||
) | ||
with self.assertRaises(ValueError): | ||
_ = fetch_channels(guild_id="1234") | ||
|
||
def test_fetch_channels_no_platform_available(self): | ||
guild_id = "1234" | ||
channels = ["111111", "22222"] | ||
self.setup_db( | ||
create_modules=True, | ||
create_platform=False, | ||
guild_id=guild_id, | ||
channels=channels, | ||
) | ||
|
||
with self.assertRaises(ValueError): | ||
_ = fetch_channels(guild_id="1234") |
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
Oops, something went wrong.