def test_limit_usual(): collection = PatientCollection(CSV_PATH) try: len(collection.limit(8)) assert False, "Iterator should not have __len__ method" except (TypeError, AttributeError): assert True for i, patient in enumerate(collection.limit(8)): true_patient = Patient(*GOOD_PARAMS[i]) for field in PATIENT_FIELDS: assert getattr(patient, field) == getattr(true_patient, field), f"Wrong attr {field} for {GOOD_PARAMS[i]} in limit"
def test_limit_add_record(): collection = PatientCollection(CSV_PATH) limit = collection.limit(len(GOOD_PARAMS) + 10) for _ in range(len(GOOD_PARAMS)): next(limit) new_patient = Patient("Митрофан", "Космодемьянский", "1999-10-15", "79030000000", PASSPORT_TYPE, "4510 000444") new_patient.save() last_patient = next(limit) for field in PATIENT_FIELDS: assert getattr(new_patient, field) == getattr(last_patient, field), f"Wrong attr {field} for changed limit"
def test_limit_remove_records(): collection = PatientCollection(CSV_PATH) limit = collection.limit(4) with open(CSV_PATH, 'w', encoding='utf-8') as f: f.write('') assert len([_ for _ in limit]) == 0, "Limit works wrong for empty file"