Skip to content

Commit

Permalink
#150: General cleanup of recent work
Browse files Browse the repository at this point in the history
- Sort out linting and remove a few lines of code used for logging etc.
  • Loading branch information
MRichards99 committed Dec 3, 2020
1 parent bcea7ec commit c866be3
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 44 deletions.
4 changes: 2 additions & 2 deletions datagateway_api/common/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get_facility_cycles_for_instrument_count_with_filters(
pass

@abstractmethod
def get_investigations_for_instrument_in_facility_cycle_with_filters(
def get_investigations_for_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
):
"""
Expand All @@ -188,7 +188,7 @@ def get_investigations_for_instrument_in_facility_cycle_with_filters(
pass

@abstractmethod
def get_investigation_count_for_instrument_facility_cycle_with_filters(
def get_investigation_count_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
):
"""
Expand Down
4 changes: 2 additions & 2 deletions datagateway_api/common/database/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_facility_cycles_for_instrument_count_with_filters(

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_with_filters(
def get_investigations_for_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
):
return get_investigations_for_instrument_in_facility_cycle(
Expand All @@ -133,7 +133,7 @@ def get_investigations_for_instrument_in_facility_cycle_with_filters(

@requires_session_id
@queries_records
def get_investigation_count_for_instrument_facility_cycle_with_filters(
def get_investigation_count_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
):
return get_investigations_for_instrument_in_facility_cycle_count(
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from flask_restful import reqparse
from sqlalchemy.exc import IntegrityError

from datagateway_api.common.query_filter import QueryFilterFactory
from datagateway_api.common.exceptions import (
ApiError,
AuthenticationError,
BadRequestError,
FilterError,
MissingCredentialsError,
)
from datagateway_api.common.query_filter import QueryFilterFactory

log = logging.getLogger()

Expand Down
4 changes: 2 additions & 2 deletions datagateway_api/common/icat/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_facility_cycles_for_instrument_count_with_filters(

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_with_filters(
def get_investigations_for_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters, **kwargs,
):
client = kwargs["client"] if kwargs["client"] else create_client()
Expand All @@ -146,7 +146,7 @@ def get_investigations_for_instrument_in_facility_cycle_with_filters(

@requires_session_id
@queries_records
def get_investigation_count_for_instrument_facility_cycle_with_filters(
def get_investigation_count_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters, **kwargs,
):
client = kwargs["client"] if kwargs["client"] else create_client()
Expand Down
1 change: 0 additions & 1 deletion datagateway_api/common/query_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def get_query_filter(request_filter):
"""

backend_type = config.get_backend_type()
print(f"Backend inside staticmethod: {backend_type}")
if backend_type == "db":
from datagateway_api.common.database.filters import (
DatabaseDistinctFieldFilter as DistinctFieldFilter,
Expand Down
21 changes: 9 additions & 12 deletions datagateway_api/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
)
from datagateway_api.src.resources.table_endpoints.table_endpoints import (
count_instrument_facility_cycles_endpoint,
count_instrument_investigation_endpoint,
instrument_facility_cycles_endpoint,
instrument_investigation_endpoint,
count_instrument_investigation_endpoint,
)
from datagateway_api.src.swagger.apispec_flask_restful import RestfulPlugin
from datagateway_api.src.swagger.initialise_spec import initialise_spec
Expand All @@ -51,7 +51,7 @@ def create_app_infrastructure(flask_app):
security=[{"session_id": []}],
)

cors = CORS(flask_app)
CORS(flask_app)
flask_app.url_map.strict_slashes = False
api = Api(flask_app)

Expand All @@ -70,24 +70,21 @@ def create_api_endpoints(flask_app, api, spec):
try:
backend_type = flask_app.config["TEST_BACKEND"]
config.set_backend_type(backend_type)
print(f"test backend: {backend_type}")
except KeyError:
backend_type = config.get_backend_type()
print(f"config backend: {backend_type}")

# TODO - Add :param backend: to the endpoint functions
backend = create_backend(backend_type)
print(f"Backend: {backend}, Type: {type(backend)}")

for entity_name in endpoints:
get_endpoint_resource = get_endpoint(
entity_name, endpoints[entity_name], backend
entity_name, endpoints[entity_name], backend,
)
api.add_resource(get_endpoint_resource, f"/{entity_name.lower()}")
spec.path(resource=get_endpoint_resource, api=api)

get_id_endpoint_resource = get_id_endpoint(
entity_name, endpoints[entity_name], backend
entity_name, endpoints[entity_name], backend,
)
api.add_resource(get_id_endpoint_resource, f"/{entity_name.lower()}/<int:id_>")
spec.path(resource=get_id_endpoint_resource, api=api)
Expand All @@ -114,15 +111,15 @@ def create_api_endpoints(flask_app, api, spec):
# Table specific endpoints
instrument_facility_cycle_resource = instrument_facility_cycles_endpoint(backend)
api.add_resource(
instrument_facility_cycle_resource, "/instruments/<int:id_>/facilitycycles"
instrument_facility_cycle_resource, "/instruments/<int:id_>/facilitycycles",
)
# spec.path(resource=instrument_facility_cycle_resource, api=api)

count_instrument_facility_cycle_resource = count_instrument_facility_cycles_endpoint(
backend
count_instrument_facility_cycle_res = count_instrument_facility_cycles_endpoint(
backend,
)
api.add_resource(
count_instrument_facility_cycle_resource,
count_instrument_facility_cycle_res,
"/instruments/<int:id_>/facilitycycles/count",
)
# spec.path(resource=count_instrument_facility_cycle_resource, api=api)
Expand All @@ -135,7 +132,7 @@ def create_api_endpoints(flask_app, api, spec):
# spec.path(resource=instrument_investigation_resource, api=api)

count_instrument_investigation_resource = count_instrument_investigation_endpoint(
backend
backend,
)
api.add_resource(
count_instrument_investigation_resource,
Expand Down
4 changes: 0 additions & 4 deletions datagateway_api/src/resources/entities/entity_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from flask import request
from flask_restful import Resource

from datagateway_api.common.backends import create_backend
from datagateway_api.common.config import config
from datagateway_api.common.helpers import (
get_filters_from_query_string,
get_session_id_from_auth_header,
)

# backend = create_backend(config.get_backend_type())


def get_endpoint(name, entity_type, backend):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
from flask import request
from flask_restful import Resource

from datagateway_api.common.backends import create_backend
from datagateway_api.common.config import config
from datagateway_api.common.exceptions import AuthenticationError
from datagateway_api.common.helpers import get_session_id_from_auth_header


log = logging.getLogger()

# backend = create_backend(config.get_backend_type())


def session_endpoints(backend):
"""
TODO - Add docstring
"""
log.info("test")

class Sessions(Resource):
def post(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from flask_restful import Resource

from datagateway_api.common.backends import create_backend
from datagateway_api.common.config import config
from datagateway_api.common.helpers import (
get_filters_from_query_string,
get_session_id_from_auth_header,
)

backend = create_backend(config.get_backend_type())


def instrument_facility_cycles_endpoint(backend):
"""
Expand Down Expand Up @@ -179,7 +175,7 @@ def get(self, instrument_id, cycle_id):
description: No such record - Unable to find a record in ICAT
"""
return (
backend.get_investigations_for_instrument_in_facility_cycle_with_filters(
backend.get_investigations_for_instrument_facility_cycle_with_filters(
get_session_id_from_auth_header(),
instrument_id,
cycle_id,
Expand Down Expand Up @@ -240,7 +236,7 @@ def get(self, instrument_id, cycle_id):
description: No such record - Unable to find a record in ICAT
"""
return (
backend.get_investigation_count_for_instrument_facility_cycle_with_filters(
backend.get_investigation_count_instrument_facility_cycle_with_filters(
get_session_id_from_auth_header(),
instrument_id,
cycle_id,
Expand Down
2 changes: 1 addition & 1 deletion test/icat/endpoints/test_count_with_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class TestCountWithFilters:
@pytest.mark.usefixtures("single_investigation_test_data")
def test_valid_count_with_filters(
self, flask_test_app_icat, valid_credentials_header
self, flask_test_app_icat, valid_credentials_header,
):
test_response = flask_test_app_icat.get(
'/investigations/count?where={"title": {"like": "Test data for the Python'
Expand Down
2 changes: 1 addition & 1 deletion test/icat/endpoints/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_valid_create_data(self, flask_test_app_icat, valid_credentials_header):
)

def test_valid_boundary_create_data(
self, flask_test_app_icat, valid_credentials_header
self, flask_test_app_icat, valid_credentials_header,
):
"""Create a single investigation, as opposed to multiple"""

Expand Down
2 changes: 1 addition & 1 deletion test/icat/endpoints/test_delete_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_valid_delete_with_id(
assert test_response.status_code == 204

def test_invalid_delete_with_id(
self, flask_test_app_icat, valid_credentials_header
self, flask_test_app_icat, valid_credentials_header,
):
"""Request with a non-existent ID"""

Expand Down
2 changes: 1 addition & 1 deletion test/icat/endpoints/test_endpoint_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_entity_endpoints(self, flask_test_app, endpoint_ending, expected_method
],
)
def test_non_entity_endpoints(
self, flask_test_app, endpoint_name, expected_methods
self, flask_test_app, endpoint_name, expected_methods,
):
endpoint_found = False

Expand Down
1 change: 0 additions & 1 deletion test/icat/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def test_include_fields_list_flatten(self, icat_client):
test_query = ICATQuery(icat_client, "User")

flat_list = test_query.flatten_query_included_fields(included_field_set)
print(flat_list)

assert flat_list == [
"instrumentScientists",
Expand Down
4 changes: 1 addition & 3 deletions test/icat/test_session_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ def test_session_id_decorator(self):
pass

def test_get_valid_session_details(
self, flask_test_app_icat, valid_credentials_header
self, flask_test_app_icat, valid_credentials_header,
):
session_details = flask_test_app_icat.get(
"/sessions", headers=valid_credentials_header,
)

print(f"JSON: {session_details.json}, Code: {session_details.status_code}")

# Check username is correct
assert (
session_details.json["USERNAME"] == f"{config.get_test_mechanism()}/"
Expand Down
2 changes: 1 addition & 1 deletion test/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_limit_filter(self):
1, len(filters), msg="Returned incorrect number of filters",
)
self.assertIs(
DatabaseLimitFilter, type(filters[0]), msg="Incorrect type of filter"
DatabaseLimitFilter, type(filters[0]), msg="Incorrect type of filter",
)

def test_order_filter(self):
Expand Down

0 comments on commit c866be3

Please sign in to comment.