def test_flattener_full_example(): test_schema = resource_json(__name__, "data/area_definition.json") flattener = JsonSchemaFlattener(test_schema) flattened = flattener.flatten_schema() assert flattened == AREA_DEFINITION_FLATTENED
def test_generate_docs_with_multiref_property(project, tmp_path_factory): project.schema = resource_json( __name__, "data/schema/valid/valid_multiref_property.json") project.type_name = "AWS::Color::Red" # tmpdir conflicts with other tests, make a unique one project.root = tmp_path_factory.mktemp("generate_with_docs_type_complex") mock_plugin = MagicMock(spec=["generate"]) with patch.object(project, "_plugin", mock_plugin): project.generate() project.generate_docs() mock_plugin.generate.assert_called_once_with(project) docs_dir = project.root / "docs" readme_file = project.root / "docs" / "README.md" assert docs_dir.is_dir() assert readme_file.is_file() with patch.object(project, "_plugin", mock_plugin): project.generate() readme_contents = readme_file.read_text(encoding="utf-8") readme_contents_target = resource_stream( __name__, "data/schema/target_output/multiref.md") read_me_stripped = readme_contents.strip().replace(" ", "") read_me_target_stripped = readme_contents_target.read().strip().replace( " ", "") LOG.debug("read_me_stripped %s", read_me_stripped) LOG.debug("read_me_target_stripped %s", read_me_target_stripped) assert project.type_name in readme_contents assert read_me_stripped == read_me_target_stripped
def plugin(): mock_plugin = create_autospec(LanguagePlugin) mock_plugin.project_settings_defaults.return_value = resource_stream( __name__, "data/project_defaults.yaml") mock_plugin.project_settings_schema.return_value = resource_json( __name__, "data/project_schema.json") return mock_plugin
def test_generate_with_docs_composite_primary_identifier( project, tmp_path_factory): project.schema = resource_json( __name__, "data/schema/valid/valid_type_composite_primary_identifier.json") project.type_name = "AWS::Color::Red" # tmpdir conflicts with other tests, make a unique one project.root = tmp_path_factory.mktemp( "generate_with_docs_composite_primary_identifier") mock_plugin = MagicMock(spec=["generate"]) with patch.object(project, "_plugin", mock_plugin): project.generate() project.generate_docs() mock_plugin.generate.assert_called_once_with(project) docs_dir = project.root / "docs" readme_file = project.root / "docs" / "README.md" assert docs_dir.is_dir() assert readme_file.is_file() with patch.object(project, "_plugin", mock_plugin): project.generate() project.generate_docs() readme_contents = readme_file.read_text(encoding="utf-8") assert project.type_name in readme_contents
def test_flattener_double_processed_refs(): """The flattener uses references to indicate objects, but these references are not JSON pointer URI fragments. In some cases, such references may be fed back into the flattener, like if object B is nested inside object A with a combiner (``oneOf``). When the combiner is processed, B is (correctly) flattened into a distinct object and placed in the schema map. A reference to B is returned, as a tuple (``{'$ref': ('properties', 'A', 'oneOf', 0, 'properties', 'B')}``), from ``_flatten_object_type``. So when the combiners are flattened, the result is: ``{'properties': {'B': {'$ref': ('properties', 'A', 'oneOf', 0, 'properties', 'B')}}}``. So when `_flatten_object_type` hits the `$ref`, it's important that ``_flatten_ref_type`` understands tuples, which is also tested, so this test is for showing that such a situation occurs in a normal, well-formed schema. """ test_schema = resource_json(__name__, "data/valid_refs_flattened_twice.json") flattener = JsonSchemaFlattener(test_schema) flattener.flatten_schema()
def test_generate_with_docs_invalid_property_type(project, tmp_path_factory): project.schema = resource_json( __name__, "data/schema/invalid/invalid_property_type_invalid.json") project.type_name = "AWS::Color::Red" # tmpdir conflicts with other tests, make a unique one project.root = tmp_path_factory.mktemp( "generate_with_docs_invalid_property_type") mock_plugin = MagicMock(spec=["generate"]) with patch.object(project, "_plugin", mock_plugin): # skip actual generation project.generate_docs() docs_dir = project.root / "docs" readme_file = project.root / "docs" / "README.md" assert docs_dir.is_dir() assert readme_file.is_file() with patch.object(project, "_plugin", mock_plugin): project.generate() project.generate_docs() readme_contents = readme_file.read_text(encoding="utf-8") assert project.type_name in readme_contents
def __make_resource_validator(base_uri=None, timeout=TIMEOUT_IN_SECONDS): schema = resource_json( __name__, "../../src/rpdk/core/data/schema/provider.definition.schema.modules.v1.json", ) return make_validator(schema, base_uri=base_uri)
def __get_sample_fragment_json(): sample_json = resource_json(__name__, SAMPLE_FRAGMENT) return sample_json