diff --git a/application/common/dos.py b/application/common/dos.py index 43ea567d7..2127f193c 100644 --- a/application/common/dos.py +++ b/application/common/dos.py @@ -329,11 +329,10 @@ def db_rows_to_spec_open_times_map(db_rows: Iterable[dict]) -> dict[str, list[Sp for db_row in db_rows: serviceid_dbrows_map[db_row["serviceid"]].append(db_row) - serviceid_specopentimes_map = {} - for service_id, db_rows in serviceid_dbrows_map.items(): - serviceid_specopentimes_map[service_id] = db_rows_to_spec_open_times(db_rows) - - return serviceid_specopentimes_map + return { + service_id: db_rows_to_spec_open_times(db_rows) + for service_id, db_rows in serviceid_dbrows_map.items() + } def db_rows_to_std_open_times(db_rows: Iterable[dict]) -> StandardOpeningTimes: @@ -362,11 +361,10 @@ def db_rows_to_std_open_times_map(db_rows: Iterable[dict]) -> dict[str, Standard for db_row in db_rows: serviceid_dbrows_map[db_row["serviceid"]].append(db_row) - serviceid_stdopentimes_map = {} - for service_id, db_rows in serviceid_dbrows_map.items(): - serviceid_stdopentimes_map[service_id] = db_rows_to_std_open_times(db_rows) - - return serviceid_stdopentimes_map + return { + service_id: db_rows_to_std_open_times(db_rows) + for service_id, db_rows in serviceid_dbrows_map.items() + } def has_palliative_care(service: DoSService, connection: Connection) -> bool: diff --git a/application/common/dynamodb.py b/application/common/dynamodb.py index 0ad978b0f..75f111883 100644 --- a/application/common/dynamodb.py +++ b/application/common/dynamodb.py @@ -146,7 +146,10 @@ def get_newest_event_per_odscode(threads: int = 2, limit: int = None) -> dict[st def merge_newest_events(newest_events: dict, more_events: list[dict]): # noqa: ANN202 for event in more_events: newest_event = newest_events.get(event["ODSCode"]) - if not (newest_event is not None and newest_event["SequenceNumber"] > event["SequenceNumber"]): + if ( + newest_event is None + or newest_event["SequenceNumber"] <= event["SequenceNumber"] + ): newest_events[event["ODSCode"]] = event def scan_thread(segment: int, total_segments: int): # noqa: ANN202 diff --git a/application/common/middlewares.py b/application/common/middlewares.py index bb138147b..441f2ebec 100644 --- a/application/common/middlewares.py +++ b/application/common/middlewares.py @@ -12,7 +12,7 @@ @lambda_handler_decorator(trace_execution=True) -def redact_staff_key_from_event(handler, event, context: LambdaContext) -> Any: # noqa: ANN001, ANN401 +def redact_staff_key_from_event(handler, event, context: LambdaContext) -> Any: # noqa: ANN001, ANN401 """Lambda middleware to remove the 'Staff' key from the Change Event payload. Args: @@ -24,7 +24,7 @@ def redact_staff_key_from_event(handler, event, context: LambdaContext) -> Any: Any: Lambda handler response """ logger.info("Checking if 'Staff' key needs removing from Change Event payload") - if "Records" in event and len(list(event["Records"])) > 0: + if "Records" in event and list(event["Records"]): for record in event["Records"]: change_event = extract_body(record["body"]) if change_event.pop("Staff", None) is not None: diff --git a/application/common/nhs.py b/application/common/nhs.py index 175d629e3..c49e69937 100644 --- a/application/common/nhs.py +++ b/application/common/nhs.py @@ -76,14 +76,20 @@ def normal_postcode(self) -> str: def extract_contact(self, contact_type: str) -> str | None: """Returns the nested contact value within the input payload.""" - for item in self.entity_data.get("Contacts", []): - if ( - item.get("ContactMethodType", "").upper() == contact_type.upper() - and item.get("ContactType", "").upper() == "PRIMARY" - and item.get("ContactAvailabilityType", "").upper() == "OFFICE HOURS" - ): - return item.get("ContactValue") - return None + return next( + ( + item.get("ContactValue") + for item in self.entity_data.get("Contacts", []) + if ( + item.get("ContactMethodType", "").upper() + == contact_type.upper() + and item.get("ContactType", "").upper() == "PRIMARY" + and item.get("ContactAvailabilityType", "").upper() + == "OFFICE HOURS" + ) + ), + None, + ) def extract_uec_service(self, service_code: str) -> bool | None: """Extracts the UEC service from the payload (e.g. Palliative Care). @@ -190,7 +196,7 @@ def is_matching_dos_service(self, dos_service: DoSService) -> bool: ) if dos_service.typeid in DENTIST_SERVICE_TYPE_IDS: - if not (len(dos_service.odscode) >= 6 and len(self.odscode) >= 7): # noqa: PLR2004 + if len(dos_service.odscode) < 6 or len(self.odscode) < 7: # noqa: PLR2004 return False odscode_extra_0 = f"{dos_service.odscode[0]}0{dos_service.odscode[1:]}" return self.odscode[:7] in (dos_service.odscode[:7], odscode_extra_0[:7]) @@ -221,10 +227,10 @@ def is_std_opening_json(item: dict) -> bool: return False # If marked as closed, ensure open time values are not present - if not is_open and (any(value not in ["", None] for value in (open_time, close_time))): - return False - - return True + return bool( + is_open + or all(value in ["", None] for value in (open_time, close_time)), + ) def is_spec_opening_json(item: dict) -> bool: @@ -249,10 +255,10 @@ def is_spec_opening_json(item: dict) -> bool: return False # If marked as closed, ensure open time values are not present - if not is_open and (any(value not in ["", None] for value in (open_time, close_time))): - return False - - return True + return bool( + is_open + or all(value in ["", None] for value in (open_time, close_time)), + ) def match_nhs_entities_to_services( diff --git a/application/common/opening_times.py b/application/common/opening_times.py index d55ba3772..343d00dc5 100644 --- a/application/common/opening_times.py +++ b/application/common/opening_times.py @@ -316,11 +316,7 @@ def remove_past_dates( """Removes any SpecifiedOpeningTime objects from the list that are in the past.""" if date_now is None: date_now = datetime.now().date() # noqa: DTZ005 - future_dates = [] - for item in times_list: - if item.date >= date_now: - future_dates.append(item) - return future_dates + return [item for item in times_list if item.date >= date_now] def export_test_format(self) -> dict: """Exports Specified opening time into a test format that can be used in the tests.""" @@ -334,7 +330,7 @@ def export_test_format_list(spec_opening_dates: list["SpecifiedOpeningTime"]) -> opening_dates_cr_format = {} for spec_open_date in spec_opening_dates: spec_open_date_payload = spec_open_date.export_test_format() - opening_dates_cr_format.update(spec_open_date_payload) + opening_dates_cr_format |= spec_open_date_payload return opening_dates_cr_format @@ -370,7 +366,7 @@ def __str__(self) -> str: def __len__(self) -> int: """Returns the number of OpenPeriods in the StandardOpeningTimes object.""" - return sum([len(getattr(self, day)) for day in WEEKDAYS]) + return sum(len(getattr(self, day)) for day in WEEKDAYS) def __eq__(self, other: "StandardOpeningTimes") -> bool: """Check equality of 2 StandardOpeningTimes (generic bankholiday values are ignored).""" diff --git a/application/common/tests/conftest.py b/application/common/tests/conftest.py index ed3e34df6..ffc90b3a3 100644 --- a/application/common/tests/conftest.py +++ b/application/common/tests/conftest.py @@ -48,11 +48,9 @@ def dummy_dos_service(**kwargs: Any) -> DoSService: # noqa: ANN401 return dos_service -def blank_dos_service(**kwargs: Any) -> DoSService: # noqa: ANN401 +def blank_dos_service(**kwargs: Any) -> DoSService: # noqa: ANN401 """Creates a DoSService Object with blank str data for the unit testing.""" - test_data = {} - for col in DoSService.field_names(): - test_data[col] = "" + test_data = {col: "" for col in DoSService.field_names()} dos_service = DoSService(test_data) for name, value in kwargs.items(): diff --git a/application/common/tests/test_dynamodb.py b/application/common/tests/test_dynamodb.py index 32ca59185..670963c85 100644 --- a/application/common/tests/test_dynamodb.py +++ b/application/common/tests/test_dynamodb.py @@ -95,7 +95,7 @@ def test_add_change_event_to_dynamodb(dynamodb_table_create, change_event, dynam expected = loads(dumps(change_event), parse_float=Decimal) assert response_id == change_id - assert deserialized["EventReceived"] == int(event_received_time) + assert deserialized["EventReceived"] == event_received_time assert deserialized["TTL"] == int(event_received_time + TTL) assert deserialized["Id"] == change_id assert deserialized["SequenceNumber"] == 1 diff --git a/application/common/tests/test_opening_times.py b/application/common/tests/test_opening_times.py index c68bc3a3b..e8e92c456 100644 --- a/application/common/tests/test_opening_times.py +++ b/application/common/tests/test_opening_times.py @@ -65,8 +65,6 @@ def test_open_period_eq_hash(): assert hash(c) != hash(d) assert d == d - assert hash(d) == hash(d) - b.end = time(17, 0, 0) assert a == b assert hash(a) == hash(b) diff --git a/application/common/tests/test_report_logging.py b/application/common/tests/test_report_logging.py index df21a91f9..c6eb9757c 100644 --- a/application/common/tests/test_report_logging.py +++ b/application/common/tests/test_report_logging.py @@ -215,7 +215,7 @@ def test_log_invalid_open_times(mock_logger): nhs_entity.odscode = "SLC4X" nhs_entity.org_name = "OrganisationName" - dos_services = [dummy_dos_service() for i in range(3)] + dos_services = [dummy_dos_service() for _ in range(3)] # Act log_invalid_open_times(nhs_entity, dos_services) # Assert diff --git a/application/common/utilities.py b/application/common/utilities.py index ac854d37f..59489227d 100644 --- a/application/common/utilities.py +++ b/application/common/utilities.py @@ -83,9 +83,7 @@ def get_sqs_msg_attribute(msg_attributes: dict[str, Any], key: str) -> str | flo data_type = attribute.get("dataType") if data_type == "String": return attribute.get("stringValue") - if data_type == "Number": - return float(attribute.get("stringValue")) - return None + return float(attribute.get("stringValue")) if data_type == "Number" else None def handle_sqs_msg_attributes(msg_attributes: dict[str, Any]) -> dict[str, Any] | None: diff --git a/application/requirements-dev.txt b/application/requirements-dev.txt index 182a0db60..42574ac75 100644 --- a/application/requirements-dev.txt +++ b/application/requirements-dev.txt @@ -16,6 +16,6 @@ pytest-sugar pytest-xdist requests responses -ruff == 0.0.269 +ruff == 0.0.270 testfixtures vulture diff --git a/application/service_matcher/service_matcher.py b/application/service_matcher/service_matcher.py index d99fcb607..7d79f0bff 100644 --- a/application/service_matcher/service_matcher.py +++ b/application/service_matcher/service_matcher.py @@ -145,7 +145,7 @@ def get_matching_services(nhs_entity: NHSEntity) -> list[DoSService]: matching_services.append(service) else: non_matching_services.append(service) - if len(non_matching_services) > 0: + if non_matching_services: log_unmatched_service_types(nhs_entity, non_matching_services) if nhs_entity.org_type_id == PHARMACY_ORG_TYPE_ID: diff --git a/application/service_sync/changes_to_dos.py b/application/service_sync/changes_to_dos.py index d4a988dc1..8b074fb55 100644 --- a/application/service_sync/changes_to_dos.py +++ b/application/service_sync/changes_to_dos.py @@ -3,15 +3,10 @@ from aws_lambda_powertools.logging import Logger -from .format import format_address, format_website from .service_histories import ServiceHistories -from .validation import validate_website -from common.dos import DoSService, get_valid_dos_location -from common.dos_location import DoSLocation +from common.dos import DoSService from common.nhs import NHSEntity -from common.opening_times import SpecifiedOpeningTime, StandardOpeningTimes, opening_period_times_from_list -from common.report_logging import log_invalid_nhsuk_postcode -from common.utilities import is_val_none_or_empty +from common.opening_times import SpecifiedOpeningTime logger = Logger(child=True) diff --git a/application/service_sync/compare_data.py b/application/service_sync/compare_data.py index d95b82e70..036c9f2b9 100644 --- a/application/service_sync/compare_data.py +++ b/application/service_sync/compare_data.py @@ -3,6 +3,7 @@ from aws_lambda_powertools.logging import Logger from .changes_to_dos import ChangesToDoS +from .format import format_address, format_website from .service_histories import ServiceHistories from .service_histories_change import ServiceHistoriesChange from .validation import validate_opening_times, validate_website @@ -25,15 +26,20 @@ from common.dos import DoSService, get_valid_dos_location from common.dos_location import DoSLocation from common.nhs import NHSEntity, get_palliative_care_log_value, skip_if_key_is_none -from common.opening_times import DAY_IDS, WEEKDAYS, StandardOpeningTimes, SpecifiedOpeningTime, opening_period_times_from_list +from common.opening_times import ( + DAY_IDS, + WEEKDAYS, + SpecifiedOpeningTime, + StandardOpeningTimes, + opening_period_times_from_list, +) from common.report_logging import ( + log_blank_standard_opening_times, log_incorrect_palliative_stockholder_type, + log_invalid_nhsuk_postcode, log_palliative_care_not_equal, - log_blank_standard_opening_times, - log_invalid_nhsuk_postcode ) from common.utilities import is_val_none_or_empty -from .format import format_address, format_website logger = Logger(child=True) @@ -77,7 +83,7 @@ def has_website_changed(changes: ChangesToDoS) -> bool: changes.current_website = changes.dos_service.web changes.new_website = None return True - elif changes.nhs_entity.website is not None and changes.nhs_entity.website != "": + elif changes.nhs_entity.website is not None and changes.nhs_entity.website: # noqa: RET505 changes.current_website = changes.dos_service.web # Adding a new website nhs_uk_website = format_website(changes.nhs_entity.website) @@ -85,8 +91,7 @@ def has_website_changed(changes: ChangesToDoS) -> bool: if changes.dos_service.web != nhs_uk_website: logger.info(f"Website is not equal, {changes.dos_service.web=} != {nhs_uk_website=}") return validate_website(changes.nhs_entity, nhs_uk_website) - else: - logger.info(f"Website is equal, {changes.dos_service.web=} == {nhs_uk_website=}") + logger.info(f"Website is equal, {changes.dos_service.web=} == {nhs_uk_website=}") return False @@ -125,9 +130,8 @@ def has_public_phone_changed(changes: ChangesToDoS) -> bool: f"Public Phone is not equal, DoS='{changes.current_public_phone}' != NHS UK='{changes.new_public_phone}'", ) return True - else: - logger.info(f"Public Phone is equal, DoS='{changes.current_public_phone}' == NHS UK='{changes.new_public_phone}'") - return False + logger.info(f"Public Phone is equal, DoS='{changes.current_public_phone}' == NHS UK='{changes.new_public_phone}'") + return False def compare_public_phone(changes_to_dos: ChangesToDoS) -> ChangesToDoS: @@ -151,7 +155,8 @@ def compare_public_phone(changes_to_dos: ChangesToDoS) -> ChangesToDoS: def has_location_changed(changes: ChangesToDoS) -> tuple[bool, bool, DoSLocation | None]: - """Check if address and postcode have changed between dos_service and nhs_entity, + """Check if address and postcode have changed between dos_service and nhs_entity. + Postcode changes are validated against the DoS locations table. Returns: @@ -183,7 +188,7 @@ def has_location_changed(changes: ChangesToDoS) -> tuple[bool, bool, DoSLocation valid_dos_location = get_valid_dos_location(nhs_postcode) valid_dos_postcode = valid_dos_location.postcode if valid_dos_location else None if valid_dos_postcode is None: - log_invalid_nhsuk_postcode(changes.nhs_entity, changes.dos_service) # type: ignore + log_invalid_nhsuk_postcode(changes.nhs_entity, changes.dos_service) if not is_address_same: is_address_same = True changes.new_address = None @@ -202,6 +207,7 @@ def has_location_changed(changes: ChangesToDoS) -> tuple[bool, bool, DoSLocation def compare_location_data(changes_to_dos: ChangesToDoS) -> ChangesToDoS: """Compares and creates changes individually for location data items if needed. + Location data covers the following fields: - address - postcode @@ -278,6 +284,7 @@ def has_standard_opening_times_changed(changes: ChangesToDoS, weekday: str) -> b """Check if the standard opening times have changed for a specific day. Args: + changes (ChangesToDoS): ChangesToDoS holder object weekday (str): The day of the week lowercase to check (e.g. "monday") Returns: @@ -297,20 +304,20 @@ def has_standard_opening_times_changed(changes: ChangesToDoS, weekday: str) -> b setattr(changes, f"current_{weekday}_opening_times", dos_opening_times) setattr(changes, f"new_{weekday}_opening_times", nhs_opening_times) return True - else: - logger.info( - f"{weekday.title()} opening times are equal, so no change. " - f"dos={opening_period_times_from_list(dos_opening_times)} " - f"nhs={opening_period_times_from_list(nhs_opening_times)}", - ) - return False + logger.info( + f"{weekday.title()} opening times are equal, so no change. " + f"dos={opening_period_times_from_list(dos_opening_times)} " + f"nhs={opening_period_times_from_list(nhs_opening_times)}", + ) + return False def has_specified_opening_times_changed(changes: ChangesToDoS) -> bool: - """Check if the specified opening times have changed + """Check if the specified opening times have changed. + Also past specified opening times are removed from the comparison. Returns: - bool: If there are changes to the specified opening times (not valiated) + bool: If there are changes to the specified opening times (not validated) """ dos_spec_open_dates = changes.dos_service.specified_opening_times nhs_spec_open_dates = changes.nhs_entity.specified_opening_times @@ -326,14 +333,14 @@ def has_specified_opening_times_changed(changes: ChangesToDoS) -> bool: extra={"dos": dos_spec_open_dates, "nhs": future_nhs_spec_open_dates}, ) return False - else: - logger.info( - "Specified opening times not equal", - extra={"dos": dos_spec_open_dates, "nhs": future_nhs_spec_open_dates}, - ) - changes.current_specified_opening_times = dos_spec_open_dates - changes.new_specified_opening_times = future_nhs_spec_open_dates - return True + + logger.info( + "Specified opening times not equal", + extra={"dos": dos_spec_open_dates, "nhs": future_nhs_spec_open_dates}, + ) + changes.current_specified_opening_times = dos_spec_open_dates + changes.new_specified_opening_times = future_nhs_spec_open_dates + return True def compare_opening_times(changes_to_dos: ChangesToDoS) -> ChangesToDoS: """Compares and creates changes individually for all opening times if needed. @@ -352,7 +359,7 @@ def compare_opening_times(changes_to_dos: ChangesToDoS) -> ChangesToDoS: if validate_opening_times(dos_service=changes_to_dos.dos_service, nhs_entity=changes_to_dos.nhs_entity): # Compare standard opening times logger.info("Opening times are valid") - for weekday, dos_weekday_key, day_id in zip(WEEKDAYS, DOS_STANDARD_OPENING_TIMES_CHANGE_KEY_LIST, DAY_IDS): + for weekday, dos_weekday_key, day_id in zip(WEEKDAYS, DOS_STANDARD_OPENING_TIMES_CHANGE_KEY_LIST, DAY_IDS): # noqa: B905, E501 if has_standard_opening_times_changed(changes=changes_to_dos, weekday=weekday): changes_to_dos.standard_opening_times_changes[day_id] = getattr( changes_to_dos, @@ -382,15 +389,16 @@ def compare_opening_times(changes_to_dos: ChangesToDoS) -> ChangesToDoS: return changes_to_dos -def set_up_for_services_table_change( +def set_up_for_services_table_change( # noqa: PLR0913 changes_to_dos: ChangesToDoS, change_key: str, - new_value: Any, - previous_value: Any, + new_value: Any, # noqa: ANN401 + previous_value: Any, # noqa: ANN401 service_table_field_name: str, update_service_history: bool = True, ) -> ChangesToDoS: """Runs the prerequisites for a change to the services table. + Including adding the change to the change object, and updating the service history. Args: @@ -427,15 +435,13 @@ def has_palliative_care_changed(changes: ChangesToDoS) -> bool: changes.new_palliative_care = changes.nhs_entity.palliative_care if changes.current_palliative_care != changes.new_palliative_care: logger.info( - f"Palliative Care is not equal, DoS='{changes.current_palliative_care}' " - + f"!= NHS UK='{changes.new_palliative_care}'", + f"Palliative Care is not equal, DoS='{changes.current_palliative_care}' != NHS UK='{changes.new_palliative_care}'", # noqa: E501 ) return True - else: - logger.info( - f"Palliative Care is equal, DoS='{changes.current_palliative_care}' == NHSUK='{changes.new_palliative_care}'", - ) - return False + logger.info( + f"Palliative Care is equal, DoS='{changes.current_palliative_care}' == NHSUK='{changes.new_palliative_care}'", # noqa: E501 + ) + return False def compare_palliative_care(changes_to_dos: ChangesToDoS) -> ChangesToDoS: diff --git a/application/service_sync/dos_data.py b/application/service_sync/dos_data.py index 98afdc883..1e24fd77a 100644 --- a/application/service_sync/dos_data.py +++ b/application/service_sync/dos_data.py @@ -30,8 +30,7 @@ def run_db_health_check() -> None: logger.info("Running health check") with connect_to_dos_db() as connection: cursor = query_dos_db(connection=connection, query="SELECT id FROM services LIMIT 1") - response_rows: list[DictRow] = cursor.fetchall() - if len(response_rows) > 0: + if cursor.fetchall(): logger.info("DoS database is running") else: logger.error("Health check failed - No services found in DoS DB") @@ -39,8 +38,7 @@ def run_db_health_check() -> None: return with connect_to_dos_db_replica() as connection: cursor = query_dos_db(connection=connection, query="SELECT id FROM services LIMIT 1") - response_rows: list[DictRow] = cursor.fetchall() - if len(response_rows) > 0: + if cursor.fetchall(): logger.info("DoS database replica is running") else: logger.error("Health check failed - No services found in DoS DB Replica") @@ -193,10 +191,10 @@ def save_demographics_into_db(connection: Connection, service_id: int, demograph ) cursor.close() return True - else: - # No demographic changes found so no need to update the service - logger.info(f"No demographic changes found for service id {service_id}") - return False + + # No demographic changes found so no need to update the service + logger.info(f"No demographic changes found for service id {service_id}") + return False def save_standard_opening_times_into_db( @@ -259,9 +257,8 @@ def save_standard_opening_times_into_db( else: logger.info(f"No standard opening times to add for dayid: {dayid}") return True - else: - logger.info(f"No standard opening times changes to save for service id {service_id}") - return False + logger.info(f"No standard opening times changes to save for service id {service_id}") + return False def save_specified_opening_times_into_db( @@ -346,9 +343,8 @@ def save_specified_opening_times_into_db( cursor.close() return True - else: - logger.info(f"No specified opening times changes to save for service id {service_id}") - return False + logger.info(f"No specified opening times changes to save for service id {service_id}") + return False def save_palliative_care_into_db( @@ -396,7 +392,7 @@ def save_palliative_care_update() -> None: save_palliative_care_update() return True # If palliative care should be changed but the Z code does not exist, log an error - elif is_changes and not validate_dos_palliative_care_z_code_exists(connection=connection): + elif is_changes and not validate_dos_palliative_care_z_code_exists(connection=connection): # noqa: RET505 add_metric("DoSPalliativeCareZCodeDoesNotExist") logger.error( f"Unable to save palliative care changes for service id {service_id} as the " diff --git a/application/service_sync/format.py b/application/service_sync/format.py index 60cd78600..89c341998 100644 --- a/application/service_sync/format.py +++ b/application/service_sync/format.py @@ -31,14 +31,13 @@ def format_website(website: str) -> str: str: Formatted website """ nhs_uk_website = urlparse(website) - if not nhs_uk_website.netloc: # handle website like www.test.com - if "/" in website: - nhs_uk_website = website.split("/") - nhs_uk_website[0] = nhs_uk_website[0].lower() - nhs_uk_website = "/".join(nhs_uk_website) - else: - nhs_uk_website = urlunparse(nhs_uk_website).lower() - else: # handle website like https://www.test.com + if nhs_uk_website.netloc: # handle websites like https://www.test.com nhs_uk_website = nhs_uk_website._replace(netloc=nhs_uk_website.netloc.lower()) nhs_uk_website = urlunparse(nhs_uk_website) + elif "/" in website: + nhs_uk_website = website.split("/") + nhs_uk_website[0] = nhs_uk_website[0].lower() + nhs_uk_website = "/".join(nhs_uk_website) + else: # handle website like www.test.com + nhs_uk_website = urlunparse(nhs_uk_website).lower() return nhs_uk_website diff --git a/application/service_sync/pending_changes.py b/application/service_sync/pending_changes.py index 9149e0efc..d4446ccee 100644 --- a/application/service_sync/pending_changes.py +++ b/application/service_sync/pending_changes.py @@ -116,7 +116,7 @@ def get_pending_changes(connection: Connection, service_id: str) -> list[Pending cursor = query_dos_db(connection=connection, query=sql_query, query_vars=query_vars) response_rows: list[DictRow] = cursor.fetchall() cursor.close() - if len(response_rows) < 1: + if not response_rows: return None logger.info(f"Pending changes found for Service ID {service_id}") pending_changes: list[PendingChange] = [] diff --git a/application/service_sync/service_histories.py b/application/service_sync/service_histories.py index 479860414..fbebea561 100644 --- a/application/service_sync/service_histories.py +++ b/application/service_sync/service_histories.py @@ -58,8 +58,7 @@ def get_service_history_from_db(self, connection: Connection) -> None: query="Select history from servicehistories where serviceid = %(SERVICE_ID)s", params={"SERVICE_ID": self.service_id}, ) - results: list[Any] = cursor.fetchall() - if results != []: + if results := cursor.fetchall(): # Change History exists in the database logger.debug(f"Service history exists in the database for serviceid {self.service_id}") service_history = results[0]["history"] diff --git a/application/service_sync/service_update_logging.py b/application/service_sync/service_update_logging.py index 4de5ba9af..6ec044ff2 100644 --- a/application/service_sync/service_update_logging.py +++ b/application/service_sync/service_update_logging.py @@ -142,14 +142,12 @@ def log_standard_opening_times_service_update_for_weekday( # noqa: PLR0913 weekday (str): The weekday to log the update for e.g monday """ previous_value = ( - opening_period_times_from_list(open_periods=previous_value.get_openings(weekday), with_space=False) - if not isinstance(previous_value, str) - else previous_value + previous_value if isinstance(previous_value, str) + else opening_period_times_from_list(open_periods=previous_value.get_openings(weekday), with_space=False) ) new_value = ( - opening_period_times_from_list(open_periods=new_value.get_openings(weekday), with_space=False) - if not isinstance(new_value, str) - else new_value + new_value if isinstance(new_value, str) + else opening_period_times_from_list(open_periods=new_value.get_openings(weekday), with_space=False) ) existing_value, updated_value = self.get_opening_times_change(data_field_modified, previous_value, new_value) diff --git a/pyproject.toml b/pyproject.toml index 63bb6c41a..6607f3c71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,9 +37,6 @@ exclude = [ "venv", "scripts", # Ignore scripts folder "application/orchestrator", # Ignore orchestrator folder as it will be removed soon. - "application/service_sync/changes_to_dos.py", - "application/service_sync/compare_data.py", - "application/service_sync/dos_data.py", ] # Same as Black.