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 add_link(self, payload): ''' This add link command will send a ``CONNECT`` control message to device application. We will check the device feature lock as first. Then, record the link to ``Link`` for future lookup. ''' da_id = UUID(payload['da_id']) mode = self.get_mode(payload.keys()) feature = payload[mode] if Link.select(payload['da_id'], feature, mode): return self.send_error(payload, reason='Link already exists') elif payload.get('func') and not UserFunction.select(payload['func']): return self.send_error( payload, reason='Function unknown. Please add it first.') return self._add_link(da_id, mode, feature, payload)
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_add(_link): assert Link.add('id', 'feature', 'idf', 'topic') assert Link.select() == {('id', 'feature', 'idf'): 'topic'}
def _link(): assert Link.clear() assert Link.select() == {} yield assert Link.clear() assert Link.select() == {}