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

Feat/discourse null values #340

Merged
merged 2 commits into from
Dec 16, 2024
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
11 changes: 8 additions & 3 deletions dags/analyzer_helper/discourse/transform_raw_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,27 @@ def transform_member(self, member: dict) -> dict:
avatar_template: str = member["avatar"]

avatar: str
if avatar_template.startswith(("http://", "https://")):
if avatar_template is not None and avatar_template.startswith(
("http://", "https://")
):
avatar = avatar_template
elif avatar_template is not None:
avatar = "https://" + self.endpoint + avatar_template
else:
avatar = None

avatar = avatar.replace("{size}", "128") if avatar else None
joined_at = member.get("joined_at")

member = {
"id": str(int(discourse_id)) if discourse_id is not None else None,
"is_bot": member.get("isBot", False),
"left_at": None,
"joined_at": self.converter.from_date_string(member.get("joined_at")),
"joined_at": (
self.converter.from_date_string(joined_at) if joined_at else None
),
"options": {
"name": member["name"] if member["name"] is not "null" else None,
"name": member["name"] if member["name"] != "null" else None,
"username": member["username"],
"avatar": avatar,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,36 @@ def test_transform_single_member(self):
result = self.transformer.transform([raw_member])
self.assertEqual(result, expected_result)

def test_transform_single_member_null_name(self):
"""
Tests that transform correctly transforms a single member
"""
raw_member = {
"id": 85149,
"joined_at": "2023-07-02",
"isBot": False,
"name": "null",
"username": "memberUser1",
"avatar": "/path1/{size}/endpoint",
}

expected_result = [
{
"id": "85149",
"is_bot": False,
"left_at": None,
"joined_at": datetime(2023, 7, 2, 0, 0, 0, 0, tzinfo=timezone.utc),
"options": {
"name": None,
"username": "memberUser1",
"avatar": "https://" + self.endpoint + "/path1/128/endpoint",
},
}
]

result = self.transformer.transform([raw_member])
self.assertEqual(result, expected_result)

def test_transform_multiple_members(self):
"""
Tests that transform correctly transforms multiple members
Expand Down
Loading