Skip to content

Commit

Permalink
Adds feedback and fixes failing validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
akolson committed Jan 12, 2024
1 parent f29bcfe commit eb0a726
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ tests/testcontent/
# Pycharm project settings
.idea/
*.iml

# pytest
.pytest_cache/
72 changes: 44 additions & 28 deletions le_utils/constants/recommendations_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,75 @@
RECOMMENDATIONSREQUESTLIST = []

SCHEMA = {
"$id": "/schemas/recommendations_request",
"$id": "/schemas/embed_request",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for recommendations API requests received by RayServe",
"description": "Schema for embed 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"},
},
"language": {
"type": "string",
"description": "The language code of the topic or channel",
"pattern": "^[a-z]{2,3}(?:-[A-Z]{2})?$",
"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]+)?$",
},
"topic": {
"type": "object",
"description": "A topic in the tree structure for which to generate recommendations",
"description": "A topic in the tree structure",
"additionalProperties": False,
"properties": {
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio",
},
"id": {"type": "string", "description": "The ID of the topic content node on Studio"},
"title": {"type": "string", "description": "The title of the topic"},
"description": {
"description": {"type": "string", "description": "The description of the topic"},
"language": {"$ref": "#/definitions/language"},
"ancestors": {"$ref": "#/definitions/ancestors"}
},
"required": ["id", "title", "description"],
},
"resource": {
"type": "object",
"description": "The key textual metadata and data for a content resource",
"additionalProperties": False,
"properties": {
"id": {"type": "string", "description": "The ID of the content resource"},
"title": {"type": "string", "description": "The title of the content resource"},
"description": {"type": "string", "description": "The description of the content resource"},
"text": {
"type": "string",
"description": "The description of the topic",
"description": "The cleaned up text extracted from the content resource (in markdown or plaintext "
"format)"
},
"language": {"$ref": "#/definitions/language"},
"ancestors": {
"type": "array",
"description": "The ancestors of the channel",
"items": {"$ref": "#/definitions/topic"},
},
},
"required": ["id", "title", "description", "language"],
"required": ["id", "title", "description", "text"]
},
},
"properties": {
"target": {"type": "string", "description": "The target topic of the channel"},
"ancestors": {
"topics": {
"type": "array",
"description": "The ancestors of the channel's target topic",
"items": {"$ref": "#/definitions/topic"},
"description": "A list of topics to embed",
"items": {"$ref": "#/definitions/topic"}
},
"resources": {
"type": "array",
"description": "A list of content resources to embed",
"items": {"$ref": "#/definitions/resource"}
},
"metadata": {
"type": "object",
"description": "The metadata of the channel for which to generate recommendations",
"additionalProperties": False,
"description": "The metadata of the channel for logging purposes",
"properties": {
"id": {"type": "string", "description": "The ID of the channel"},
"title": {"type": "string", "description": "The title of the channel"},
"language": {"$ref": "#/definitions/language"},
"channel_id": {"type": "string", "description": "The ID of the channel"},
"channel_title": {"type": "string", "description": "The title of the channel"}
},
"required": ["id", "title", "language"],
"required": ["channel_id", "channel_title"]
},
},
"required": ["target", "metadata"],
"required": ["topics", "resources"]
}
31 changes: 17 additions & 14 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,27 @@ def test_recommendations__topic__valid():
with _assert_not_raises(jsonschema.ValidationError):
validate_recommendations_request(
{
"target": {
"id": "456",
"title": "Target topic",
"description": "Target description",
"language": "en",
},
"ancestors": [
"topics": [
{
"id": "456",
"title": "Target topic",
"description": "Target description",
"language": "en"
}
],
"resources": [
{
"id": "123",
"title": "Parent title",
"description": "Parent description",
"language": "en",
"title": "Resource title",
"description": "Resource description",
"text": "Resource text",
"language": "en"
},
],
"metadata": {
"id": "000",
"title": "Channel title",
"language": "en",
},
"channel_id": "000",
"channel_title": "Channel title",
"some_additional_field": "some_random_value"
}
}
)

0 comments on commit eb0a726

Please sign in to comment.