Skip to content

Commit

Permalink
#135: Changes made by linter
Browse files Browse the repository at this point in the history
- Even though I've pushed #155 to master, it's still not applied half of it... Oh well, least it's nice and simple to do - need to go back through the code once all my PRs are merged and re-lint the code and sort out the order of imports
  • Loading branch information
MRichards99 committed Aug 17, 2020
1 parent f4a06ce commit def14c7
Show file tree
Hide file tree
Showing 23 changed files with 1,283 additions and 879 deletions.
16 changes: 12 additions & 4 deletions common/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def update_with_id(self, session_id, entity_type, id_, data):
pass

@abstractmethod
def get_instrument_facilitycycles_with_filters(self, session_id, instrument_id, filters):
def get_instrument_facilitycycles_with_filters(
self, session_id, instrument_id, filters
):
"""
Given an instrument_id get facility cycles where the instrument has investigations that occur within that cycle
:param session_id: The session id of the requesting user
Expand All @@ -141,7 +143,9 @@ def get_instrument_facilitycycles_with_filters(self, session_id, instrument_id,
pass

@abstractmethod
def count_instrument_facilitycycles_with_filters(self, session_id, instrument_id, filters):
def count_instrument_facilitycycles_with_filters(
self, session_id, instrument_id, filters
):
"""
Given an instrument_id get the facility cycles count where the instrument has investigations that occur within
that cycle
Expand All @@ -153,7 +157,9 @@ def count_instrument_facilitycycles_with_filters(self, session_id, instrument_id
pass

@abstractmethod
def get_instrument_facilitycycle_investigations_with_filters(self, session_id, instrument_id, facilitycycle_id, filters):
def get_instrument_facilitycycle_investigations_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
):
"""
Given an instrument id and facility cycle id, get investigations that use the given instrument in the given cycle
:param session_id: The session id of the requesting user
Expand All @@ -165,7 +171,9 @@ def get_instrument_facilitycycle_investigations_with_filters(self, session_id, i
pass

@abstractmethod
def count_instrument_facilitycycles_investigations_with_filters(self, session_id, instrument_id, facilitycycle_id, filters):
def count_instrument_facilitycycles_investigations_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
):
"""
Given an instrument id and facility cycle id, get the count of the investigations that use the given instrument in
the given cycle
Expand Down
3 changes: 1 addition & 2 deletions common/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
elif backend_type == "python_icat":
backend = PythonICATBackend()
else:
sys.exit(
f"Invalid config value '{backend_type}' for config option backend")
sys.exit(f"Invalid config value '{backend_type}' for config option backend")
backend = Backend()
3 changes: 1 addition & 2 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Config(object):

def __init__(self):
config_path = Path(__file__).parent.parent / "config.json"
with open(config_path) as target:
Expand Down Expand Up @@ -35,7 +34,7 @@ def get_icat_check_cert(self):
return self.config["icat_check_cert"]
except:
# This could be set to true if there's no value, and log a warning
# that no value has been found from the config - save app from
# that no value has been found from the config - save app from
# exiting
sys.exit("Missing config value, icat_check_cert")

Expand Down
55 changes: 43 additions & 12 deletions common/database_backend.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
from common.backend import Backend
from common.database_helpers import get_facility_cycles_for_instrument, get_facility_cycles_for_instrument_count, \
get_investigations_for_instrument_in_facility_cycle, get_investigations_for_instrument_in_facility_cycle_count, \
get_rows_by_filter, create_rows_from_json, patch_entities, get_row_by_id, insert_row_into_table, \
delete_row_by_id, update_row_from_id, get_filtered_row_count, get_first_filtered_row
from common.database_helpers import (
get_facility_cycles_for_instrument,
get_facility_cycles_for_instrument_count,
get_investigations_for_instrument_in_facility_cycle,
get_investigations_for_instrument_in_facility_cycle_count,
get_rows_by_filter,
create_rows_from_json,
patch_entities,
get_row_by_id,
insert_row_into_table,
delete_row_by_id,
update_row_from_id,
get_filtered_row_count,
get_first_filtered_row,
)
from common.database_helpers import requires_session_id
from common.helpers import queries_records
from common.models.db_models import SESSION
Expand All @@ -11,8 +22,10 @@
import datetime

import logging

log = logging.getLogger()


class DatabaseBackend(Backend):
"""
Class that contains functions to access and modify data in an ICAT database directly
Expand All @@ -21,8 +34,14 @@ class DatabaseBackend(Backend):
def login(self, credentials):
if credentials["username"] == "user" and credentials["password"] == "password":
session_id = str(uuid.uuid1())
insert_row_into_table(SESSION, SESSION(ID=session_id, USERNAME=f"{credentials['mechanism']}/root",
EXPIREDATETIME=datetime.datetime.now() + datetime.timedelta(days=1)))
insert_row_into_table(
SESSION,
SESSION(
ID=session_id,
USERNAME=f"{credentials['mechanism']}/root",
EXPIREDATETIME=datetime.datetime.now() + datetime.timedelta(days=1),
),
)
return session_id
else:
raise AuthenticationError("Username and password are incorrect")
Expand Down Expand Up @@ -82,20 +101,32 @@ def update_with_id(self, session_id, table, id_, data):

@requires_session_id
@queries_records
def get_instrument_facilitycycles_with_filters(self, session_id, instrument_id, filters):
def get_instrument_facilitycycles_with_filters(
self, session_id, instrument_id, filters
):
return get_facility_cycles_for_instrument(instrument_id, filters)

@requires_session_id
@queries_records
def count_instrument_facilitycycles_with_filters(self, session_id, instrument_id, filters):
def count_instrument_facilitycycles_with_filters(
self, session_id, instrument_id, filters
):
return get_facility_cycles_for_instrument_count(instrument_id, filters)

@requires_session_id
@queries_records
def get_instrument_facilitycycle_investigations_with_filters(self, session_id, instrument_id, facilitycycle_id, filters):
return get_investigations_for_instrument_in_facility_cycle(instrument_id, facilitycycle_id, filters)
def get_instrument_facilitycycle_investigations_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
):
return get_investigations_for_instrument_in_facility_cycle(
instrument_id, facilitycycle_id, filters
)

@requires_session_id
@queries_records
def count_instrument_facilitycycles_investigations_with_filters(self, session_id, instrument_id, facilitycycle_id, filters):
return get_investigations_for_instrument_in_facility_cycle_count(instrument_id, facilitycycle_id, filters)
def count_instrument_facilitycycles_investigations_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters
):
return get_investigations_for_instrument_in_facility_cycle_count(
instrument_id, facilitycycle_id, filters
)
Loading

0 comments on commit def14c7

Please sign in to comment.