def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['BASEDIR'] = os.getcwd() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(app.config['BASEDIR'], TEST_DB) self.app = app.test_client() db.drop_all() db.create_all() self.handle = 'test' # register remove function # self.addCleanup(os.remove, os.path.join(app.config['BASEDIR'], TEST_DB)) self.d_type1, self.d_type2 = DocType(name='test_type1'), DocType( name='test_type2') db.session.bulk_save_objects([self.d_type1, self.d_type2]) self.d_reason1, self.d_reason2 = Reason(name='test_reason1'), Reason( name='test_reason2') db.session.bulk_save_objects([self.d_reason1, self.d_reason2]) db.session.commit() for i in range(5): db.session.add( DocLost(series=f'test{i}', number=f'test{i}', reason_id=choice(Reason.query.all()).id, doc_type_id=choice(DocType.query.all()).id)) self.access_token_test = 'test_token' self.token = OAuth2Token(access_token=self.access_token_test) db.session.add(self.token) db.session.commit()
def post_save_handler(sender, **kwargs): instance = kwargs['instance'] # Find mappings & (re-)index the instance for all of them. for dt in DocType.for_ct(get_ct(instance)): for mapping in dt.docindexmapping_set.all(): mapping.maybe_index_doc(instance)
def has_mapped_doc_index(model): if not has_doc_index(model): return False for dt in DocType.for_ct(get_ct(model)): if dt.docindexmapping_set.count() > 0: return True else: return False
def __set__(self, obj, value): dt = DocType.make(name=value, model=cls, mfield=mfield) attr.__set__(obj, dt)