예제 #1
0
def test_create_entity(mock_get_entitytype, mock_get_entity):
    dn = "Network=One,Element=Two"

    entitytype = EntityType(33, "testtype", "")
    parent_entity = Entity(42, "One", 18, "Network=One", None)

    mock_conn = mock.Mock()
    mock_cursor = mock.Mock()
    mock_conn.cursor.return_value = mock_cursor

    mock_cursor.fetchone.return_value = (
        1,               # id
        datetime.now(),  # first_appearance
        'Two',           # name
        33,              # entitytype_id
        dn,              # dn
        42               # parent_id
    )

    mock_get_entitytype.return_value = entitytype
    mock_get_entity.return_value = parent_entity

    entity = helpers.create_entity(mock_conn, dn)

    assert entity.name == "Two"
    eq_(entity.entitytype_id, entitytype.id)
    assert entity.dn == dn
    assert entity.parent_id == parent_entity.id
예제 #2
0
def get_or_create_entity(conn, dn):
    try:
        entity = get_entity(conn, dn)
    except NoSuchEntityError:
        entity = create_entity(conn, dn)

    return entity
예제 #3
0
def test_create_entity_empty_dn():
    dn = ""

    mock_conn = mock.Mock()

    helpers.create_entity(mock_conn, dn)