def test_request_do_insert(test_dao, test_configuration):
    """ request_do_insert() should return False on success. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

    assert not DUT.request_do_insert(
        revision_id=1, hardware_id=10, parent_id=1)
def test_request_do_select_all(test_dao, test_configuration):
    """ request_do_select_all() should return a Tree of RAMSTKSimilarItem data models. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')

    _tree = DUT.request_do_select_all(revision_id=1)

    assert isinstance(_tree, Tree)
    assert isinstance(_tree.get_node(2).data, RAMSTKSimilarItem)
def test_request_do_calculate(test_dao, test_configuration):
    """ request_do_calculate() should return False on success. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

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

    assert not DUT.request_do_calculate(1, hazard_rate=2.5003126e-06)
    assert DUT.request_do_select(1).result_1 == pytest.approx(2.2446556e-06)
def test_request_do_roll_up(test_dao, test_configuration):
    """ request_do_roll_up() should return False on success. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

    for _node in DUT.request_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.request_do_update_all()

    assert not DUT.request_do_roll_up(1)
    assert DUT.request_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 #5
0
    def request_do_open_program(self):
        """
        Request an RAMSTK Program database be opened for analyses.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        _database = None

        if self.RAMSTK_CONFIGURATION.RAMSTK_BACKEND == 'sqlite':
            _database = self.RAMSTK_CONFIGURATION.RAMSTK_BACKEND + ':///' + \
                self.RAMSTK_CONFIGURATION.RAMSTK_PROG_INFO['database']

        # If the database was successfully opened, create an instance of each
        # of the slave data controllers.
        _error_code, _msg = self.ramstk_model.do_open_program(_database)
        if _error_code == 0:
            pub.sendMessage('requestOpen')
            self.dic_controllers['revision'] = dtcRevision(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['function'] = dtcFunction(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['requirement'] = dtcRequirement(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['hardware'] = dtcHardwareBoM(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['validation'] = dtcValidation(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['profile'] = dtcUsageProfile(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['definition'] = dtcFailureDefinition(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['ffmea'] = dtcFMEA(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False,
                functional=True)
            self.dic_controllers['stakeholder'] = dtcStakeholder(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['allocation'] = dtcAllocation(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['hazops'] = dtcHazardAnalysis(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['similaritem'] = dtcSimilarItem(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False)
            self.dic_controllers['dfmeca'] = dtcFMEA(
                self.ramstk_model.program_dao,
                self.RAMSTK_CONFIGURATION,
                test=False,
                functional=False)
            self.dic_controllers['pof'] = dtcPoF(self.ramstk_model.program_dao,
                                                 self.RAMSTK_CONFIGURATION,
                                                 test=False)

            # Find which modules are active for the program being opened.
            self.dic_controllers['options'].request_do_select_all(site=False,
                                                                  program=True)
            _program_info = self.dic_controllers[
                'options'].request_get_options(site=False, program=True)
            self.RAMSTK_CONFIGURATION.RAMSTK_MODULES['function'] = \
                _program_info['function_active']
            self.RAMSTK_CONFIGURATION.RAMSTK_MODULES['requirement'] = \
                _program_info['requirement_active']
            self.RAMSTK_CONFIGURATION.RAMSTK_MODULES['hardware'] = \
                _program_info['hardware_active']
            self.RAMSTK_CONFIGURATION.RAMSTK_MODULES['validation'] = \
                _program_info['vandv_active']

            _page = 1
            for _module in self._lst_modules:
                if self.RAMSTK_CONFIGURATION.RAMSTK_MODULES[_module] == 1:
                    self.RAMSTK_CONFIGURATION.RAMSTK_PAGE_NUMBER[
                        _page] = _module
                    _page += 1

            # TODO: Where to put this code for the status icon?
            _icon = self.RAMSTK_CONFIGURATION.RAMSTK_ICON_DIR + \
                '/32x32/db-connected.png'
            _icon = gtk.gdk.pixbuf_new_from_file_at_size(_icon, 22, 22)
            self.icoStatus.set_from_pixbuf(_icon)
            self.icoStatus.set_tooltip(
                _(u"RAMSTK is connected to program database "
                  u"{0:s}.".format(
                      self.RAMSTK_CONFIGURATION.RAMSTK_PROG_INFO['database'])))

            self.loaded = True

            self.RAMSTK_CONFIGURATION.RAMSTK_USER_LOG.info(_msg)
            if not self.__test:
                pub.sendMessage('openedProgram')

        else:
            self.RAMSTK_CONFIGURATION.RAMSTK_DEBUG_LOG.error(_msg)
            _return = True

        return _return
def test_request_do_calculate_all(test_dao, test_configuration):
    """ request_do_calculate_all() should return False on success. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

    assert not DUT.request_do_calculate_all(hazard_rate=24.5003126e-06)
def test_request_do_update_all(test_dao, test_configuration):
    """ request_do_update_all() should return False on success. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

    assert not DUT.request_do_update_all()
def test_request_do_update_non_existent_id(test_dao, test_configuration):
    """ request_do_update() should return True when attempting to save a non-existent SimilarItem. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

    assert DUT.request_do_update(100)
def test_request_do_select_non_existent_id(test_dao, test_configuration):
    """ request_do_select() should return None when requesting an SimilarItem that doesn't exist. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

    assert DUT.request_do_select(100) is None
Exemple #10
0
def test_request_do_select(test_dao, test_configuration):
    """ request_do_select() should return an RAMSTKSimilarItem data model. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')
    DUT.request_do_select_all(revision_id=1)

    assert isinstance(DUT.request_do_select(2), RAMSTKSimilarItem)
Exemple #11
0
def test_create_similar_item_data_controller(test_dao, test_configuration):
    """ __init__() should return instance of SimilarItem data controller. """
    DUT = dtcSimilarItem(test_dao, test_configuration, test='True')

    assert isinstance(DUT, dtcSimilarItem)
    assert isinstance(DUT._dtm_data_model, dtmSimilarItem)