Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to
### Fixed

- Fix type of `statement.result.score.scaled` from `int` to `Decimal`
- Fix optional `member` field in Identified Groups not actually being optional
- Fix misregistered `TypeError` in Pydantic models validation
- Fix `check-changelog` CI job by replacing the removed `git whatchanged`
command with `git log --name-only`
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/models/xapi/base/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BaseXapiIdentifiedGroup(BaseXapiGroupCommonProperties):
member (list): Consist of a list of the members of this Group.
"""

member: Optional[List[BaseXapiAgent]]
member: Optional[List[BaseXapiAgent]] = None


class BaseXapiIdentifiedGroupWithMbox(BaseXapiIdentifiedGroup, BaseXapiMboxIFI):
Expand Down
59 changes: 58 additions & 1 deletion tests/models/xapi/base/test_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""Tests for the base xAPI `Group` definitions."""

from ralph.models.xapi.base.groups import BaseXapiGroupCommonProperties
import pytest
from pydantic import ValidationError

from ralph.models.xapi.base.groups import (
BaseXapiGroupCommonProperties,
BaseXapiIdentifiedGroupWithMbox,
BaseXapiIdentifiedGroupWithMboxSha1Sum,
)

from tests.factories import mock_xapi_instance

Expand All @@ -12,3 +19,53 @@ def test_models_xapi_base_groups_group_common_properties_with_valid_field():
field = mock_xapi_instance(BaseXapiGroupCommonProperties)

assert field.objectType == "Group"


@pytest.mark.parametrize(
"group",
[
{
"name": "d75662f7c72c8d12267712aaf31b649cdab13cb8",
"mbox_sha1sum": "6395037c217b04eae94355900bcaf014772c7d7c",
"objectType": "Group",
},
{
"name": "d75662f7c72c8d12267712aaf31b649cdab13cb8",
"mbox_sha1sum": "6395037c217b04eae94355900bcaf014772c7d7c",
"objectType": "Group",
"member": [],
},
],
)
def test_models_xapi_base_group_mbox_sha1sum_valid(group):
"""Test an invalid group with `mbox_sha1sum` property"""

try:
BaseXapiIdentifiedGroupWithMboxSha1Sum(**group)
except ValidationError as err:
pytest.fail(f"Valid statement should not raise exceptions: {err}")


@pytest.mark.parametrize(
"group",
[
{
"name": "d75662f7c72c8d12267712aaf31b649cdab13cb8",
"mbox": "mailto:foob@r.com",
"objectType": "Group",
},
{
"name": "d75662f7c72c8d12267712aaf31b649cdab13cb8",
"mbox": "mailto:foob@r.com",
"objectType": "Group",
"member": [],
},
],
)
def test_models_xapi_base_group_mbox_valid(group):
"""Test an invalid group with `mbox` property"""

try:
BaseXapiIdentifiedGroupWithMbox(**group)
except ValidationError as err:
pytest.fail(f"Valid statement should not raise exceptions: {err}")