From 600edc22da627d78f3ea110ba9c55b354655b98c Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Sat, 30 Nov 2024 23:01:34 +0100 Subject: [PATCH] global: remove examples directory * not updated anymore --- examples/app-setup.sh | 14 ---- examples/app-teardown.sh | 4 - examples/app.py | 69 ---------------- examples/samplepkg/samplepkg/__init__.py | 9 -- .../samplepkg/jsonschemas/__init__.py | 9 -- .../biology/animal_record_schema.json | 12 --- .../samplepkg/jsonschemas/record_schema.json | 8 -- examples/samplepkg/setup.py | 22 ----- tests/test_examples_app.py | 82 ------------------- 9 files changed, 229 deletions(-) delete mode 100755 examples/app-setup.sh delete mode 100755 examples/app-teardown.sh delete mode 100644 examples/app.py delete mode 100644 examples/samplepkg/samplepkg/__init__.py delete mode 100644 examples/samplepkg/samplepkg/jsonschemas/__init__.py delete mode 100644 examples/samplepkg/samplepkg/jsonschemas/biology/animal_record_schema.json delete mode 100644 examples/samplepkg/samplepkg/jsonschemas/record_schema.json delete mode 100644 examples/samplepkg/setup.py delete mode 100644 tests/test_examples_app.py diff --git a/examples/app-setup.sh b/examples/app-setup.sh deleted file mode 100755 index 5efd8e8..0000000 --- a/examples/app-setup.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -# quit on errors: -set -o errexit - -# quit on unbound symbols: -set -o nounset - -DIR=`dirname $0` - -# install the sample application -cd $DIR/samplepkg -pip install -e . -cd - diff --git a/examples/app-teardown.sh b/examples/app-teardown.sh deleted file mode 100755 index 1485d74..0000000 --- a/examples/app-teardown.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -# install the sample application -pip uninstall -y samplepkg_invenio_jsonschemas diff --git a/examples/app.py b/examples/app.py deleted file mode 100644 index 5d71e04..0000000 --- a/examples/app.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2015-2018 CERN. -# -# Invenio is free software; you can redistribute it and/or modify it -# under the terms of the MIT License; see LICENSE file for more details. - -"""Minimal Flask application example for development. - -SPHINX-START - -Run example development server: - -.. code-block:: console - - $ pip install -e .[all] - $ cd examples - $ ./app-setup.sh - $ python app.py - -Open the schema from web: - -.. code-block:: console - - $ curl http://localhost:5000/schemas/record_schema.json - $ curl http://localhost:5000/schemas/biology/animal_record_schema.json - -Teardown the application: - -.. code-block:: console - - $ ./app-teardown.sh - -SPHINX-END -""" - -from __future__ import absolute_import, print_function - -import json - -from flask import Flask - -from invenio_jsonschemas import InvenioJSONSchemas - -# Create Flask application -app = Flask(__name__) - -# set the endpoint serving the JSON schemas -app.config["JSONSCHEMAS_ENDPOINT"] = "/schemas" - -# Initialize the application with the InvenioJSONSchema extension. -# This registers the jsonschemas from examples/samplepkg/jsonschemas as -# samplepkg's setup.py has the "invenio_jsonschemas.schemas" entrypoint. -ext = InvenioJSONSchemas(app) - -# list all registered schemas -print("SCHEMAS >> {}".format(ext.list_schemas())) -for schema in ext.list_schemas(): - print("=" * 50) - print("SCHEMA {}".format(schema)) - # retrieve the schema content - print(json.dumps(ext.get_schema(schema), indent=4)) - -# InvenioJSONSchemas registers a blueprint serving the JSON schemas -print('>> You can retrieve the schemas using the url in their "id".') - -if __name__ == "__main__": - app.run() diff --git a/examples/samplepkg/samplepkg/__init__.py b/examples/samplepkg/samplepkg/__init__.py deleted file mode 100644 index faef63f..0000000 --- a/examples/samplepkg/samplepkg/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2015-2018 CERN. -# -# Invenio is free software; you can redistribute it and/or modify it -# under the terms of the MIT License; see LICENSE file for more details. - -"""Sample Package for Testing Invenio-JSONSchemas.""" diff --git a/examples/samplepkg/samplepkg/jsonschemas/__init__.py b/examples/samplepkg/samplepkg/jsonschemas/__init__.py deleted file mode 100644 index faef63f..0000000 --- a/examples/samplepkg/samplepkg/jsonschemas/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2015-2018 CERN. -# -# Invenio is free software; you can redistribute it and/or modify it -# under the terms of the MIT License; see LICENSE file for more details. - -"""Sample Package for Testing Invenio-JSONSchemas.""" diff --git a/examples/samplepkg/samplepkg/jsonschemas/biology/animal_record_schema.json b/examples/samplepkg/samplepkg/jsonschemas/biology/animal_record_schema.json deleted file mode 100644 index 46d0eaa..0000000 --- a/examples/samplepkg/samplepkg/jsonschemas/biology/animal_record_schema.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "id": "http://localhost:5000/schemas/biology/animal_record_schema.json", - "allOf": [{ - "$ref": "http://localhost:5000/schemas/record_schema.json" - }, { - "type": "object", - "properties": { - "specie": { "type": "string" } - } - }] -} diff --git a/examples/samplepkg/samplepkg/jsonschemas/record_schema.json b/examples/samplepkg/samplepkg/jsonschemas/record_schema.json deleted file mode 100644 index d5742e8..0000000 --- a/examples/samplepkg/samplepkg/jsonschemas/record_schema.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "id": "http://localhost:5000/schemas/record_schema.json", - "type": "object", - "properties": { - "title": { "type": "string" } - } -} diff --git a/examples/samplepkg/setup.py b/examples/samplepkg/setup.py deleted file mode 100644 index 85fc9be..0000000 --- a/examples/samplepkg/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2015-2018 CERN. -# -# Invenio is free software; you can redistribute it and/or modify it -# under the terms of the MIT License; see LICENSE file for more details. - -"""Sample Package for Testing Invenio-JSONSchemas.""" - -from setuptools import setup - -setup( - name="samplepkg-invenio-jsonschemas", - version="0.0.0", - zip_safe=False, - include_package_data=True, - packages=["samplepkg"], - entry_points={ - "invenio_jsonschemas.schemas": ["samplepkg = samplepkg.jsonschemas"], - }, -) diff --git a/tests/test_examples_app.py b/tests/test_examples_app.py deleted file mode 100644 index 8ac7791..0000000 --- a/tests/test_examples_app.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2016-2018 CERN. -# -# Invenio is free software; you can redistribute it and/or modify it -# under the terms of the MIT License; see LICENSE file for more details. - -"""Test example app.""" - -import json -import os -import signal -import subprocess -import time - -import pytest - - -@pytest.yield_fixture -def example_app(): - """Example app fixture.""" - current_dir = os.getcwd() - - # Go to example directory - project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - exampleappdir = os.path.join(project_dir, "examples") - os.chdir(exampleappdir) - - # Setup example - cmd = "./app-setup.sh" - exit_status = subprocess.call(cmd, shell=True) - assert exit_status == 0 - - # Starting example web app - cmd = "python app.py" - webapp = subprocess.Popen( - cmd, stdout=subprocess.PIPE, preexec_fn=os.setsid, shell=True - ) - time.sleep(10) - # Return webapp - yield webapp - - # Stop server - try: - os.killpg(webapp.pid, signal.SIGTERM) - except OSError as err: - print(f"ERROR stop server: {webapp.pid}") - os.system(f"sudo kill {webapp.pid}") - - # Tear down example app - cmd = "./app-teardown.sh" - subprocess.call(cmd, shell=True) - - # Return to the original directory - os.chdir(current_dir) - cmd = "pip install -e .[all]" - subprocess.call(cmd, shell=True) - - -def test_example_app(example_app): - """Test example app.""" - cmd = "curl http://localhost:5000/schemas/biology/animal_record_schema.json" - output = json.loads(subprocess.check_output(cmd, shell=True).decode("utf-8")) - assert ( - output["id"] - == "http://localhost:5000/schemas/biology/animal_record_schema.json" - ) - allof = output["allOf"] - assert len(allof) == 2 - for obj in allof: - if "$ref" in obj: - assert obj["$ref"] == "http://localhost:5000/schemas/record_schema.json" - if "properties" in obj: - assert allof[1]["properties"]["specie"]["type"] == "string" - assert allof[1]["type"] == "object" - - cmd = "curl http://localhost:5000/schemas/record_schema.json" - output = json.loads(subprocess.check_output(cmd, shell=True).decode("utf-8")) - assert output["id"] == "http://localhost:5000/schemas/record_schema.json" - assert output["type"] == "object" - assert output["properties"]["title"]["type"] == "string"