Skip to content

funfedi_parsing_test_cases.cases

ActivityTestCase dataclass

Activity test case

Parameters:

Name Type Description Default
activity dict
required
object_id str
required
Source code in funfedi_parsing_test_cases/cases/activity.py
@dataclass
class ActivityTestCase:
    """Activity test case"""

    activity: dict
    object_id: str

ActivityTestCaseMaker dataclass

Creates an Activity test case

Parameters:

Name Type Description Default
object_maker Callable[list, dict]
<function default_object_maker at 0x7f199b829170>
activity_maker Callable[list, dict]
<function default_activity_maker at 0x7f199b829590>
Source code in funfedi_parsing_test_cases/cases/activity.py
@dataclass
class ActivityTestCaseMaker:
    """Creates an Activity test case"""

    object_maker: Callable[[Environment], dict] = default_object_maker
    activity_maker: Callable[[Environment, dict], dict] = default_activity_maker

    def activity_and_object(self, environment: Environment) -> tuple[dict, dict]:
        obj = self.object_maker(environment)
        activity = self.activity_maker(environment, obj)
        return activity, obj

    def to_send(self, environment: Environment) -> ActivityTestCase:
        #
        # Might want to return object_id instead of activity, as it is what is used
        # to lookup later
        #
        # Also activity might be a lie as one might have an activity in an activity
        #
        activity, obj = self.activity_and_object(environment)

        object_id = obj.get("id")
        if not isinstance(object_id, str):
            raise InvalidTestCaseException(
                "Only test cases where the object has an id are supported"
            )

        return ActivityTestCase(activity, object_id)

default_activity_maker

default_activity_maker(
    environment: Environment, obj: dict
) -> dict
>>> from funfedi_parsing_test_cases.testing import default_env
>>> obj = default_object_maker(default_env)
>>> default_activity_maker(default_env, obj)
{'@context': ['https://www.w3.org/ns/activitystreams'],
    'actor': 'http://host.test/some/actor',
    'id': '...
    'object': ...
    'published': '...
    'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
    'cc': [],
    'type': 'Create'}
Source code in funfedi_parsing_test_cases/cases/defaults.py
def default_activity_maker(environment: Environment, obj: dict) -> dict:
    """
    ```python
    >>> from funfedi_parsing_test_cases.testing import default_env
    >>> obj = default_object_maker(default_env)
    >>> default_activity_maker(default_env, obj)
    {'@context': ['https://www.w3.org/ns/activitystreams'],
        'actor': 'http://host.test/some/actor',
        'id': '...
        'object': ...
        'published': '...
        'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
        'cc': [],
        'type': 'Create'}

    ```
    """
    return {
        "@context": [
            "https://www.w3.org/ns/activitystreams",
        ],
        "actor": environment.sending_actor,
        "id": environment.id_maker("activities"),
        "object": obj,
        "published": now_isoformat(),
        "to": [
            "https://www.w3.org/ns/activitystreams#Public",
            environment.receiving_actor,
        ],
        "cc": [],
        "type": "Create",
    }

default_event_maker

default_event_maker(environment: Environment) -> dict
>>> from funfedi_parsing_test_cases.testing import default_env
>>> default_event_maker(default_env)
{'@context': ['https://www.w3.org/ns/activitystreams'],
    'id': '...
    'type': 'Event',
    'attributedTo': 'http://host.test/some/actor',
    'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
    'cc': [],
    'published': '...
    'content': 'event content',
    'name': 'my event',
    'startTime': '...
    'endTime': '...
    'location': {'type': 'VirtualLocation', 'url': 'http://localhost'}}
Source code in funfedi_parsing_test_cases/cases/defaults.py
def default_event_maker(environment: Environment) -> dict:
    """
    ```python
    >>> from funfedi_parsing_test_cases.testing import default_env
    >>> default_event_maker(default_env)
    {'@context': ['https://www.w3.org/ns/activitystreams'],
        'id': '...
        'type': 'Event',
        'attributedTo': 'http://host.test/some/actor',
        'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
        'cc': [],
        'published': '...
        'content': 'event content',
        'name': 'my event',
        'startTime': '...
        'endTime': '...
        'location': {'type': 'VirtualLocation', 'url': 'http://localhost'}}

    ```
    """

    return {
        **base_object(environment, "Event"),
        "content": "event content",
        "name": "my event",
        "startTime": to_iso(
            datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=4)
        ),
        "endTime": to_iso(
            datetime.datetime.now(tz=datetime.timezone.utc)
            + datetime.timedelta(days=4, hours=3)
        ),
        "location": {"type": "VirtualLocation", "url": "http://localhost"},
    }

default_object_maker

default_object_maker(environment: Environment) -> dict
>>> from funfedi_parsing_test_cases.testing import default_env
>>> default_object_maker(default_env)
{'@context': ['https://www.w3.org/ns/activitystreams'],
    'id': '...
    'type': 'Note',
    'attributedTo': 'http://host.test/some/actor',
    'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
    'cc': [],
    'published': '...
    'content': 'text',
    'tag': [{'type': 'Mention', 'href': 'http://other.test/some/actor'}]}
Source code in funfedi_parsing_test_cases/cases/defaults.py
def default_object_maker(environment: Environment) -> dict:
    """
    ```python
    >>> from funfedi_parsing_test_cases.testing import default_env
    >>> default_object_maker(default_env)
    {'@context': ['https://www.w3.org/ns/activitystreams'],
        'id': '...
        'type': 'Note',
        'attributedTo': 'http://host.test/some/actor',
        'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
        'cc': [],
        'published': '...
        'content': 'text',
        'tag': [{'type': 'Mention', 'href': 'http://other.test/some/actor'}]}

    ```
    """
    return {
        **base_object(environment, "Note"),
        "content": "text",
        "tag": [{"type": "Mention", "href": environment.receiving_actor}],
    }

default_poll_maker

default_poll_maker(environment: Environment) -> dict
>>> from funfedi_parsing_test_cases.testing import default_env
>>> default_poll_maker(default_env)
{'@context': ['https://www.w3.org/ns/activitystreams'],
    'id': '...
    'type': 'Question',
    'attributedTo': 'http://host.test/some/actor',
    'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
    'cc': [],
    'published': '...
    'content': '<p>Question</p>',
    'endTime': '...
    'updated': '...
    'oneOf': [{'type': 'Note', 'name': 'Answer 1', 'replies': {'type': 'Collection', 'totalItems': 0}},
        {'type': 'Note', 'name': 'Answer 2', 'replies': {'type': 'Collection', 'totalItems': 0}}]}
Source code in funfedi_parsing_test_cases/cases/defaults.py
def default_poll_maker(environment: Environment) -> dict:
    """
    ```python
    >>> from funfedi_parsing_test_cases.testing import default_env
    >>> default_poll_maker(default_env)
    {'@context': ['https://www.w3.org/ns/activitystreams'],
        'id': '...
        'type': 'Question',
        'attributedTo': 'http://host.test/some/actor',
        'to': ['https://www.w3.org/ns/activitystreams#Public', 'http://other.test/some/actor'],
        'cc': [],
        'published': '...
        'content': '<p>Question</p>',
        'endTime': '...
        'updated': '...
        'oneOf': [{'type': 'Note', 'name': 'Answer 1', 'replies': {'type': 'Collection', 'totalItems': 0}},
            {'type': 'Note', 'name': 'Answer 2', 'replies': {'type': 'Collection', 'totalItems': 0}}]}

    ```
    """

    return {
        **base_object(environment, "Question"),
        "content": "<p>Question</p>",
        "endTime": to_iso(
            datetime.datetime.now() + datetime.timedelta(days=4, hours=3)
        ),
        "updated": to_iso(datetime.datetime.now()),
        "oneOf": [
            {
                "type": "Note",
                "name": "Answer 1",
                "replies": {"type": "Collection", "totalItems": 0},
            },
            {
                "type": "Note",
                "name": "Answer 2",
                "replies": {"type": "Collection", "totalItems": 0},
            },
        ],
    }