Skip to content

Commit

Permalink
Added unit tests for StringSubstitutionFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteggink committed Aug 8, 2016
1 parent 97cc883 commit ca8c0f7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/filters/configs/stringsubstitutionfilter.cfg
@@ -0,0 +1,18 @@
# Config file for unit testing StringSubstitutionFilter.

[etl]
chains = input_string_file|string_sub_filter|packet_buffer|output_std

[input_string_file]
class = inputs.fileinput.StringFileInput
file_path = tests/data/stringfileinput_formatargs.txt

[string_sub_filter]
class = filters.stringfilter.StringSubstitutionFilter
format_args = greeting:Hello name:NLExtract

[packet_buffer]
class = filters.packetbuffer.PacketBuffer

[output_std]
class = outputs.standardoutput.StandardOutput
38 changes: 38 additions & 0 deletions tests/filters/test_string_substitution_filter.py
@@ -0,0 +1,38 @@
import os

from stetl.etl import ETL
from stetl.filters.packetbuffer import PacketBuffer
from stetl.filters.stringfilter import StringSubstitutionFilter
from tests.stetl_test_case import StetlTestCase

class StringSubstitutionFilterTest(StetlTestCase):
"""Unit tests for StringSubstitutionFilter"""

def setUp(self):
super(StringSubstitutionFilterTest, self).setUp()

# Initialize Stetl
curr_dir = os.path.dirname(os.path.realpath(__file__))
cfg_dict = {'config_file': os.path.join(curr_dir, 'configs/stringsubstitutionfilter.cfg')}
self.etl = ETL(cfg_dict)

def test_class(self):
chain = StetlTestCase.get_chain(self.etl)
section = StetlTestCase.get_section(chain, 1)
class_name = self.etl.configdict.get(section, 'class')

self.assertEqual('filters.stringfilter.StringSubstitutionFilter', class_name)

def test_instance(self):
chain = StetlTestCase.get_chain(self.etl)

self.assertTrue(isinstance(chain.get_by_index(1), StringSubstitutionFilter))

def test_execute(self):
chain = StetlTestCase.get_chain(self.etl)
chain.run()

buffer_filter = chain.get_by_class(PacketBuffer)
packet_list = buffer_filter.packet_list

self.assertEqual(packet_list[0].data, 'Hello NLExtract!')

0 comments on commit ca8c0f7

Please sign in to comment.