def test_set_state_for_file_when_file_in_black_list(config, blacklist_for_centre, testing_centres): centre = Centre(config, config.CENTRES[0]) centre_file = CentreFile("AP_sanger_report_200503_2338.csv", centre) centre_file.set_state_for_file() assert centre_file.file_state == CentreFileState.FILE_IN_BLACKLIST
def test_is_valid_date_format(centre_file: CentreFile) -> None: assert centre_file.is_valid_date_format({}, 1, FIELD_DATE_TESTED) == (True, {}) date_time = datetime(year=2020, month=11, day=22, hour=4, minute=36, second=38, tzinfo=timezone.utc) # "Normal" datetime, seen most of the time, with timezone row: ModifiedRow = { FIELD_DATE_TESTED: date_time.strftime("%Y-%m-%d %H:%M:%S %Z") } assert centre_file.is_valid_date_format(row, 1, FIELD_DATE_TESTED) == ( True, { "year": f"{date_time.year:02}", "month": f"{date_time.month:02}", "day": f"{date_time.day:02}", "time": date_time.strftime("%H:%M:%S"), "timezone_name": date_time.tzname(), }, ) # "Normal" datetime, seen most of the time, without timezone row = {FIELD_DATE_TESTED: date_time.strftime("%Y-%m-%d %H:%M:%S")} assert centre_file.is_valid_date_format(row, 1, FIELD_DATE_TESTED) == ( True, { "year": f"{date_time.year:02}", "month": f"{date_time.month:02}", "day": f"{date_time.day:02}", "time": date_time.strftime("%H:%M:%S"), "timezone_name": None, }, ) # other format row = {FIELD_DATE_TESTED: date_time.strftime("%d/%m/%Y %H:%M")} assert centre_file.is_valid_date_format(row, 1, FIELD_DATE_TESTED) == ( True, { "year": f"{date_time.year:02}", "month": f"{date_time.month:02}", "day": f"{date_time.day:02}", "time": date_time.strftime("%H:%M"), }, ) # wrong format row = {FIELD_DATE_TESTED: date_time.strftime("%d %m %Y %H:%M")} assert centre_file.is_valid_date_format(row, 1, FIELD_DATE_TESTED) == (False, {}) # empty date row = {FIELD_DATE_TESTED: ""} assert centre_file.is_valid_date_format(row, 1, FIELD_DATE_TESTED) == (True, {})
def test_set_state_for_file_when_never_seen_before(config, testing_centres): centre = Centre(config, config.CENTRES[0]) centre_file = CentreFile("AP_sanger_report_200503_2338.csv", centre) centre_file.set_state_for_file() assert centre_file.file_state == CentreFileState.FILE_NOT_PROCESSED_YET
def centre_file(centre): yield CentreFile("some_file.csv", centre)