def add_new_donor(): print("Adding new donor...\n") time.sleep(1) clear() donor_sample = Donor() donor_sample.name = DonorManager.data_in(donor_sample, Validate.validate_name, "Name: ", NAME_ERR) donor_sample.weight = DonorManager.data_in( donor_sample, Validate.validate_positive_int, "Weight (in KG): ", POSINT_ERR ) donor_sample.gender = DonorManager.data_in(donor_sample, Validate.validate_gender, "Gender (M/F): ", GEND_ERR) donor_sample.dateofbirth = DonorManager.data_in( donor_sample, Validate.validate_date, "Date of Birth: ", DATE_ERR ) donor_sample.lastdonationdate = DonorManager.data_in( donor_sample, Validate.validate_date, "Last Donation: ", DATE_ERR ) if not donor_sample.is_suitable(): print("\n\t - It seems your donor is not suitable for the donation. =( - ") input("\n\n (Press ENTER to go BACK)") clear() return None donor_sample.wassick = DonorManager.data_in( donor_sample, Validate.validate_sickness, "Was he/she sick in the last month? (Y/N) ", SICK_ERR ) donor_sample.uniqueid = DonorManager.data_in(donor_sample, Validate.validate_id, "Unique ID: ", ID_ERR) donor_sample.bloodtype = DonorManager.data_in( donor_sample, Validate.validate_blood_type, "Blood Type: ", BTYPE_ERR ) donor_sample.expofid = DonorManager.data_in( donor_sample, Validate.validate_date, "Expiration of ID: ", DATE_ERR ) donor_sample.emailaddress = DonorManager.data_in( donor_sample, Validate.validate_email, "Email address: ", EMAIL_ERR ) donor_sample.mobilnumber = DonorManager.data_in( donor_sample, Validate.validate_mobilnumber, "Mobile Number: ", MOBILE_ERR ) with open("Data/donors.csv", "a") as f: f.write(donor_sample.name + ",") f.write(donor_sample.weight + ",") f.write(donor_sample.gender + ",") f.write(donor_sample.dateofbirth + ",") f.write(donor_sample.lastdonationdate + ",") f.write(donor_sample.wassick + ",") f.write(donor_sample.uniqueid + ",") f.write(donor_sample.expofid + ",") f.write(donor_sample.bloodtype + ",") f.write(donor_sample.generate_hemoglobin_level() + ",") f.write(donor_sample.emailaddress + ",") f.write(donor_sample.mobilnumber + "\n") print("\n - Your donor is added to the csv -\n\n Going back to main menu...") time.sleep(2.5) clear()
def test_donor_old_enough(self): bela = Donor() bela.weight = 75 bela.lastdonationdate = "2014.01.01" bela.dateofbirth = "1956.01.01" self.assertTrue(bela.is_suitable())
def test_donor_too_young(self): bela = Donor() bela.weight = 75 bela.lastdonationdate = "2014.01.01" bela.dateofbirth = "2014.01.01" self.assertFalse(bela.is_suitable())
def test_more_than_three_months(self): bela = Donor() bela.weight = 75 bela.lastdonationdate = (datetime.datetime.today()-datetime.timedelta(days=100)).strftime("%Y.%m.%d") bela.dateofbirth = '1990.02.26' self.assertTrue(bela.is_suitable())
def test_too_early_last_donation(self): bela = Donor() bela.weight = 75 bela.lastdonationdate = (datetime.datetime.today()-datetime.timedelta(days=70)).strftime("%Y.%m.%d") bela.dateofbirth = '1990.02.26' self.assertFalse(bela.is_suitable())
def test_too_skinny(self): bela = Donor() bela.weight = 50 bela.lastdonationdate = '2013.11.05' bela.dateofbirth = '1990.02.26' self.assertFalse(bela.is_suitable())
def test_enough_weight(self): bela = Donor() bela.weight = 51 bela.lastdonationdate = '2013.11.05' bela.dateofbirth = '1990.02.26' self.assertTrue(bela.is_suitable())
def add_new_donor(): print("Adding new donor...\n") time.sleep(1) clear() donor_sample = Donor() donor_sample.name = DonorManager.data_in(donor_sample, Validate.validate_name, "Name: ", NAME_ERR) donor_sample.weight = DonorManager.data_in( donor_sample, Validate.validate_positive_int, "Weight (in KG): ", POSINT_ERR) donor_sample.gender = DonorManager.data_in(donor_sample, Validate.validate_gender, "Gender (M/F): ", GEND_ERR) donor_sample.dateofbirth = DonorManager.data_in( donor_sample, Validate.validate_date, "Date of Birth: ", DATE_ERR) donor_sample.lastdonationdate = DonorManager.data_in( donor_sample, Validate.validate_date, "Last Donation: ", DATE_ERR) if not donor_sample.is_suitable(): print( "\n\t - It seems your donor is not suitable for the donation. =( - " ) input("\n\n (Press ENTER to go BACK)") clear() return None donor_sample.wassick = DonorManager.data_in( donor_sample, Validate.validate_sickness, "Was he/she sick in the last month? (Y/N) ", SICK_ERR) donor_sample.uniqueid = DonorManager.data_in(donor_sample, Validate.validate_id, "Unique ID: ", ID_ERR) donor_sample.bloodtype = DonorManager.data_in( donor_sample, Validate.validate_blood_type, "Blood Type: ", BTYPE_ERR) donor_sample.expofid = DonorManager.data_in(donor_sample, Validate.validate_date, "Expiration of ID: ", DATE_ERR) donor_sample.emailaddress = DonorManager.data_in( donor_sample, Validate.validate_email, "Email address: ", EMAIL_ERR) donor_sample.mobilnumber = DonorManager.data_in( donor_sample, Validate.validate_mobilnumber, "Mobile Number: ", MOBILE_ERR) with open("Data/donors.csv", "a") as f: f.write(donor_sample.name + ",") f.write(donor_sample.weight + ",") f.write(donor_sample.gender + ",") f.write(donor_sample.dateofbirth + ",") f.write(donor_sample.lastdonationdate + ",") f.write(donor_sample.wassick + ",") f.write(donor_sample.uniqueid + ",") f.write(donor_sample.expofid + ",") f.write(donor_sample.bloodtype + ",") f.write(donor_sample.generate_hemoglobin_level() + ",") f.write(donor_sample.emailaddress + ",") f.write(donor_sample.mobilnumber + "\n") print( "\n - Your donor is added to the csv -\n\n Going back to main menu..." ) time.sleep(2.5) clear()