Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(types): socialAccount creating from string for username + tests

dextmorgn3ad9e72ca1c4
diff --git a/flowsint-types/src/flowsint_types/social_account.py b/flowsint-types/src/flowsint_types/social_account.py
index f9245ea2..1981d9f2 100644
--- a/flowsint-types/src/flowsint_types/social_account.py
+++ b/flowsint-types/src/flowsint_types/social_account.py
@@ -16,6 +16,14 @@ class SocialAccount(FlowsintType):
json_schema_extra={"primary": True}
)
username: Username = Field(..., description="Username associated with this account", title="Username")
+
+ @field_validator('username', mode='before')
+ @classmethod
+ def convert_username(cls, v: Union[str, Username]) -> Username:
+ """Convert string to Username object if needed."""
+ if isinstance(v, str):
+ return Username(value=v)
+ return v
display_name: Optional[str] = Field(None, description="Display name or full name on the profile", title="Display name")
profile_url: Optional[str] = Field(None, description="URL to the account profile page", title="Profile URL")
profile_picture_url: Optional[str] = Field(None, description="URL to the profile avatar/picture", title="Image URL")
diff --git a/flowsint-types/tests/test_socialaccount.py b/flowsint-types/tests/test_socialaccount.py
new file mode 100644
index 00000000..d837652f
--- /dev/null
+++ b/flowsint-types/tests/test_socialaccount.py
@@ -0,0 +1,19 @@
+from flowsint_types import Username, SocialAccount
+
+
+def test_social_account_from_type():
+ username = Username(value="johndoe")
+ account = SocialAccount(
+ username=username, display_name="John Doe", platform="twitter"
+ )
+ assert account.label == "John Doe (@johndoe)"
+ assert account.username.value == "johndoe"
+
+
+def test_social_account_from_string():
+ account = SocialAccount(
+ # insert username as string instead of obj
+ username="johndoe", display_name="John Doe", platform="twitter"
+ )
+ assert account.label == "John Doe (@johndoe)"
+ assert account.username.value == "johndoe"