Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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
Esempio n. 4
0
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)
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
def test_dwm_init_default_udf():
    """ test Dwm class initializes with default fields empty """
    assert Dwm(name='test', mongo=DB).udfs == {}
Esempio n. 8
0
def test_dwm_init_mongo():
    """ test Dwm class sets MongoDB client """
    assert Dwm(name='test', mongo=DB).mongo == DB
Esempio n. 9
0
def test_dwm_init_name():
    """ test Dwm class sets name variable """
    assert Dwm(name='test', mongo=DB).name == 'test'
Esempio n. 10
0
def test_dwm_initialize():
    """ Test that Dwm class initializes with proper object type """
    assert isinstance(Dwm(name='test', mongo=DB), Dwm)
Esempio n. 11
0
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
Esempio n. 12
0
""" 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)