def after_model_change(self, form, model, is_created): if is_created: create_records(model, self.session) _create_audit_log(model, 'CREATE') else: update_records(self.session) _create_audit_log(model, 'UPDATE')
def test_populates_restricted_word(db): model = VirtualWordCondition(rc_words='tdd, quality') create_records(model, db.session) result = db.session.query(RestrictedWord).all() assert_that(len(result), equal_to(2)) assert_that(result[0].word_phrase, equal_to('tdd')) assert_that(result[1].word_phrase, equal_to('quality'))
def update_records(session): session.query(RestrictedWordCondition).delete() session.query(RestrictedCondition).delete() session.query(RestrictedWord).delete() result = session.query(VirtualWordCondition).all() for row in result: create_records(row, session) session.commit()
def test_populates_restricted_word_condition(db): model = VirtualWordCondition(rc_consenting_body='needs approval', rc_words='tdd, quality') create_records(model, db.session) result = db.session.query(RestrictedWordCondition).all() assert_that(len(result), equal_to(2)) assert_that(result[0].cnd_id, equal_to(1)) assert_that(result[0].word_id, equal_to(1)) assert_that(result[1].cnd_id, equal_to(1)) assert_that(result[1].word_id, equal_to(2))
def test_default_flags(db): model = VirtualWordCondition(rc_consenting_body='needs approval', rc_condition_text='do that', rc_instructions='call me') create_records(model, db.session) result = db.session.query(RestrictedCondition).all() assert_that(len(result), equal_to(1)) assert_that(result[0].consenting_body, equal_to('needs approval')) assert_that(result[0].cnd_text, equal_to('do that')) assert_that(result[0].instructions, equal_to('call me')) assert_that(result[0].allow_use, equal_to('Y')) assert_that(result[0].consent_required, equal_to('N'))
def test_populates_restricted_condition(db): initial = VirtualWordCondition(rc_consenting_body='needs approval', rc_words='tdd, quality') db.session.add(initial) create_records(initial, db.session) result = db.session.query(VirtualWordCondition).all() updated = result[0] updated.rc_consenting_body = 'needs signature' db.session.commit() assert_that(result[0].rc_consenting_body, equal_to('needs signature')) result = db.session.query(VirtualWordCondition).all() assert_that(len(result), equal_to(1)) update_records(db.session) result = db.session.query(RestrictedCondition).all() assert_that(len(result), equal_to(1)) assert_that(result[0].consenting_body, equal_to('needs signature'))
def test_multi_creation(db): one = VirtualWordCondition(rc_consenting_body='needs approval', rc_words='tdd, quality') db.session.add(one) create_records(one, db.session) two = VirtualWordCondition(rc_consenting_body='needs signature', rc_words='bc, royal') db.session.add(two) create_records(two, db.session) three = VirtualWordCondition(rc_consenting_body='needs magic', rc_words='one, two, three, four ,five') db.session.add(three) create_records(three, db.session) result = db.session.query(RestrictedWordCondition).all() assert_that(len(result), equal_to(9))