Skip to content

Commit

Permalink
#184: Ensure every line meets 88 character length
Browse files Browse the repository at this point in the history
- This is the suggested line length defined by Black, which flake8 is configured to also follow
  • Loading branch information
MRichards99 committed Nov 3, 2020
1 parent 9b85ea7 commit 81671f4
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 72 deletions.
2 changes: 1 addition & 1 deletion datagateway_api/common/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def get_investigations_for_instrument_in_facility_cycle_with_filters(
pass

@abstractmethod
def get_investigations_for_instrument_in_facility_cycle_count_with_filters(
def get_investigation_count_for_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
):
"""
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/common/database/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_investigations_for_instrument_in_facility_cycle_with_filters(

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_count_with_filters(
def get_investigation_count_for_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/icat/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_investigations_for_instrument_in_facility_cycle_with_filters(

@requires_session_id
@queries_records
def get_investigations_for_instrument_in_facility_cycle_count_with_filters(
def get_investigation_count_for_instrument_facility_cycle_with_filters(
self, session_id, instrument_id, facilitycycle_id, filters,
):
self.client.sessionId = session_id
Expand Down
10 changes: 5 additions & 5 deletions datagateway_api/common/icat/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def execute_query(self, client, return_json_formattable=False):
distinct_attributes, flat_query_includes,
)
log.debug(
"Attribute names used in the distinct filter, mapped to the entity they"
" are a part of: %s",
"Attribute names used in the distinct filter, mapped to the entity"
" they are a part of: %s",
mapped_distinct_fields,
)

Expand Down Expand Up @@ -188,7 +188,7 @@ def entity_to_dict(self, entity, includes, distinct_fields=None):
)
if isinstance(target, Entity):
if distinct_fields is not None:
distinct_fields_copy = self.prepare_distinct_fields_for_recursion(
distinct_fields_copy = self.prepare_distinct_fields(
key, distinct_fields,
)
else:
Expand All @@ -203,7 +203,7 @@ def entity_to_dict(self, entity, includes, distinct_fields=None):
d[key] = []
for e in target:
if distinct_fields is not None:
distinct_fields_copy = self.prepare_distinct_fields_for_recursion(
distinct_fields_copy = self.prepare_distinct_fields(
key, distinct_fields,
)
else:
Expand Down Expand Up @@ -296,7 +296,7 @@ def map_distinct_attributes_to_entity_names(self, distinct_fields, included_fiel

return distinct_field_dict

def prepare_distinct_fields_for_recursion(self, entity_name, distinct_fields):
def prepare_distinct_fields(self, entity_name, distinct_fields):
"""
Copy `distinct_fields` and move the data held in `entity_name` portion of the
dictionary to the "base" section of the dictionary. This function is called in
Expand Down
3 changes: 2 additions & 1 deletion datagateway_api/common/logger_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"version": 1,
"formatters": {
"default": {
"format": "[%(asctime)s] {%(module)s:%(filename)s:%(funcName)s:%(lineno)d} %(levelname)s -%(message)s ",
"format": "[%(asctime)s] {%(module)s:%(filename)s:%(funcName)s:%(lineno)d}"
" %(levelname)s - %(message)s",
},
},
"handlers": {
Expand Down
3 changes: 2 additions & 1 deletion datagateway_api/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def handle_error(e):
spec.path(resource=InstrumentsFacilityCyclesInvestigations, api=api)
api.add_resource(
InstrumentsFacilityCyclesInvestigationsCount,
"/instruments/<int:instrument_id>/facilitycycles/<int:cycle_id>/investigations/count",
"/instruments/<int:instrument_id>/facilitycycles/<int:cycle_id>/investigations"
"/count",
)
spec.path(resource=InstrumentsFacilityCyclesInvestigationsCount, api=api)

Expand Down
81 changes: 48 additions & 33 deletions datagateway_api/src/resources/entities/entity_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def get_endpoint(name, entity_type):
:return: The generated endpoint class
"""

entity_schema_name = entity_type.strip("_").upper()

class Endpoint(Resource):
def get(self):
return (
Expand All @@ -45,21 +47,23 @@ def get(self):
- INCLUDE_FILTER
responses:
200:
description: Success - returns {entity_type} that satisfy the filters
description: Success - returns {entity_type} that satisfy the
filters
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref:
'#/components/schemas/{entity_schema_name}'
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

def post(self):
Expand All @@ -73,7 +77,8 @@ def post(self):
post.__doc__ = f"""
---
summary: Create new {name}
description: Creates new {entity_type} object(s) with details provided in the request body
description: Creates new {entity_type} object(s) with details provided in
the request body
tags:
- {name}
requestBody:
Expand All @@ -84,7 +89,7 @@ def post(self):
schema:
type: array
items:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
responses:
200:
description: Success - returns the created object
Expand All @@ -93,15 +98,15 @@ def post(self):
schema:
type: array
items:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

def patch(self):
Expand All @@ -115,7 +120,8 @@ def patch(self):
patch.__doc__ = f"""
---
summary: Update {name}
description: Updates {entity_type} object(s) with details provided in the request body
description: Updates {entity_type} object(s) with details provided in the
request body
tags:
- {name}
requestBody:
Expand All @@ -126,7 +132,7 @@ def patch(self):
schema:
type: array
items:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
responses:
200:
description: Success - returns the updated object(s)
Expand All @@ -135,15 +141,15 @@ def patch(self):
schema:
type: array
items:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

Endpoint.__name__ = name
Expand All @@ -161,6 +167,8 @@ def get_id_endpoint(name, entity_type):
:return: The generated id endpoint class
"""

entity_schema_name = entity_type.strip("_").upper()

class EndpointWithID(Resource):
def get(self, id_):
return (
Expand Down Expand Up @@ -189,15 +197,15 @@ def get(self, id_):
content:
application/json:
schema:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

def delete(self, id_):
Expand All @@ -207,7 +215,8 @@ def delete(self, id_):
delete.__doc__ = f"""
---
summary: Delete {name} by id
description: Updates {entity_type} with the specified ID with details provided in the request body
description: Updates {entity_type} with the specified ID with details
provided in the request body
tags:
- {name}
parameters:
Expand All @@ -223,11 +232,11 @@ def delete(self, id_):
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

def patch(self, id_):
Expand All @@ -238,7 +247,8 @@ def patch(self, id_):
patch.__doc__ = f"""
---
summary: Update {name} by id
description: Updates {entity_type} with the specified ID with details provided in the request body
description: Updates {entity_type} with the specified ID with details
provided in the request body
tags:
- {name}
parameters:
Expand All @@ -254,22 +264,22 @@ def patch(self, id_):
content:
application/json:
schema:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
responses:
200:
description: Success - returns the updated object
content:
application/json:
schema:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

EndpointWithID.__name__ = f"{name}WithID"
Expand Down Expand Up @@ -300,7 +310,8 @@ def get(self):
get.__doc__ = f"""
---
summary: Count {name}
description: Return the count of the {entity_type} objects that would be retrieved given the filters provided
description: Return the count of the {entity_type} objects that would be
retrieved given the filters provided
tags:
- {name}
parameters:
Expand All @@ -317,11 +328,11 @@ def get(self):
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

CountEndpoint.__name__ = f"{name}Count"
Expand All @@ -339,6 +350,8 @@ def get_find_one_endpoint(name, entity_type):
:return: The generated findOne endpoint class
"""

entity_schema_name = entity_type.strip("_").upper()

class FindOneEndpoint(Resource):
def get(self):
filters = get_filters_from_query_string()
Expand All @@ -352,7 +365,8 @@ def get(self):
get.__doc__ = f"""
---
summary: Get single {entity_type}
description: Retrieves the first {entity_type} objects that satisfies the filters.
description: Retrieves the first {entity_type} objects that satisfies the
filters.
tags:
- {name}
parameters:
Expand All @@ -364,19 +378,20 @@ def get(self):
- INCLUDE_FILTER
responses:
200:
description: Success - a {entity_type} object that satisfies the filters
description: Success - a {entity_type} object that satisfies the
filters
content:
application/json:
schema:
$ref: '#/components/schemas/{entity_type.strip("_").upper()}'
$ref: '#/components/schemas/{entity_schema_name}'
400:
description: Bad request - Something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
description: No such record - Unable to find a record in the database
description: No such record - Unable to find a record in ICAT
"""

FindOneEndpoint.__name__ = f"{name}FindOne"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def post(self):
description: Session ID
example: xxxxxx-yyyyyyy-zzzzzz
400:
description: Bad request. User credentials were not provided in request body.
description: Bad request. User credentials not provided in request body
403:
description: Forbidden. User credentials were invalid
"""
Expand Down Expand Up @@ -81,7 +81,7 @@ def delete(self):
400:
description: Bad request - something was wrong with the request
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
404:
Expand Down Expand Up @@ -120,7 +120,7 @@ def get(self):
type: string
description: Username associated with this session
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
"""
Expand All @@ -145,7 +145,7 @@ def put(self):
description: Session ID
example: xxxxxx-yyyyyyy-zzzzzz
401:
description: Unauthorized - No session ID was found in the HTTP Authorization header
description: Unauthorized - No session ID found in HTTP Auth. header
403:
description: Forbidden - The session ID provided is invalid
"""
Expand Down
Loading

0 comments on commit 81671f4

Please sign in to comment.