def test_treatment_table_treatment_table_entry_relationship(self): table1 = TreatmentTable(name='Table 1') table2 = TreatmentTable(name='Table 2') entry1 = TreatmentTableEntry() entry2 = TreatmentTableEntry() # before connecting self.assertEqual(len(table1.treatment_table_entries.all()), 0) self.assertEqual(len(table2.treatment_table_entries.all()), 0) # after connecting entry1.treatment_table = table1 entry2.treatment_table = table1 self.assertEqual(len(table1.treatment_table_entries.all()), 2) self.assertEqual(table1, entry1.treatment_table) self.assertEqual(table1, entry2.treatment_table) self.assertTrue(entry1 in table1.treatment_table_entries.all()) self.assertTrue(entry2 in table1.treatment_table_entries.all()) self.assertEqual(len(table2.treatment_table_entries.all()), 0) self.assertNotEqual(table2, entry1.treatment_table) self.assertNotEqual(table2, entry2.treatment_table) self.assertFalse(entry1 in table2.treatment_table_entries.all()) self.assertFalse(entry2 in table2.treatment_table_entries.all())
def test_database_cascade(self): # User and PatientNote user = User(first_name='one', last_name='one', username='******', email='*****@*****.**', password='******') patient_note = PatientNote(title='title', notes='notes') patient_note.user = user db.session.add_all([user, patient_note]) db.session.commit() db.session.delete(user) db.session.commit() self.assertEqual(len(PatientNote.query.all()), 0) # User and Appointment user = User(first_name='one', last_name='one', username='******', email='*****@*****.**', password='******') today = datetime.utcnow() appointment = Appointment(title='title', description='description', date_start=today, date_end=today) appointment.user = user db.session.add_all([user, appointment]) db.session.commit() db.session.delete(user) db.session.commit() self.assertEqual(len(Appointment.query.all()), 0) # Patient and PatientNote patient = Patient(first_name='patient1', last_name='patient1', email='*****@*****.**') patient_note = PatientNote(title='title', notes='notes') patient_note.patient = patient db.session.add_all([patient, patient_note]) db.session.commit() db.session.delete(patient) db.session.commit() self.assertEqual(len(PatientNote.query.all()), 0) # Patient and Appointment patient = Patient(first_name='patient1', last_name='patient1', email='*****@*****.**') appointment = Appointment(title='title', description='description', date_start=today, date_end=today) appointment.patient = patient db.session.add_all([patient, appointment]) db.session.commit() db.session.delete(patient) db.session.commit() self.assertEqual(len(Appointment.query.all()), 0) # Treatment and Appointment treatment = Treatment(name='treatment1') appointment = Appointment(title='title', description='description', date_start=today, date_end=today) appointment.treatment = treatment db.session.add_all([treatment, appointment]) db.session.commit() db.session.delete(treatment) db.session.commit() self.assertEqual(len(Appointment.query.all()), 0) # Hospital and User user = User(first_name='one', last_name='one', username='******', email='*****@*****.**', password='******') hospital = Hospital(name='hospital') user.hospital = hospital db.session.add_all([hospital, user]) db.session.commit() db.session.delete(hospital) db.session.commit() self.assertEqual(len(User.query.all()), 0) # Hospital and Treatment treatment = Treatment(name='treatment1') hospital = Hospital(name='hospital') treatment.hospital = hospital db.session.add_all([hospital, treatment]) db.session.commit() db.session.delete(hospital) db.session.commit() self.assertEqual(len(Treatment.query.all()), 0) # TreatmentTable and TreatmentTableEntry table = TreatmentTable(name='table') entry = TreatmentTableEntry() entry.treatment_table = table db.session.add_all([table, entry]) db.session.commit() db.session.delete(table) db.session.commit() self.assertEqual(len(TreatmentTableEntry.query.all()), 0) # TreatmentTable and Patient table = TreatmentTable(name='table') patient = Patient(first_name='patient1', last_name='patient1', email='*****@*****.**') table.patient = patient db.session.add_all([table, patient]) db.session.commit() db.session.delete(patient) db.session.commit() self.assertEqual(len(TreatmentTable.query.all()), 0) # TreatmentTableEntry and Treatment treatment = Treatment(name='treatment') entry = TreatmentTableEntry() entry.treatment = treatment db.session.add_all([treatment, entry]) db.session.commit() db.session.delete(treatment) db.session.commit() self.assertEqual(len(TreatmentTableEntry.query.all()), 0)