def test_dwm_init_udf_badpos(): """ test Dwm class raises error with invalid position """ udf_set = { 'badposition': udf_example_good } Dwm(name='test', mongo=DB, udfs=udf_set)
def setup_dwm_instance(name_str, mongo_obj, udfs_dict): """ set up DWM instance :param str name_str: Name of configuration :param MongoClient mongo: MongoDB connection :param dict udfs: dict of udfs to run """ return Dwm(name=name_str, mongo=mongo_obj, udfs=udfs_dict)
def test_dwm_init_udf(): """ test Dwm class initializes with defined UDFs """ udf_set = { 'beforeGenericValLookup': udf_example_good, 'beforeGenericValRegex': udf_example_good, 'beforeFieldSpecificLookup': udf_example_good, 'beforeFieldSpecificRegex': udf_example_good, 'beforeNormLookup': udf_example_good, 'beforeNormRegex': udf_example_good, 'beforeNormIncludes': udf_example_good, 'beforeDerive': udf_example_good, 'afterAll': udf_example_good } assert Dwm(name='test', mongo=DB, udfs=udf_set).udfs == udf_set
def test_dwm_init_fields_badderive(): """ test Dwm class raises error with bad derive type """ fields = { 'field1': { 'lookup': [ 'genericLookup', 'genericRegex', 'fieldSpecificRegex', 'fieldSpecificLookup', 'normLookup', 'normIncludes' ], 'derive': [{ 'type': 'badderive', 'fieldSet': ['field2'], 'options': [] }] } } Dwm(name='test', mongo=DB, fields=fields)
def test_dwm_init_fields(): """ test Dwm class initializes with defined field set """ fields = { 'field1': { 'lookup': [ 'genericLookup', 'genericRegex', 'fieldSpecificRegex', 'fieldSpecificLookup', 'normLookup', 'normIncludes' ], 'derive': [{ 'type': 'deriveIncludes', 'fieldSet': ['field2'], 'options': [] }] } } assert Dwm(name='test', mongo=DB, fields=fields).fields == fields
def test_dwm_init_order_fields(): """ test Dwm class initializes with defined field set in specified order""" field_order = ['field4', 'field3', 'field2', 'field1'] fields = { 'field1': { 'lookup': ['genericLookup', 'genericRegex', 'fieldSpecificRegex', 'fieldSpecificLookup', 'normLookup', 'normIncludes'], 'derive': [ { 'type': 'deriveIncludes', 'fieldSet': ['field2'], 'options': [] } ] }, 'field3': { 'lookup': ['genericLookup', 'genericRegex', 'fieldSpecificRegex', 'fieldSpecificLookup', 'normLookup', 'normIncludes'], 'derive': [ { 'type': 'deriveIncludes', 'fieldSet': ['field2'], 'options': [] } ] }, 'field4': { 'lookup': ['genericLookup', 'genericRegex', 'fieldSpecificRegex', 'fieldSpecificLookup', 'normLookup', 'normIncludes'], 'derive': [] }, 'field2': { 'lookup': ['genericLookup', 'genericRegex', 'fieldSpecificRegex', 'fieldSpecificLookup', 'normLookup', 'normIncludes'], 'derive': [] } } ordered_fields = collections.OrderedDict() for x in field_order: ordered_fields.update({x: fields[x]}) assert Dwm(name='test', mongo=DB, fields=fields, field_order=field_order).fields == ordered_fields
def test_dwm_init_default_udf(): """ test Dwm class initializes with default fields empty """ assert Dwm(name='test', mongo=DB).udfs == {}
def test_dwm_init_mongo(): """ test Dwm class sets MongoDB client """ assert Dwm(name='test', mongo=DB).mongo == DB
def test_dwm_init_name(): """ test Dwm class sets name variable """ assert Dwm(name='test', mongo=DB).name == 'test'
def test_dwm_initialize(): """ Test that Dwm class initializes with proper object type """ assert isinstance(Dwm(name='test', mongo=DB), Dwm)
DB.genericRegex.insert({"pattern": r"^badvalue$"}) # Setup Dwm instance FIELDS = { 'field1': { 'lookup': ['genericRegex'], 'derive': [] }, 'field2': { 'lookup': ['genericRegex'], 'derive': [] } } DWM = Dwm(name='test', mongo=DB, fields=FIELDS) # Let the testing begin def test_dwm_vg_reg_bad(): """ Ensure generic regex occurs """ rec = {'field1': 'BADVALUE'} rec_out, _ = DWM._val_g_regex(rec, {}) #pylint: disable=W0212 assert rec_out == {'field1': ''} def test_dwm_vg_reg_good(): """ Ensure good value not cleared """ rec = {'field1': 'GOODVALUE'} rec_out, _ = DWM._val_g_regex(rec, {}) #pylint: disable=W0212
""" test norm include function """ import mongomock from dwm import Dwm from .test_normIncludes import normIncludes # Setup mongomock db DB = mongomock.MongoClient().db DB.normIncludes.insert_many(normIncludes) # Setup Dwm instance FIELDS = {"field1": {"lookup": ["normIncludes"], "derive": []}} DWM = Dwm(name='test', mongo=DB, fields=FIELDS) FIELDS_OVERWRITE_FALSE = { "field1": { "lookup": [], "derive": [{ "type": "deriveValue", "fieldSet": ["field2"], "options": [] }] } } DWM_OVERWRITE_FALSE_OBJ = Dwm(name='test', mongo=DB, fields=FIELDS_OVERWRITE_FALSE)