Skip to content

Commit

Permalink
#150: Allow backends to be created for testing purposes
Browse files Browse the repository at this point in the history
- Currently getting a 403 on these changes but I'm not sure the code is at fault...
  • Loading branch information
MRichards99 committed Sep 29, 2020
1 parent db43d3d commit 2dee8f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
25 changes: 16 additions & 9 deletions common/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
from common.config import config
import sys

backend_type = config.get_backend_type()

if backend_type == "db":
backend = DatabaseBackend()
elif backend_type == "python_icat":
backend = PythonICATBackend()
else:
sys.exit(f"Invalid config value '{backend_type}' for config option backend")
backend = Backend()

def create_backend(backend_type):
"""
TODO - Add docstring
"""

if backend_type == "db":
backend = DatabaseBackend()
elif backend_type == "python_icat":
backend = PythonICATBackend()
else:
# Might turn to a warning so the abstract class can be tested?
sys.exit(f"Invalid config value '{backend_type}' for config option backend")
backend = Backend()

return backend
6 changes: 5 additions & 1 deletion src/resources/entities/entity_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
get_session_id_from_auth_header,
get_filters_from_query_string,
)
from common.backends import backend
from common.backends import create_backend
from common.config import config


backend = create_backend(config.get_backend_type())


def get_endpoint(name, table):
Expand Down
4 changes: 3 additions & 1 deletion src/resources/non_entities/sessions_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
)
from common.helpers import get_session_id_from_auth_header
from common.models.db_models import SESSION
from common.backends import backend
from common.backends import create_backend
from common.exceptions import AuthenticationError
from common.config import config

log = logging.getLogger()

backend = create_backend(config.get_backend_type())

class Sessions(Resource):
def post(self):
Expand Down
5 changes: 4 additions & 1 deletion src/resources/table_endpoints/table_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
get_session_id_from_auth_header,
get_filters_from_query_string,
)
from common.backends import backend
from common.backends import create_backend
from common.config import config

backend = create_backend(config.get_backend_type())


class InstrumentsFacilityCycles(Resource):
Expand Down

0 comments on commit 2dee8f0

Please sign in to comment.