Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quest schema #133

Merged
merged 2 commits into from
Jul 18, 2019
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
228 changes: 228 additions & 0 deletions test/quest_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "A representation of an Old School RuneScape (OSRS) quest",

"definitions": {
"requirements.skills": {
"type": "object",
"required": [ "skill", "level", "boostable" ],
"properties": {
"skill": {
"type": "string",
"description": "The name of the required skill.",
"enum": [ "attack", "strength", "defence", "ranged", "prayer", "magic", "runecrafting", "hitpoints", "crafting", "mining", "smithing", "fishing", "cooking", "firemaking", "woodcutting", "agility", "herblore", "thieving", "fletching", "slayer", "farming", "construction", "hunter" ]
},
"level": {
"type": "integer",
"description": "The skill level requirement to start a quest."
},
"boostable": {
"type": "boolean",
"description": "The boostability of a skill level to start a quest."
}
}
},
"rewards.skills": {
"type": "object",
"required": [ "skill", "xp" ],
"properties": {
"skill": {
"type": "string",
"description": "The name of the rewarded skill.",
"enum": [ "attack", "strength", "defence", "ranged", "prayer", "magic", "runecrafting", "hitpoints", "crafting", "mining", "smithing", "fishing", "cooking", "firemaking", "woodcutting", "agility", "herblore", "thieving", "fletching", "slayer", "farming", "construction", "hunter" ]
},
"xp": {
"type": "integer",
"description": "The XP reward in a specific skill for completing the quest."
}
}
},
"items": {
"type": "object",
"required": [ "id", "quantity" ],
"properties": {
"id": {
"type": "integer",
"description": "The ID of the item required"
},
"quantity" : {
"type": "integer",
"description": "The quantity of an item requied"
}
}
}
},

"title": "Quest Properties",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"members": {
"type": "boolean"
},
"release_date": {
"type": "string",
"format": "date"
},
"series": {
"type": "array",
"items": {
"type": "string"
}
},
"developers": {
"type": "array",
"items": {
"type": "string"
}
},
"start_point": {
"type": "string"
},
"difficulty": {
"type": "string"
},
"length": {
"type": "string"
},
"description": {
"type": "string"
},
"url_quest_image": {
"type": "string",
"format": "uri"
},
"url_quest_guide_full": {
"type": "string",
"format": "uri"
},
"url_quest_guide_quick": {
"type": "string",
"format": "uri"
},
"required_for_completing": {
"type": "array",
"items": {
"type": "number"
}
},
"quest_trivia": {
"type": "array",
"items": {
"type": "string"
}
},
"requirements": {
"description": "Quest Requirements",
"type": "object",
"properties": {
"quest_points": {
"description": "The number of quest points required to start the quest.",
"type": "integer"
},
"quests": {
"description": "The quests that are required to start the quest",
"type": "array",
"items": {
"type": "number"
}
},
"skills": {
"description": "The skill name, level and boostability required to start the quest.",
"type": "array",
"items": { "$ref": "#/definitions/requirements.skills" }
},
"items_required": {
"description": "The items and associated quantity required for the quest.",
"type": "array",
"items": { "$ref": "#/definitions/items" }
},
"items_recommended": {
"description": "The items and associated quantity recommended for the quest.",
"type": "array",
"items": { "$ref": "#/definitions/items" }
},
"enemies_to_defeat": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
"quest_points",
"quests",
"skills",
"items_required",
"items_recommended",
"enemies_to_defeat"
]
},
"rewards": {
"description": "Quest Rewards",
"type": "object",
"properties": {
"quest_points": {
"description": "The quest points rewarded for completing the quest.",
"type": "integer"
},
"coins": {
"description": "The coins rewarded for completing the quest.",
"type": "integer"
},
"items": {
"description": "The items rewarded for completing the quest.",
"type": "array",
"items": { "$ref": "#/definitions/items" }
},
"skills": {
"description": "The skill and XP rewards for completing the quest.",
"type": "array",
"items": { "$ref": "#/definitions/rewards.skills" }
},
"misc": {
"title": "Quest Rewards Misc",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"quest_points",
"coins",
"items",
"skills",
"misc"
]
}
},
"required": [
"id",
"name",
"type",
"members",
"release_date",
"series",
"developer",
"start_point",
"difficulty",
"length",
"description",
"url_quest_image",
"url_quest_guide_full",
"url_quest_guide_quick",
"required_for_completing",
"quest_trivia",
"requirements",
"rewards"
]
}
53 changes: 53 additions & 0 deletions test/test_quests_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Author: PH01L
Email: phoil@osrsbox.com
Website: https://www.osrsbox.com

Description:
Tests for module: osrsbox.quests_api.all_quests

Copyright (c) 2019, PH01L

###############################################################################
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
###############################################################################
"""

import json
from pathlib import Path

import pytest
import jsonschema


@pytest.mark.skip(reason="Skipped: The quest data is not currently populated.")
def test_quests_data(path_to_docs_dir: Path):
"""Unit test to check quests database contents against JSON schema

:param path_to_docs_dir: The path to the `docs` folder.
"""
# Read in the quest_schema.json file
path_to_schema = Path("test/quest_schema.json")
with open(path_to_schema, 'r') as f:
schema = json.loads(f.read())

# Set the path to the quests-json folder and get all the JSON files
path_to_quests_json_dir = Path(f"{path_to_docs_dir}/quests-json")
fis = path_to_quests_json_dir.glob("*.json")
fis = sorted(fis)

# Validate each file
for json_file in fis:
with open(json_file) as fi:
item = json.load(fi)
# print(item["id"])
jsonschema.validate(instance=item, schema=schema)