Skip to content

Commit

Permalink
Merge pull request #200 from vertexmc/asksort
Browse files Browse the repository at this point in the history
fixes ask cli bug where user cannot lift multiple forms
  • Loading branch information
vertexmc authored Apr 7, 2017
2 parents 2270df0 + 4b65abf commit e04f7a3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
8 changes: 1 addition & 7 deletions synapse/cmds/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ def runCmdOpts(self, opts):
ques = opts.get('query')
core = self.getCmdItem()
resp = core.ask(ques)
# {'oplog': [{'mnem': 'lift', 'add': 0, 'took': 1, 'sub': 0}], 'data': [], 'options': {'uniq': 1}, 'limits': {'touch': None, 'lift': None, 'time': None}}

#props = []
#pvalu = opts.get('props')
#if pvalu != None:
#props = pvalu.split(',')

if opts.get('debug'):

Expand All @@ -50,7 +44,7 @@ def runCmdOpts(self, opts):
self.printf(' %s = %s' % (name,valu))

def nodevalu(t):
return t[1].get( t[1].get('tufo:form') )
return repr( t[1].get( t[1].get('tufo:form') ) )

nodes = list(sorted( resp.get('data'), key=nodevalu))

Expand Down
76 changes: 71 additions & 5 deletions synapse/tests/test_cmds_cortex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import,unicode_literals

import re
from contextlib import contextmanager

import synapse.cortex as s_cortex
Expand Down Expand Up @@ -55,14 +56,16 @@ def test_cmds_quit(self):

def test_cmds_addnode(self):
with self.getDmonCore() as core:
cmdr = self.getCoreCmdr(core)
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)
cmdr.runCmdLine('addnode inet:email visi@vertex.link')
self.nn( core.getTufoByProp('inet:email','visi@vertex.link') )

def test_cmds_addtag(self):

with self.getDmonCore() as core:
cmdr = self.getCoreCmdr(core)
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)

core.formTufoByProp('inet:email','visi@vertex.link')

Expand All @@ -71,10 +74,20 @@ def test_cmds_addtag(self):
node = core.formTufoByProp('inet:email','visi@vertex.link')
self.nn( node[1].get('*|inet:email|woot') )

def test_cmds_addtag_nonodes(self):

with self.getDmonCore() as core:
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)

cmdr.runCmdLine('addtag woot inet:email="visi@vertex.link"')
self.eq( str(outp).strip(), '0 nodes...')

def test_cmds_deltag(self):

with self.getDmonCore() as core:
cmdr = self.getCoreCmdr(core)
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)

node = core.formTufoByProp('inet:email','visi@vertex.link')
core.addTufoTag(node,'woot')
Expand All @@ -84,10 +97,63 @@ def test_cmds_deltag(self):
node = core.getTufoByProp('inet:email','visi@vertex.link')
self.none( node[1].get('*|inet:email|woot') )

def test_cmds_deltag_nonodes(self):

with self.getDmonCore() as core:
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)

cmdr.runCmdLine('deltag woot inet:email="visi@vertex.link"')
self.eq( str(outp).strip(), '0 nodes...')

def test_cmds_ask(self):
# FIXME moar robust output testing
with self.getDmonCore() as core:
cmdr = self.getCoreCmdr(core)
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)
core.formTufoByProp('inet:email','visi@vertex.link')
resp = cmdr.runCmdLine('ask inet:email="visi@vertex.link"')
self.eq( len(resp['data']), 1 )
self.eq( str(outp).strip(), 'visi@vertex.link -')

def test_cmds_ask_debug(self):
with self.getDmonCore() as core:
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)
core.formTufoByProp('inet:email','visi@vertex.link')
resp = cmdr.runCmdLine('ask --debug inet:email="visi@vertex.link"')
self.eq( len(resp['data']), 1 )

outp = str(outp)
terms = ('oplog', 'took', 'options', 'limits')

for term in terms:
self.nn(re.search(term, outp))

def test_cmds_ask_props(self):
with self.getDmonCore() as core:
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)
core.formTufoByProp('inet:email','visi@vertex.link')
resp = cmdr.runCmdLine('ask --props inet:email="visi@vertex.link"')
self.eq( len(resp['data']), 1 )

outp = str(outp)
terms = ('fqdn = vertex.link', 'user = visi')

for term in terms:
self.nn(re.search(term, outp))

def test_cmds_ask_multilift(self):
with self.getDmonCore() as core:
outp = s_output.OutPutStr()
cmdr = s_cmdr.getItemCmdr(core, outp=outp)
core.formTufoByProp('str', 'hehe')
core.formTufoByProp('inet:ipv4', 0)
resp = cmdr.runCmdLine('ask str inet:ipv4')
self.eq( len(resp['data']), 2 )

outp = str(outp)
terms = ('0.0.0.0 -', 'hehe -')

for term in terms:
self.nn(re.search(term, outp))

0 comments on commit e04f7a3

Please sign in to comment.