def test_mark_project_barcode_check_off(self): pr = ProjectAdaptor(**{'session_class': self.session_class}) pr.start_session() pr.store_project_and_attribute_data(self.data) pr.close_session() mark_project_barcode_check_off( project_igf_id='IGFP001_test1_24-1-18', session_class=self.session_class) # no attribute record pr.start_session() attribute_check = pr.check_project_attributes( project_igf_id='IGFP001_test1_24-1-18', attribute_name='barcode_check') self.assertTrue(attribute_check) pr_attributes = pr.get_project_attributes( project_igf_id='IGFP001_test1_24-1-18', attribute_name='barcode_check') for pr_attribute in pr_attributes.to_dict(orient='records'): self.assertEqual(pr_attribute['attribute_value'], 'OFF') pr_attributes = pr.get_project_attributes( project_igf_id='IGFP002_test1_24-1-18', attribute_name='barcode_check') for pr_attribute in pr_attributes.to_dict(orient='records'): self.assertEqual(pr_attribute['attribute_value'], 'ON') pr.close_session() mark_project_barcode_check_off( project_igf_id='IGFP002_test1_24-1-18', session_class=self.session_class) # barcode check ON pr.start_session() pr_attributes = pr.get_project_attributes( project_igf_id='IGFP002_test1_24-1-18', attribute_name='barcode_check') for pr_attribute in pr_attributes.to_dict(orient='records'): self.assertEqual(pr_attribute['attribute_value'], 'OFF') pr_attributes = pr.get_project_attributes( project_igf_id='IGFP003_test1_24-1-18', attribute_name='barcode_check') for pr_attribute in pr_attributes.to_dict(orient='records'): self.assertEqual(pr_attribute['attribute_value'], 'OFF') pr.close_session() mark_project_barcode_check_off( project_igf_id='IGFP003_test1_24-1-18', session_class=self.session_class) # barcode check OFF pr.start_session() pr_attributes = pr.get_project_attributes( project_igf_id='IGFP003_test1_24-1-18', attribute_name='barcode_check') for pr_attribute in pr_attributes.to_dict(orient='records'): self.assertEqual(pr_attribute['attribute_value'], 'OFF') pr.close_session()
def mark_project_barcode_check_off(project_igf_id, session_class, barcode_check_attribute='barcode_check', barcode_check_val='OFF'): ''' A utility method for marking project barcode check as off using the project_igf_id :param project_igf_id: A project_igf_id string :param session_class: A db session class object :param barcode_check_attribute: A text keyword for barcode check attribute, default barcode_check :param barcode_check_val: A text for barcode check attribute value, default is 'OFF' ''' try: db_connected = False pr = ProjectAdaptor(**{'session_class': session_class}) pr.start_session() db_connected = True pr_attributes = pr.check_project_attributes( project_igf_id=project_igf_id, attribute_name=barcode_check_attribute ) # check for the existing project attribute if pr_attributes: # if attribute present, then modify it project = pr.fetch_project_records_igf_id( project_igf_id=project_igf_id) # fetch project info query=pr.session.\ query(Project_attribute).\ filter(Project_attribute.attribute_name==barcode_check_attribute).\ filter(Project_attribute.project_id==project.project_id).\ update({Project_attribute.attribute_value:barcode_check_val,}, synchronize_session=False) # create query for fetching attribute records and modify attribute records else: # if project attribute is not present, store it data = [{ 'project_igf_id': project_igf_id, 'attribute_name': barcode_check_attribute, 'attribute_value': barcode_check_val }] # create data structure for the attribute table pr.store_project_attributes( data, autosave=False ) # store data to attribute table without auto commit pr.commit_session() except: if db_connected: pr.rollback_session() raise finally: if db_connected: pr.close_session()