Browse Source

Restructure top-level app and configuration structure for pytest.

Stefano Cossu 6 years ago
parent
commit
9d57a4b927
10 changed files with 122 additions and 63 deletions
  1. 15 0
      conftest.py
  2. 36 29
      doc/notes/TODO
  3. 3 3
      etc.skeleton/application.yml
  4. 16 0
      etc.skeleton/test.yml
  5. 0 0
      lakesuperior/__init__.py
  6. 35 0
      lakesuperior/app.py
  7. 4 1
      lakesuperior/config_parser.py
  8. 1 0
      requirements.txt
  9. 4 30
      server.py
  10. 8 0
      util/bootstrap.py

+ 15 - 0
conftest.py

@@ -0,0 +1,15 @@
+import sys
+sys.path.append('.')
+import uuid
+
+import pytest
+
+from lakesuperior.app import create_app
+from lakesuperior.config_parser import config
+
+
+@pytest.fixture
+def app():
+    app = create_app(config['test'], config['logging'])
+
+    return app

+ 36 - 29
doc/notes/TODO

@@ -1,36 +1,43 @@
 # Alpha 1 TODO
 
-H Pairtree resources
-D Logging
-D Server-managed triples
-  D PATCH
-  D PUT + POST
-D Single-subject rule
-  D PATCH
-  D PUT + POST
-D Prefer headers
-D LDP-NR
-D Direct and Indirect containers
-D Referential integrity
-D Tombstone
-  D Set
-  D Retrieve
-  D Delete
-D Refactor toolbox
-- GUnicorn
-- Tests
-- Messaging SPI
+- [D] Logging
+- [D] Server-managed triples
+  - [D] PATCH
+  - [D] PUT + POST
+- [D] Single-subject rule
+  - [D] PATCH
+  - [D] PUT + POST
+- [D] Prefer headers
+- [D] LDP-NR
+- [D] Direct and Indirect containers
+- [D] Referential integrity
+- [D] Tombstone
+  - [D] Set
+  - [D] Retrieve
+  - [D] Delete
+- [D] Refactor toolbox
+- [D] GUnicorn
+- [W] Tests
+  - [D] Framework + config
+  - [W] HTTP layer
+  - [ ] Unit tests
+- [ ] Optimize queries
+- [ ] Messaging SPI
+- [ ] Hook up Hyrax
 
 # Alpha 2 TODO
 
-- Separate read-only graph/resource generation from RW graph/res generation
-- Move server-managed triples to separate graph in simple layout
-- Full provenance layout
-- Fixity checks
+- [ ] Migraion tool
+- [ ] Complete header handling
+- [ ] Query API
+- [ ] Separate read-only graph/resource generation from RW graph/res generation
+- [ ] Move server-managed triples to separate graph in simple layout
+- [ ] Fixity checks
 
 # Alpha 3 TODO
-- Basic UI
-- Versioning
-- Async coroutines
-  - Within sync request
-  - Fully async request
+- [ ] Full provenance layout
+- [ ] Versioning
+- [ ] Async coroutines
+  - [ ] Within sync request
+  - [ ] Fully async request
+- [?] Basic UI

+ 3 - 3
etc.skeleton/application.yml

@@ -39,9 +39,9 @@ store:
         query_ep: sparql
         update_ep: sparql
         # Optional
-        username: <set me>
-        password: <set me>
-        ssl_verify: false
+        #username: <set me>
+        #password: <set me>
+        #ssl_verify: false
 
     # The path used to persist LDP-NR (bitstreams).
     # This is for now a POSIX filesystem. Other solutions such as HDFS may be

+ 16 - 0
etc.skeleton/test.yml

@@ -0,0 +1,16 @@
+# Configuration for testing framework.
+#
+# These values override the ones found in `application.yml`.
+
+store:
+    ldp_rs:
+        webroot: http://localhost:9999/namespace/fcrepo_test/
+        query_ep: sparql
+        update_ep: sparql
+        # Optional
+        #username: <set me>
+        #password: <set me>
+        #ssl_verify: false
+    ldp_nr:
+        path: /tmp/fcrepo_test/ldpnr_store
+

+ 0 - 0
lakesuperior/__init__.py


+ 35 - 0
lakesuperior/app.py

@@ -0,0 +1,35 @@
+import logging
+import os
+
+from logging.config import dictConfig
+
+from flask import Flask
+
+from lakesuperior.endpoints.ldp import ldp
+from lakesuperior.endpoints.query import query
+
+
+# App factory.
+
+def create_app(app_conf, logging_conf):
+    app = Flask(__name__)
+    app.config.update(app_conf)
+
+    dictConfig(logging_conf)
+    logger = logging.getLogger(__name__)
+    logger.info('Starting LAKEsuperior HTTP server.')
+
+    ## Configure endpoint blueprints here. ##
+
+    app.register_blueprint(ldp, url_prefix='/ldp', url_defaults={
+        'url_prefix': 'ldp'
+    })
+    # Legacy endpoint. @TODO Deprecate.
+    app.register_blueprint(ldp, url_prefix='/rest', url_defaults={
+        'url_prefix': 'rest'
+    })
+    app.register_blueprint(query, url_prefix='/query')
+
+    return app
+
+

+ 4 - 1
lakesuperior/config_parser.py

@@ -1,5 +1,6 @@
 import os
 
+import hiyapyco
 import yaml
 
 configs = (
@@ -23,4 +24,6 @@ for cname in configs:
     with open(file, 'r') as stream:
         config[cname] = yaml.load(stream, yaml.SafeLoader)
 
-
+# Merge default and test configurations.
+config['test'] = hiyapyco.load(CONFIG_DIR + '/application.yml',
+        CONFIG_DIR + '/test.yml', method=hiyapyco.METHOD_MERGE)

+ 1 - 0
requirements.txt

@@ -5,6 +5,7 @@ click==6.7
 dateutils==0.6.6
 Flask==0.12.2
 gunicorn==19.7.1
+HiYaPyCo==0.4.11
 idna==2.6
 isodate==0.5.4
 itsdangerous==0.24

+ 4 - 30
server.py

@@ -1,39 +1,13 @@
-import logging
-import os
-
-from logging.config import dictConfig
-
-from flask import Flask, render_template
+from flask import render_template
 
+from lakesuperior.app import create_app
 from lakesuperior.config_parser import config
-from lakesuperior.endpoints.ldp import ldp
-from lakesuperior.endpoints.query import query
-
-fcrepo = Flask(__name__)
-fcrepo.config.update(config['flask'])
-
-dictConfig(config['logging'])
-logger = logging.getLogger(__name__)
-logger.info('Starting LAKEsuperior HTTP server.')
-
-## Configure enpoint blueprints here. ##
 
-fcrepo.register_blueprint(ldp, url_prefix='/ldp', url_defaults={
-    'url_prefix': 'ldp'
-})
-# Legacy endpoint. @TODO Deprecate.
-fcrepo.register_blueprint(ldp, url_prefix='/rest', url_defaults={
-    'url_prefix': 'rest'
-})
-fcrepo.register_blueprint(query, url_prefix='/query')
 
-# Initialize temporary folders.
-tmp_path = config['application']['store']['ldp_nr']['path'] + '/tmp'
-if not os.path.exists(tmp_path):
-    os.makedirs(tmp_path)
+fcrepo = create_app(config['flask'], config['logging'])
 
 
-## ROUTES ##
+## GENERIC ROUTES ##
 
 @fcrepo.route('/', methods=['GET'])
 def index():

+ 8 - 0
util/bootstrap.py

@@ -1,8 +1,16 @@
 #!/usr/bin/env python
 
+from lakesuperior.config_parser import config
+
 # This script will parse configuration files and initialize a filesystem and
 # triplestore with an empty FCREPO repository.
 #
 # Additional, scaffolding files may be parsed to create initial contents.
 
 # @TODO
+
+# Initialize temporary folders.
+tmp_path = config['application']['store']['ldp_nr']['path'] + '/tmp'
+if not os.path.exists(tmp_path):
+    os.makedirs(tmp_path)
+