예제 #1
0
    def test_cortex_sync(self):
        core0 = s_cortex.openurl('ram://')
        core1 = s_cortex.openurl('ram://')

        core0.on('core:sync', core1.sync )

        tufo0 = core0.formTufoByProp('foo','bar',baz='faz')
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertEqual( tufo1[1].get('foo'), 'bar' )
        self.assertEqual( tufo1[1].get('foo:baz'), 'faz' )

        tufo0 = core0.addTufoTag(tufo0,'hehe')
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertTrue( s_tags.tufoHasTag(tufo1,'hehe') )

        core0.delTufoTag(tufo0,'hehe')
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertFalse( s_tags.tufoHasTag(tufo1,'hehe') )

        core0.delTufo(tufo0)
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertIsNone( tufo1 )
예제 #2
0
    def test_cortex_sync(self):
        core0 = s_cortex.openurl('ram://')
        core1 = s_cortex.openurl('ram://')

        core0.on('core:sync', core1.sync )

        tufo0 = core0.formTufoByProp('foo','bar',baz='faz')
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertEqual( tufo1[1].get('foo'), 'bar' )
        self.assertEqual( tufo1[1].get('foo:baz'), 'faz' )

        tufo0 = core0.addTufoTag(tufo0,'hehe')
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertTrue( s_tags.tufoHasTag(tufo1,'hehe') )

        core0.delTufoTag(tufo0,'hehe')
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertFalse( s_tags.tufoHasTag(tufo1,'hehe') )

        core0.delTufo(tufo0)
        tufo1 = core1.getTufoByProp('foo','bar')

        self.assertIsNone( tufo1 )
예제 #3
0
    def _spliceTufoTagDel(self, act, info, props):
        tag = self._reqSpliceInfo(act, info, 'tag')
        form = self._reqSpliceInfo(act, info, 'form')
        valu = self._reqSpliceInfo(act, info, 'valu')

        item = self.getTufoByProp(form, valu)
        if item == None:
            raise NoSuchTufo('%s=%r' % (form, valu))

        if not s_tags.tufoHasTag(item, tag):
            return None, item

        props['on:%s' % form] = valu

        perm = 'tufo:tag:del:%s*%s' % (form, tag)

        props['perm'] = perm
        props['status'] = 'done'

        item = self.delTufoTag(item, tag)
        splice = self.formTufoByProp('syn:splice', guid(), **props)
        return splice, item
예제 #4
0
파일: common.py 프로젝트: jhsmith/synapse
    def _spliceTufoTagDel(self, act, info, props):
        tag = self._reqSpliceInfo(act,info,'tag')
        form = self._reqSpliceInfo(act,info,'form')
        valu = self._reqSpliceInfo(act,info,'valu')

        item = self.getTufoByProp(form,valu)
        if item == None:
            raise NoSuchTufo('%s=%r' % (form,valu))

        if not s_tags.tufoHasTag(item,tag):
            return None,item

        props['on:%s' % form] = valu

        perm = 'tufo:tag:del:%s*%s' % (form,tag)

        props['perm'] = perm
        props['status'] = 'done'

        item = self.delTufoTag(item,tag)
        splice = self.formTufoByProp('syn:splice',guid(),**props)
        return splice,item
예제 #5
0
    def test_cortex_splice(self):
        core = s_cortex.openurl('ram://')

        ####################################################################
        info = {'form':'foo','valu':'bar','props':{'baz':'faz'}}

        splice,retval = core.splice('visi','tufo:add',info, note='hehehaha')

        self.assertEqual( len(core.getTufosByProp('foo',valu='bar')), 1 )
        self.assertIsNotNone( splice[1].get('syn:splice:reqtime') )

        self.assertEqual( splice[1].get('syn:splice:user'), 'visi' )
        self.assertEqual( splice[1].get('syn:splice:note'), 'hehehaha' )
        self.assertEqual( splice[1].get('syn:splice:perm'), 'tufo:add:foo' )
        self.assertEqual( splice[1].get('syn:splice:action'), 'tufo:add' )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        self.assertEqual( retval[1].get('foo'), 'bar' )
        self.assertEqual( retval[1].get('foo:baz'), 'faz' )

        ####################################################################
        info = {'form':'foo','valu':'bar','prop':'baz','pval':'gronk'}
        splice,retval = core.splice('visi','tufo:set',info)

        self.assertEqual( retval[1].get('foo:baz'), 'gronk')
        self.assertEqual( len(core.getTufosByProp('foo:baz',valu='gronk')), 1 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:prop'), 'baz' )
        self.assertEqual( splice[1].get('syn:splice:act:pval'), 'gronk' )

        ####################################################################
        info = {'form':'foo','valu':'bar','tag':'lol'}
        splice,retval = core.splice('visi','tufo:tag:add',info)

        self.assertTrue( s_tags.tufoHasTag(retval,'lol') )
        self.assertEqual( len(core.getTufosByTag('foo','lol')), 1 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:tag'), 'lol' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        ####################################################################
        info = {'form':'foo','valu':'bar','tag':'lol'}
        splice,retval = core.splice('visi','tufo:tag:del',info)

        self.assertFalse( s_tags.tufoHasTag(retval,'lol') )
        self.assertEqual( len(core.getTufosByTag('foo','lol')), 0 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:tag'), 'lol' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        ####################################################################
        info = {'form':'foo','valu':'bar'}
        splice,retval = core.splice('visi','tufo:del',info)

        self.assertEqual( len(core.getTufosByProp('foo',valu='bar')), 0 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        core.fini()
예제 #6
0
    def test_cortex_splice(self):
        core = s_cortex.openurl('ram://')

        ####################################################################
        info = {'form':'foo','valu':'bar','props':{'baz':'faz'}}

        splice,retval = core.splice('visi','tufo:add',info, note='hehehaha')

        self.assertEqual( len(core.getTufosByProp('foo',valu='bar')), 1 )
        self.assertIsNotNone( splice[1].get('syn:splice:reqtime') )

        self.assertEqual( splice[1].get('syn:splice:user'), 'visi' )
        self.assertEqual( splice[1].get('syn:splice:note'), 'hehehaha' )
        self.assertEqual( splice[1].get('syn:splice:perm'), 'tufo:add:foo' )
        self.assertEqual( splice[1].get('syn:splice:action'), 'tufo:add' )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        self.assertEqual( retval[1].get('foo'), 'bar' )
        self.assertEqual( retval[1].get('foo:baz'), 'faz' )

        ####################################################################
        info = {'form':'foo','valu':'bar','prop':'baz','pval':'gronk'}
        splice,retval = core.splice('visi','tufo:set',info)

        self.assertEqual( retval[1].get('foo:baz'), 'gronk')
        self.assertEqual( len(core.getTufosByProp('foo:baz',valu='gronk')), 1 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:prop'), 'baz' )
        self.assertEqual( splice[1].get('syn:splice:act:pval'), 'gronk' )

        ####################################################################
        info = {'form':'foo','valu':'bar','tag':'lol'}
        splice,retval = core.splice('visi','tufo:tag:add',info)

        self.assertTrue( s_tags.tufoHasTag(retval,'lol') )
        self.assertEqual( len(core.getTufosByTag('foo','lol')), 1 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:tag'), 'lol' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        ####################################################################
        info = {'form':'foo','valu':'bar','tag':'lol'}
        splice,retval = core.splice('visi','tufo:tag:del',info)

        self.assertFalse( s_tags.tufoHasTag(retval,'lol') )
        self.assertEqual( len(core.getTufosByTag('foo','lol')), 0 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:tag'), 'lol' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        ####################################################################
        info = {'form':'foo','valu':'bar'}
        splice,retval = core.splice('visi','tufo:del',info)

        self.assertEqual( len(core.getTufosByProp('foo',valu='bar')), 0 )

        self.assertEqual( splice[1].get('syn:splice:on:foo'), 'bar' )
        self.assertEqual( splice[1].get('syn:splice:act:form'), 'foo' )
        self.assertEqual( splice[1].get('syn:splice:act:valu'), 'bar' )

        core.fini()