Skip to content

Commit

Permalink
Merge pull request #340 from TogetherCrew/feat/discourse-null-values
Browse files Browse the repository at this point in the history
Feat/discourse null values
  • Loading branch information
amindadgar authored Dec 16, 2024
2 parents 08321e6 + 3c271a9 commit b1006e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
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

0 comments on commit b1006e7

Please sign in to comment.