Skip to content

Commit

Permalink
Better fixtures
Browse files Browse the repository at this point in the history
Better fixtures
  • Loading branch information
Ryan Faircloth committed Jun 28, 2019
1 parent 8a48a06 commit 3227350
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 77 deletions.
104 changes: 42 additions & 62 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 22 additions & 15 deletions tests/test_poc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@
import splunklib.results as results
import splunklib.client as client
from time import sleep

import pytest

env = Environment(extensions=['jinja2_time.TimeExtension'])
word_url = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = urllib.request.urlopen(word_url)
long_txt = response.read().decode()
words = long_txt.splitlines()

@pytest.fixture
def setup_wordlist():

word_url = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = urllib.request.urlopen(word_url)
long_txt = response.read().decode()
return long_txt.splitlines()

@pytest.fixture
def setup_splunk():
return client.connect(username="admin", password="Changed@11", host="splunk", port="8089")

def sendsingle(message):
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('sc4s', 514)

sock.connect(server_address)
sock.sendall(str.encode(message))
sock.close()


def splunk_single(search):
service = client.connect(username="admin", password="Changed@11", host="splunk", port="8089")
def splunk_single(service,search):
kwargs_normalsearch = {"exec_mode": "normal"}
tried = 0
while True:
Expand Down Expand Up @@ -60,17 +65,19 @@ def splunk_single(search):
return resultCount, eventCount


def test_defaultroute(record_property):
host = "{}-{}".format(random.choice(words), random.choice(words))
def test_defaultroute(record_property,setup_wordlist,setup_splunk):
host = "{}-{}".format(random.choice(setup_wordlist), random.choice(setup_wordlist))

t = env.from_string("{{ mark }} {% now 'utc', '%b %d %H:%M:%S' %}.000z {{ host }} sc4s_default[0]: test")
message = t.render(mark="<111>1", host=host)
mt = env.from_string("{{ mark }} {% now 'utc', '%b %d %H:%M:%S' %}.000z {{ host }} sc4s_default[0]: test\n")
message = mt.render(mark="<111>1", host=host)

sendsingle(message)

search = 'search "{}" | head 10'.format(host)
st= env.from_string("search \"{{ host }}\" | head 2")
search = st.render(host=host)

resultCount, eventCount = splunk_single(setup_splunk,search)

resultCount, eventCount = splunk_single(search)
record_property("host", host)
record_property("resultCount", resultCount)
record_property("message", message)
Expand Down

0 comments on commit 3227350

Please sign in to comment.