def test_do_select_all(test_dao):
    """ do_select_all() should return a treelib Tree() on success when selecting SimilarItems. """
    DUT = dtmSimilarItem(test_dao)
    _tree = DUT.do_select_all(revision_id=1)

    assert isinstance(_tree, Tree)
    assert isinstance(_tree.get_node(2).data, RAMSTKSimilarItem)
def test_create_similar_item_data_model(test_dao):
    """ __init__ should return instance of SimilarItem data model. """
    DUT = dtmSimilarItem(test_dao)

    assert isinstance(DUT, dtmSimilarItem)
    assert isinstance(DUT.tree, Tree)
    assert isinstance(DUT.dao, DAO)
def test_do_select_non_existent_id(test_dao):
    """ do_select() should return None when a non-existent SimilarItem ID is requested. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    _similar_item = DUT.do_select(100)

    assert _similar_item is None
def test_do_delete(test_dao):
    """ do_delete() should return a zero error code on success. """
    DUT = dtmSimilarItem(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_children(test_dao):
    """ do_select_children() should return the immediate subtree of the passed node ID. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    _nodes = DUT.do_select_children(1)

    assert isinstance(_nodes, list)
    assert isinstance(_nodes[0].data, RAMSTKSimilarItem)
    assert _nodes[0].identifier == 2
def test_do_update_non_existent_id(test_dao):
    """ do_update() should return a non-zero error code when passed an SimilarItem ID that doesn't exist. """
    DUT = dtmSimilarItem(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 SimilarItem "
                    "ID 100.")
def test_do_select(test_dao):
    """ do_select() should return an instance of the RAMSTKSimilarItem data model on success. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    _similar_item = DUT.do_select(2)

    assert isinstance(_similar_item, RAMSTKSimilarItem)
    assert _similar_item.hardware_id == 2
    assert _similar_item.change_description_1 == ''
    assert _similar_item.parent_id == 1
def test_do_update_all(test_dao):
    """ do_update_all() should return a zero error code on success. """
    DUT = dtmSimilarItem(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 line items in the similar item "
        "analysis worksheet.")
def test_do_update(test_dao):
    """ do_update() should return a zero error code on success. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    _similar_item = DUT.do_select(1)
    _similar_item.n_sub_systems = 2

    _error_code, _msg = DUT.do_update(1)

    assert _error_code == 0
    assert _msg == ("RAMSTK SUCCESS: Updating the RAMSTK Program database.")
Exemple #10
0
def test_do_insert(test_dao):
    """ do_insert() should return a zero error code on success. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_insert(revision_id=1,
                                      hardware_id=15,
                                      parent_id=1)

    assert _error_code == 0
    assert _msg == ("RAMSTK SUCCESS: Adding one or more items to the RAMSTK "
                    "Program database.")
    assert DUT.last_id == 15
Exemple #11
0
def test_do_calculate_user_defined(test_dao):
    """ do_calculate() should return False on success when using user defined similar item analysis. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    _node = DUT.do_select(1)
    _node.method_id = 2
    _node.change_factor_1 = 0.75
    _node.change_factor_2 = 1.2
    _node.change_factor_3 = 0.95
    _node.change_factor_4 = 1.05
    _node.function_1 = 'hr * pi1 * pi2 * pi3 *pi4'

    assert not DUT.do_calculate(1, hazard_rate=2.5003126e-06)
    assert _node.result_1 == pytest.approx(2.2446556e-06)
Exemple #12
0
def test_do_roll_up(test_dao):
    """ do_roll_up() should return False on success. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    for _node in DUT.do_select_children(1):
        _attributes = _node.data.get_attributes()
        _attributes['change_description_1'] = ('This is change description 1 '
                                               'for Node ID: {0:d}').format(
                                                   _attributes['hardware_id'])
        _node.data.set_attributes(_attributes)
    DUT.do_update_all()

    assert not DUT.do_roll_up(1)
    assert DUT.do_select(1).get_attributes()['change_description_1'] == (
        'This is change description 1 for Node ID: 2\n\nThis is change '
        'description 1 for Node ID: 3\n\nThis is change description 1 for '
        'Node ID: 4\n\nThis is change description 1 for Node ID: 5\n\n')
Exemple #13
0
def test_do_calculate_topic_633(test_dao):
    """ do_calculate() should return False on success when using Topic 633 similar item analysis. """
    DUT = dtmSimilarItem(test_dao)
    DUT.do_select_all(revision_id=1)

    _node = DUT.do_select(1)
    _node.method_id = 1
    _node.temperature_from = 27.5
    _node.temperature_to = 35.0
    _node.quality_from_id = 2
    _node.quality_to_id = 3
    _node.environment_from_id = 1
    _node.environment_to_id = 3

    assert not DUT.do_calculate(1, hazard_rate=2.5003126e-06)
    assert _node.change_factor_1 == 0.6
    assert _node.change_factor_2 == 0.3
    assert _node.change_factor_3 == 0.9
    assert _node.result_1 == pytest.approx(1.5434028e-05)