def success(payload): ''' :return: the response of ``add_link`` api call. This handle return *ok* if the ``Link`` record create successfully. The sqlite in-memory will be executed in ``serializable`` ioslation level. If the writting transaction of ``Link`` is failed, we will return a *error* state as response. ''' mode = self.get_mode(payload) try: Link.add(payload['da_id'], payload[mode], mode, topic) except ValueError as err: payload['state'] = 'error' payload['reason'] = 'Link already exists' # update esm worker config and (re)start func = UserFunction.select(payload['func']) if payload.get('func') else None if mode == 'idf': conf = self.esm_worker.idf_confs.copy() conf.append({'src': func, 'topic': topic}) self.esm_worker.idf_confs = conf elif mode == 'odf': conf = self.esm_worker.odf_confs.copy() conf.append({'src': func, 'topic': topic}) self.esm_worker.odf_confs = conf self.esm_worker.start() return payload
def test_link_add_conflict(_link): assert Link.add('id', 'feature', 'idf', 'topic') assert Link.select() == {('id', 'feature', 'idf'): 'topic'} with pytest.raises(ValueError) as err: Link.add('id', 'feature', 'idf', 'topic') assert 'exists' in str(err)
def test_link_pop_key(_link): assert Link.add('id', 'feature', 'idf', 'topic') assert Link.select('id', 'feature', 'idf') == 'topic' assert Link.pop('id', 'feature', 'idf') == 'topic' assert Link.select('id', 'feature', 'idf') is None
def test_link_rm(_link): assert Link.add('id', 'feature', 'idf', 'topic') assert Link.rm('id', 'feature', 'idf')
def test_link_add(_link): assert Link.add('id', 'feature', 'idf', 'topic') assert Link.select() == {('id', 'feature', 'idf'): 'topic'}