Adds schema tests to intl json

This commit is contained in:
Carl Beekhuizen 2021-04-07 13:12:35 +02:00
parent c61f197277
commit a92890a4f6
No known key found for this signature in database
GPG Key ID: 8F29E54F49E7AAB5
8 changed files with 460 additions and 0 deletions

View File

@ -107,3 +107,6 @@ iniconfig==1.0.1 \
toml==0.10.1 \
--hash=sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f \
--hash=sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88
jsonschema==3.2.0 \
--hash=sha256:4e5b3cf8216f577bee9ce139cbe72eca3ea4f292ec60928ff24758ce626cd163 \
--hash=sha256:c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a

View File

@ -0,0 +1,100 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"validate_mnemonic": {
"type": "object",
"properties": {
"err_invalid_mnemonic": {
"type": "string"
}
},
"required": [
"err_invalid_mnemonic"
]
},
"existing_mnemonic": {
"type": "object",
"properties": {
"arg_existing_mnemonic": {
"type": "object",
"properties": {
"help": {
"type": "string"
}
},
"required": [
"help"
]
},
"arg_mnemonic": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"help": {
"type": "string"
},
"prompt": {
"type": "string"
}
},
"required": [
"argument",
"help",
"prompt"
]
},
"arg_mnemonic_password": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"help": {
"type": "string"
}
},
"required": [
"argument",
"help"
]
},
"arg_validator_start_index": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"help": {
"type": "string"
},
"prompt": {
"type": "string"
}
},
"required": [
"argument",
"help",
"prompt"
]
},
"msg_mnemonic_password_confirm": {
"type": "string"
}
},
"required": [
"arg_existing_mnemonic",
"arg_mnemonic",
"arg_mnemonic_password",
"arg_validator_start_index",
"msg_mnemonic_password_confirm"
]
}
},
"required": [
"validate_mnemonic",
"existing_mnemonic"
]
}

View File

@ -0,0 +1,140 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"validate_password": {
"type": "object",
"properties": {
"msg_password_prompt": {
"type": "string"
},
"msg_password_confirm": {
"type": "string"
},
"err_password_mismatch": {
"type": "string"
}
},
"required": [
"msg_password_prompt",
"msg_password_confirm",
"err_password_mismatch"
]
},
"generate_keys_arguments_decorator": {
"type": "object",
"properties": {
"num_validators": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"help": {
"type": "string"
},
"prompt": {
"type": "string"
}
},
"required": [
"argument",
"help",
"prompt"
]
},
"folder": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"help": {
"type": "string"
}
},
"required": [
"argument",
"help"
]
},
"chain": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"help": {
"type": "string"
},
"prompt": {
"type": "string"
}
},
"required": [
"argument",
"help",
"prompt"
]
},
"keystore_password": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"help": {
"type": "string"
},
"prompt": {
"type": "string"
}
},
"required": [
"argument",
"help",
"prompt"
]
}
},
"required": [
"num_validators",
"folder",
"chain",
"keystore_password"
]
},
"generate_keys": {
"type": "object",
"properties": {
"msg_key_creation": {
"type": "string"
},
"msg_creation_success": {
"type": "string"
},
"msg_pause": {
"type": "string"
},
"err_verify_keystores": {
"type": "string"
},
"err_verify_deposit": {
"type": "string"
}
},
"required": [
"msg_key_creation",
"msg_creation_success",
"msg_pause",
"err_verify_keystores",
"err_verify_deposit"
]
}
},
"required": [
"validate_password",
"generate_keys_arguments_decorator",
"generate_keys"
]
}

View File

@ -0,0 +1,64 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"new_mnemonic": {
"type": "object",
"properties": {
"arg_new_mnemonic": {
"type": "object",
"properties": {
"help": {
"type": "string"
}
},
"required": [
"help"
]
},
"arg_mnemonic_language": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"default": {
"type": "string"
},
"help": {
"type": "string"
},
"prompt": {
"type": "string"
}
},
"required": [
"argument",
"default",
"help",
"prompt"
]
},
"msg_mnemonic_presentation": {
"type": "string"
},
"msg_press_any_key": {
"type": "string"
},
"msg_mnemonic_retype_prompt": {
"type": "string"
}
},
"required": [
"arg_new_mnemonic",
"arg_mnemonic_language",
"msg_mnemonic_presentation",
"msg_press_any_key",
"msg_mnemonic_retype_prompt"
]
}
},
"required": [
"new_mnemonic"
]
}

View File

@ -0,0 +1,56 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"from_mnemonic": {
"type": "object",
"properties": {
"msg_key_creation": {
"type": "string"
}
},
"required": [
"msg_key_creation"
]
},
"export_keystores": {
"type": "object",
"properties": {
"msg_keystore_creation": {
"type": "string"
}
},
"required": [
"msg_keystore_creation"
]
},
"export_deposit_data_json": {
"type": "object",
"properties": {
"msg_depositdata_creation": {
"type": "string"
}
},
"required": [
"msg_depositdata_creation"
]
},
"verify_keystores": {
"type": "object",
"properties": {
"msg_keystore_verification": {
"type": "string"
}
},
"required": [
"msg_keystore_verification"
]
}
},
"required": [
"from_mnemonic",
"export_keystores",
"export_deposit_data_json",
"verify_keystores"
]
}

View File

@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"check_python_version": {
"type": "object",
"properties": {
"err_python_version": {
"type": "string"
}
},
"required": [
"err_python_version"
]
}
},
"required": [
"check_python_version"
]
}

View File

@ -0,0 +1,32 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"verify_deposit_data_json": {
"type": "object",
"properties": {
"msg_deposit_verification": {
"type": "string"
}
},
"required": [
"msg_deposit_verification"
]
},
"validate_password_strength": {
"type": "object",
"properties": {
"msg_password_length": {
"type": "string"
}
},
"required": [
"msg_password_length"
]
}
},
"required": [
"verify_deposit_data_json",
"validate_password_strength"
]
}

View File

@ -0,0 +1,45 @@
import json
import jsonschema
import os
import pytest
import re
from typing import (
List,
)
from eth2deposit.utils.constants import INTL_CONTENT_PATH
TEST_SCHEMAS_FOLDER = os.path.join(os.path.dirname(__file__), 'schemas')
def files_to_check(root_dir: str) -> List[str]:
file_list = []
for dir_, _, files in os.walk(root_dir):
for file_name in files:
rel_dir = os.path.relpath(dir_, root_dir)
rel_file = os.path.join(rel_dir, file_name)
file_list.append(rel_file)
return file_list
def languages_to_check(root_dir: str) -> List[str]:
dirs = next(os.walk(root_dir))[1]
regex = re.compile('([A-Za-z]){2}(-([A-Za-z]){2})?')
return [d for d in dirs if re.fullmatch(regex, d)]
@pytest.mark.parametrize(
'lang, schema_path',
[
(lang, schema)
for schema in files_to_check(TEST_SCHEMAS_FOLDER)
for lang in languages_to_check(INTL_CONTENT_PATH)
]
)
def test_language_schemas(lang: str, schema_path: str) -> None:
with open(os.path.join(TEST_SCHEMAS_FOLDER, schema_path)) as schema_file:
schema = json.load(schema_file)
with open(os.path.join(INTL_CONTENT_PATH, lang, schema_path)) as lang_file:
lang_json = json.load(lang_file)
jsonschema.validate(lang_json, schema)