Skip to content
Snippets Groups Projects
Commit ec74f0ab authored by supersonicwisd1's avatar supersonicwisd1
Browse files

refactor models

Signed-off-by: supersonicwisd1 <supersonicwisd1>
parent 287d78ca
Branches
No related tags found
1 merge request!6Model Definition and Testing for ActivityPub (Code Structure Changed)
aiohappyeyeballs==2.4.3
aiohttp==3.10.10
aioredis==2.0.1
aiosignal==1.3.1
annotated-types==0.7.0
async-timeout==5.0.0
attrs==24.2.0
cffi==1.17.1
cryptography==43.0.3
factory_boy==3.3.1
Faker==30.8.0
frozenlist==1.4.1
greenlet==3.1.1
idna==3.10
iniconfig==2.0.0
multidict==6.1.0
packaging==24.1
pluggy==1.5.0
prometheus_client==0.21.0
propcache==0.2.0
pycparser==2.22
pydantic==2.9.2
pydantic_core==2.23.4
PyJWT==2.9.0
pytest==8.3.3
pytest-asyncio==0.24.0
python-dateutil==2.9.0.post0
redis==5.2.0
six==1.16.0
SQLAlchemy==2.0.36
typing_extensions==4.12.2
yarl==1.15.2
...@@ -9,7 +9,7 @@ https://www.w3.org/TR/activitystreams-vocabulary/#activity-types ...@@ -9,7 +9,7 @@ https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
from pydantic import Field, HttpUrl from pydantic import Field, HttpUrl
from typing import Optional, Union, Literal, Dict, Any from typing import Optional, Union, Literal, Dict, Any
from .objects import APObject from pyfed.models.objects import APObject
class APActivity(APObject): class APActivity(APObject):
""" """
......
...@@ -12,7 +12,7 @@ from pydantic import Field, HttpUrl, field_validator ...@@ -12,7 +12,7 @@ from pydantic import Field, HttpUrl, field_validator
from typing import Optional, List, Dict, Any, TypedDict, Literal from typing import Optional, List, Dict, Any, TypedDict, Literal
from datetime import datetime from datetime import datetime
from pyfed.utils.exceptions import InvalidURLError from pyfed.utils.exceptions import InvalidURLError
from pyfed.plugins import plugin_manager # from pyfed.plugins import plugin_manager
from pyfed.utils.logging import get_logger from pyfed.utils.logging import get_logger
from pyfed.cache import object_cache from pyfed.cache import object_cache
...@@ -79,7 +79,7 @@ class APActor(APObject): ...@@ -79,7 +79,7 @@ class APActor(APObject):
""" """
logger.info(f"Sending activity to inbox: {self.inbox}") logger.info(f"Sending activity to inbox: {self.inbox}")
# Execute pre-send hook # Execute pre-send hook
plugin_manager.execute_hook('pre_send_to_inbox', self, activity) # plugin_manager.execute_hook('pre_send_to_inbox', self, activity)
# Placeholder for actual implementation # Placeholder for actual implementation
return True return True
...@@ -99,7 +99,7 @@ class APActor(APObject): ...@@ -99,7 +99,7 @@ class APActor(APObject):
return cached_followers return cached_followers
# Execute pre-fetch hook # Execute pre-fetch hook
plugin_manager.execute_hook('pre_fetch_followers', self) # plugin_manager.execute_hook('pre_fetch_followers', self)
# Fetch followers (placeholder implementation) # Fetch followers (placeholder implementation)
followers = [] # Actual implementation would go here followers = [] # Actual implementation would go here
......
...@@ -10,10 +10,10 @@ https://www.w3.org/TR/activitystreams-core/#collections ...@@ -10,10 +10,10 @@ https://www.w3.org/TR/activitystreams-core/#collections
from __future__ import annotations from __future__ import annotations
from typing import Optional, List, Union, Literal, Dict, Any from typing import Optional, List, Union, Literal, Dict, Any
from pydantic import Field, HttpUrl from pydantic import Field, HttpUrl
from .objects import APObject from pyfed.models.objects import APObject
import logging from pyfed.utils.logging import get_logger
logger = logging.getLogger(__name__) logger = get_logger(__name__)
class APCollection(APObject): class APCollection(APObject):
""" """
......
...@@ -9,7 +9,7 @@ https://www.w3.org/TR/activitystreams-vocabulary/#link ...@@ -9,7 +9,7 @@ https://www.w3.org/TR/activitystreams-vocabulary/#link
from pydantic import Field, HttpUrl, field_validator from pydantic import Field, HttpUrl, field_validator
from typing import Optional, List, Literal from typing import Optional, List, Literal
from ..serializers.json_serializer import ActivityPubBase from pyfed.serializers.json_serializer import ActivityPubBase
class APLink(ActivityPubBase): class APLink(ActivityPubBase):
""" """
......
...@@ -11,7 +11,7 @@ from ..serializers.json_serializer import ActivityPubBase ...@@ -11,7 +11,7 @@ from ..serializers.json_serializer import ActivityPubBase
from pydantic import Field, HttpUrl, field_validator, model_validator from pydantic import Field, HttpUrl, field_validator, model_validator
from typing import Optional, List, Union, Literal, Dict from typing import Optional, List, Union, Literal, Dict
from datetime import datetime from datetime import datetime
from .links import APLink from pyfed.models.links import APLink
class APObject(ActivityPubBase): class APObject(ActivityPubBase):
"""Base class for all ActivityPub objects. """Base class for all ActivityPub objects.
......
...@@ -9,7 +9,7 @@ from typing import Any, Dict ...@@ -9,7 +9,7 @@ from typing import Any, Dict
from pydantic import BaseModel from pydantic import BaseModel
from pydantic_core import Url from pydantic_core import Url
from ..utils.logging import get_logger from ..utils.logging import get_logger
from ..plugins import plugin_manager # from ..plugins import plugin_manager
logger = get_logger(__name__) logger = get_logger(__name__)
...@@ -73,7 +73,7 @@ class ActivityPubSerializer: ...@@ -73,7 +73,7 @@ class ActivityPubSerializer:
logger.debug("Serializing object") logger.debug("Serializing object")
# Execute pre-serialize hook # Execute pre-serialize hook
plugin_manager.execute_hook('pre_serialize', obj) # plugin_manager.execute_hook('pre_serialize', obj)
# Convert to dictionary and convert keys to camelCase # Convert to dictionary and convert keys to camelCase
data = convert_dict_keys_to_camel_case(obj.model_dump()) data = convert_dict_keys_to_camel_case(obj.model_dump())
......
...@@ -5,7 +5,7 @@ This module tests that all necessary modules can be imported correctly. ...@@ -5,7 +5,7 @@ This module tests that all necessary modules can be imported correctly.
import pytest import pytest
from pyfed.serializers.json_serializer import ActivityPubSerializer from pyfed.serializers.json_serializer import ActivityPubSerializer
from pyfed.plugins import plugin_manager # Updated import path # from pyfed.plugins import plugin_manager # Updated import path
from pyfed.models import ( from pyfed.models import (
APObject, APEvent, APPlace, APProfile, APRelationship, APTombstone, APObject, APEvent, APPlace, APProfile, APRelationship, APTombstone,
APArticle, APAudio, APDocument, APImage, APNote, APPage, APVideo, APArticle, APAudio, APDocument, APImage, APNote, APPage, APVideo,
...@@ -66,6 +66,6 @@ def test_can_import_serializer(): ...@@ -66,6 +66,6 @@ def test_can_import_serializer():
"""Test that the serializer can be imported.""" """Test that the serializer can be imported."""
assert ActivityPubSerializer assert ActivityPubSerializer
def test_can_import_plugin_manager(): # def test_can_import_plugin_manager():
"""Test that the plugin manager can be imported.""" # """Test that the plugin manager can be imported."""
assert plugin_manager # assert plugin_manager
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment