Beispiel #1
0
class ServerEvent(BaseServerEvent):
    """Represents a common server event.

    This type of event is triggered from the django middleware on each request excluding:
    `/event`, `login`, `heartbeat`, `/segmentio/event` and `/performance`.

    Attributes:
        event_type (str): Consist of the relative URL (without the hostname) of the requested page.
            Retrieved with:
                `request.META['PATH_INFO']`
        event (str): Consist of a JSON string holding the content of the GET or POST request.
            Retrieved with:
                `json.dumps({'GET': dict(request.GET), 'POST': dict(request.POST)})[:512]`
            Note:
                Values for ['password', 'newpassword', 'new_password', 'oldpassword',
                'old_password', 'new_password1', 'new_password2'] are replaced by `********`.
                The JSON string is truncated at 512 characters resulting in invalid JSON.
    """

    __selector__ = selector(event_source="server",
                            event_type=LazyModelField("context__path"))

    # pylint: disable=unsubscriptable-object
    event_type: Path
    event: Union[Json[ServerEventField], ServerEventField]
Beispiel #2
0
class UISeqNext(BaseBrowserEvent):
    """Represents the `seq_next` browser event.

    The browser emits such event when a user selects a navigational control.
    `seq_next` is emitted when a user navigates to the next unit in a sequence.

    Attributes:
        event (obj): Consists of member fields that identify specifics triggered event.
        event_type (str): Consists of the value `seq_next`.
        name (str): Consists of the value `seq_next`.
    """

    __selector__ = selector(event_source="browser", event_type="seq_next")

    # pylint: disable=unsubscriptable-object
    event: Union[Json[NavigationalEventField], NavigationalEventField]
    event_type: Literal["seq_next"]
    name: Literal["seq_next"]

    @validator("event")
    def validate_next_jump_event_field(
        cls, value
    ):  # pylint: disable=no-self-argument, no-self-use
        """Checks that event.new is equal to event.old + 1."""

        if value.new != value.old + 1:
            raise ValueError("event.new - event.old should be equal to 1")

        return value
Beispiel #3
0
class UISeqGoto(BaseBrowserEvent):
    """Represents the `seq_goto` browser event.

    The browser emits such event when a user selects a navigational control.
    `seq_goto` is emitted when a user jumps between units in a sequence.

    Attributes:
        event (obj): Consists of member fields that identify specifics triggered event.
        event_type (str): Consists of the value `seq_goto`.
        name (str): Consists of the value `seq_goto`.
    """

    __selector__ = selector(event_source="browser", event_type="seq_goto")

    # pylint: disable=unsubscriptable-object
    event: Union[Json[NavigationalEventField], NavigationalEventField]
    event_type: Literal["seq_goto"]
    name: Literal["seq_goto"]
Beispiel #4
0
class UIPageClose(BaseBrowserEvent):
    """Represents the `page_close` browser event.

    This type of event is triggered when the user navigates to the next page
    or closes the browser window (when the JavaScript `window.onunload` event
    is called).

    Attributes:
        event (str): Consists of the string value `{}`.
        event_type (str): Consists of the value `page_close`.
        name (str): Consists of the value `page_close`.
    """

    __selector__ = selector(event_source="browser", event_type="page_close")

    # pylint: disable=unsubscriptable-object
    event: Literal["{}"]
    event_type: Literal["page_close"]
    name: Literal["page_close"]
Beispiel #5
0
class EdxCourseEnrollmentUpgradeSucceeded(BaseServerEvent):
    """Represents the `edx.course.enrollment.upgrade.succeeded` server event.

    The server emits this event when the process of upgrading a student’s
    student_courseenrollment.mode from `audit` or `honor` to `verified` is complete.

    Attributes:
        context (EdxCourseEnrollmentUpgradeSucceededContextField):
            See EdxCourseEnrollmentUpgradeSucceededContextField.
        event_type (str): Consists of the value `edx.course.enrollment.upgrade.succeeded`.
        name (str): Consists of the value `edx.course.enrollment.upgrade.succeeded`.
    """

    __selector__ = selector(
        event_source="server", event_type="edx.course.enrollment.upgrade.succeeded"
    )

    context: EdxCourseEnrollmentUpgradeSucceededContextField
    event_type: Literal["edx.course.enrollment.upgrade.succeeded"]
    name: Literal["edx.course.enrollment.upgrade.succeeded"]
Beispiel #6
0
class EdxCourseEnrollmentDeactivated(BaseServerEvent):
    """Represents the `edx.course.enrollment.deactivated` server event.

    When a student unenrolls from a course, the server emits this event.

    Attributes:
        event (EnrollmentEventField): See EnrollmentEventField.
        event_type (str): Consists of the value `edx.course.enrollment.deactivated`.
        name (str): Consists of the value `edx.course.enrollment.deactivated`.
    """

    __selector__ = selector(
        event_source="server", event_type="edx.course.enrollment.deactivated"
    )

    event: Union[
        Json[EnrollmentEventField],  # pylint: disable=unsubscriptable-object
        EnrollmentEventField,
    ]
    event_type: Literal["edx.course.enrollment.deactivated"]
    name: Literal["edx.course.enrollment.deactivated"]
Beispiel #7
0
class UIEdxCourseEnrollmentUpgradeClicked(BaseBrowserEvent):
    """Represents the `edx.course.enrollment.upgrade_clicked` browser event.

    The browser emits this event when a student clicks <kbd>ChallengeYourself</kbd> option,
    and the process of upgrading the student_courseenrollment.mode for the student
    to `verified` begins.

    Attributes:
        context (EdxCourseEnrollmentUpgradeClickedContextField):
            See EdxCourseEnrollmentUpgradeClickedContextField.
        event_type (str): Consists of the value `edx.course.enrollment.upgrade_clicked`.
        name (str): Consists of the value `edx.course.enrollment.upgrade_clicked`.
    """

    __selector__ = selector(
        event_source="browser", event_type="edx.course.enrollment.upgrade_clicked"
    )

    context: EdxCourseEnrollmentUpgradeClickedContextField
    event_type: Literal["edx.course.enrollment.upgrade_clicked"]
    name: Literal["edx.course.enrollment.upgrade_clicked"]
Beispiel #8
0
class EdxCourseEnrollmentModeChanged(BaseServerEvent):
    """Represents the `edx.course.enrollment.mode_changed` server event.

    The server emits this event when the process of changing a student’s
    student_courseenrollment.mode to a different mode is complete.

    Attributes:
        event (EnrollmentEventField): See EnrollmentEventField.
        event_type (str): Consists of the value `edx.course.enrollment.mode_changed`.
        name (str): Consists of the value `edx.course.enrollment.mode_changed`.
    """

    __selector__ = selector(
        event_source="server", event_type="edx.course.enrollment.mode_changed"
    )

    event: Union[
        Json[EnrollmentEventField],  # pylint: disable=unsubscriptable-object
        EnrollmentEventField,
    ]
    event_type: Literal["edx.course.enrollment.mode_changed"]
    name: Literal["edx.course.enrollment.mode_changed"]
Beispiel #9
0
    ModelRules,
    ModelSelector,
    Rule,
    selector,
)


@pytest.mark.parametrize(
    "model_rules,decision_tree",
    [
        # Empty model_rules => empty decision_tree.
        ({}, {}),
        # Single model, single rule case.
        (
            {
                ServerEvent: selector(event_source="server")
            },
            {
                Rule(LazyModelField("event_source"), "server"): {
                    True: ServerEvent,
                    False: None,
                }
            },
        ),
        # Single model, multiple rules case.
        (
            {
                ServerEvent:
                selector(event_source="server",
                         event_type=LazyModelField("context__path"))
            },