Skip to content

Commit

Permalink
Merge pull request #121 from akolson/add-level-property-to-ancestors
Browse files Browse the repository at this point in the history
Add level property to ancestors
  • Loading branch information
bjester authored Feb 2, 2024
2 parents 669d9b3 + 55fe5d4 commit ce8adcf
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 40 deletions.
65 changes: 53 additions & 12 deletions js/EmbedTopicsRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,75 @@ export const SCHEMA = {
"description": "Schema for embed topics requests received by RayServe",
"additionalProperties": false,
"definitions": {
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {
"$ref": "#/definitions/topic"
}
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
},
"title": {
"type": "string",
"description": "The title of the topic"
},
"description": {
"type": "string",
"description": "The description of the topic"
},
"language": {
"type": "string",
"description": "Language code from https://github.com/learningequality/le-utils/blob/main/le_utils/resources/languagelookup.json",
"pattern": "^[a-z]{2,3}(?:-[a-zA-Z]+)?$"
},
"level": {
"type": "integer",
"description": "The level of the ancestor, where the root is 0 and the parent is the highest level"
},
"ancestor": {
"type": "object",
"description": "An ancestor in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"$ref": "#/definitions/id"
},
"title": {
"$ref": "#/definitions/title"
},
"description": {
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
},
"level": {
"$ref": "#/definitions/level"
}
},
"required": [
"id",
"title",
"description",
"level"
]
},
"ancestors": {
"type": "array",
"description": "The ancestors of the topic. Please see 'level' in the ancestor schema for more information",
"items": {
"$ref": "#/definitions/ancestor"
}
},
"topic": {
"type": "object",
"description": "A topic in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
"$ref": "#/definitions/id"
},
"title": {
"type": "string",
"description": "The title of the topic"
"$ref": "#/definitions/title"
},
"description": {
"type": "string",
"description": "The description of the topic"
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "0.2.4"
"version": "0.2.5"
}
46 changes: 33 additions & 13 deletions le_utils/constants/embed_topics_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,50 @@
"description": "Schema for embed topics requests received by RayServe",
"additionalProperties": False,
"definitions": {
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {"$ref": "#/definitions/topic"},
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio",
},
"title": {"type": "string", "description": "The title of the topic"},
"description": {
"type": "string",
"description": "The description of the topic",
},
"language": {
"type": "string",
"description": "Language code from https://github.com/learningequality/le-utils/blob/main/le_utils/resources/languagelookup.json",
"pattern": "^[a-z]{2,3}(?:-[a-zA-Z]+)?$",
},
"level": {
"type": "integer",
"description": "The level of the ancestor, where the root is 0 and the parent is the highest level",
},
"ancestor": {
"type": "object",
"description": "An ancestor in the tree structure",
"additionalProperties": False,
"properties": {
"id": {"$ref": "#/definitions/id"},
"title": {"$ref": "#/definitions/title"},
"description": {"$ref": "#/definitions/description"},
"language": {"$ref": "#/definitions/language"},
"level": {"$ref": "#/definitions/level"},
},
"required": ["id", "title", "description", "level"],
},
"ancestors": {
"type": "array",
"description": "The ancestors of the topic. Please see 'level' in the ancestor schema for more information",
"items": {"$ref": "#/definitions/ancestor"},
},
"topic": {
"type": "object",
"description": "A topic in the tree structure",
"additionalProperties": False,
"properties": {
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio",
},
"title": {"type": "string", "description": "The title of the topic"},
"description": {
"type": "string",
"description": "The description of the topic",
},
"id": {"$ref": "#/definitions/id"},
"title": {"$ref": "#/definitions/title"},
"description": {"$ref": "#/definitions/description"},
"language": {"$ref": "#/definitions/language"},
"ancestors": {"$ref": "#/definitions/ancestors"},
},
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name="le-utils",
packages=find_packages(),
version="0.2.4",
version="0.2.5",
description="LE-Utils contains shared constants used in Kolibri, Ricecooker, and Kolibri Studio.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
65 changes: 53 additions & 12 deletions spec/schema-embed_topics_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,75 @@
"description": "Schema for embed topics requests received by RayServe",
"additionalProperties": false,
"definitions": {
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {
"$ref": "#/definitions/topic"
}
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
},
"title": {
"type": "string",
"description": "The title of the topic"
},
"description": {
"type": "string",
"description": "The description of the topic"
},
"language": {
"type": "string",
"description": "Language code from https://github.com/learningequality/le-utils/blob/main/le_utils/resources/languagelookup.json",
"pattern": "^[a-z]{2,3}(?:-[a-zA-Z]+)?$"
},
"level": {
"type": "integer",
"description": "The level of the ancestor, where the root is 0 and the parent is the highest level"
},
"ancestor": {
"type": "object",
"description": "An ancestor in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"$ref": "#/definitions/id"
},
"title": {
"$ref": "#/definitions/title"
},
"description": {
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
},
"level": {
"$ref": "#/definitions/level"
}
},
"required": [
"id",
"title",
"description",
"level"
]
},
"ancestors": {
"type": "array",
"description": "The ancestors of the topic. Please see 'level' in the ancestor schema for more information",
"items": {
"$ref": "#/definitions/ancestor"
}
},
"topic": {
"type": "object",
"description": "A topic in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
"$ref": "#/definitions/id"
},
"title": {
"type": "string",
"description": "The title of the topic"
"$ref": "#/definitions/title"
},
"description": {
"type": "string",
"description": "The description of the topic"
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
Expand Down
33 changes: 32 additions & 1 deletion tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_completion_criteria__reference__invalid():


@pytest.mark.skipif(jsonschema is None, reason="jsonschema package is unavailable")
def test_embed__topics__valid():
def test_embed__topics__without__ancestors__valid():
with _assert_not_raises(jsonschema.ValidationError):
validate_embed_topics_request(
{
Expand All @@ -293,6 +293,37 @@ def test_embed__topics__valid():
)


@pytest.mark.skipif(jsonschema is None, reason="jsonschema package is unavailable")
def test_embed__topics__with__ancestors__valid():
with _assert_not_raises(jsonschema.ValidationError):
validate_embed_topics_request(
{
"topics": [
{
"id": "456",
"title": "Target topic",
"description": "Target description",
"language": "en",
"ancestors": [
{
"id": "456",
"title": "Parent topic",
"description": "Parent description",
"language": "en",
"level": 1,
}
],
}
],
"metadata": {
"channel_id": "000",
"channel_title": "Channel title",
"some_additional_field": "some_random_value",
},
}
)


@pytest.mark.skipif(jsonschema is None, reason="jsonschema package is unavailable")
def test_embed__content__valid():
with _assert_not_raises(jsonschema.ValidationError):
Expand Down

0 comments on commit ce8adcf

Please sign in to comment.