def test_do_select_all(test_dao):
    """ do_select_all() should return a Tree() object populated with RAMSTKFailureDefinitions instances on success. """
    DUT = dtmFailureDefinition(test_dao)
    _tree = DUT.do_select_all(revision_id=1)

    assert isinstance(_tree, Tree)
    assert isinstance(_tree.get_node(1).data, RAMSTKFailureDefinition)
def test_create_data_model(test_dao):
    """ __init__ should return instance of a FailureDefition data model. """
    DUT = dtmFailureDefinition(test_dao)

    assert isinstance(DUT, dtmFailureDefinition)
    assert isinstance(DUT.tree, Tree)
    assert isinstance(DUT.dao, DAO)
def test_do_delete(test_dao):
    """ do_delete() should return a zero error code on success. """
    DUT = dtmFailureDefinition(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_delete(DUT.last_id)

    assert _error_code == 0
    assert _msg == ('RAMSTK SUCCESS: Deleting an item from the RAMSTK Program '
                    'database.')
def test_do_select(test_dao):
    """ do_select() should return an instance of the RAMSTKFailureDefinition data model on success. """
    DUT = dtmFailureDefinition(test_dao)
    DUT.do_select_all(revision_id=1)

    _definition = DUT.do_select(1)

    assert isinstance(_definition, RAMSTKFailureDefinition)
    assert _definition.definition_id == 1
    assert _definition.definition == 'Failure Definition'
def test_do_update_all(test_dao):
    """ do_update_all() should return a zero error code on success. """
    DUT = dtmFailureDefinition(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_update_all()

    assert _error_code == 0
    assert _msg == ("RAMSTK SUCCESS: Updating all records in the failure "
                    "definition table.")
def test_do_update_non_existent_id(test_dao):
    """ do_update() should return a non-zero error code when passed a Failure Definition ID that doesn't exist. """
    DUT = dtmFailureDefinition(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_update(100)

    assert _error_code == 2207
    assert _msg == ('RAMSTK ERROR: Attempted to save non-existent Failure '
                    'Definition ID 100.')
def test_do_insert(test_dao):
    """ do_insert() should return False on success. """
    DUT = dtmFailureDefinition(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_insert(revision_id=1)

    assert _error_code == 0
    assert _msg == ('RAMSTK SUCCESS: Adding one or more items to the RAMSTK Program '
                    'database.')
    assert DUT.last_id == 2
def test_do_update(test_dao):
    """ do_update() should return a zero error code on success. """
    DUT = dtmFailureDefinition(test_dao)
    DUT.do_select_all(revision_id=1)

    _definition = DUT.do_select(1)
    _definition.definition = 'Test Failure Definition'

    _error_code, _msg = DUT.do_update(1)

    assert _error_code == 0
    assert _msg == ('RAMSTK SUCCESS: Updating the RAMSTK Program database.')
def test_do_select_non_existent_id(test_dao):
    """ do_select() should return None when a non-existent Definition ID is requested. """
    DUT = dtmFailureDefinition(test_dao)
    _definition = DUT.do_select(100)

    assert _definition is None