示例#1
0
def test_create_preferences_data_controller(test_dao, test_common_dao,
                                            test_configuration):
    """ __init__() should return instance of Preferences data controller. """
    DUT = dtcPreferences(
        test_dao, test_configuration, site_dao=test_common_dao, test='True')

    assert isinstance(DUT, dtcPreferences)
    assert isinstance(DUT._dtm_data_model, dtmPreferences)
示例#2
0
def test_request_get_preferences_user(test_dao, test_common_dao,
                                      test_configuration):
    """ request_get_preferences() should return a dict of program option:value pairs. """
    DUT = dtcPreferences(
        test_dao, test_configuration, site_dao=test_common_dao, test='True')
    DUT.request_do_select_all(site=True, user=True)

    _preferences = DUT.request_get_preferences(site=False, user=True)

    assert isinstance(_preferences, dict)
    assert _preferences.keys() == [
        'hr_multiplier', 'report_size', 'decimal', 'icondir', 'colors',
        'common_db_info', 'datadir', 'tabpos', 'calcreltime', 'logdir',
        'sitedir', 'program_db_info', 'format_files', 'progdir'
    ]
示例#3
0
def test_request_do_update(test_dao, test_common_dao, test_configuration):
    """ request_do_update() should return False on success. """
    DUT = dtcPreferences(
        test_dao, test_configuration, site_dao=test_common_dao, test='True')
    DUT.request_do_select_all(site=True, user=True)

    DUT.request_get_preferences(site=False, user=True)
    DUT._dtm_data_model.user_preferences['hr_multiplier'] = 1.0

    _new_user = RAMSTKUser()
    _new_user.user_lname = 'Rowland'
    _new_user.user_fname = 'Doyle'
    _new_user.user_email = '*****@*****.**'
    _new_user.user_phone = '269.491.4765'
    _new_user.user_group_id = 1
    DUT._dtm_data_model.site_preferences['users'].append(_new_user)

    assert not DUT.request_do_update()
示例#4
0
def test_request_get_preferences_site(test_dao, test_common_dao,
                                      test_configuration):
    """ request_get_preferences() should return a dict of dicts of site option:value pairs. """
    DUT = dtcPreferences(
        test_dao, test_configuration, site_dao=test_common_dao, test='True')
    DUT.request_do_select_all(site=True, user=True)

    _preferences = DUT.request_get_preferences(site=True, user=False)

    assert isinstance(_preferences, dict)
    assert _preferences.keys() == [
        'detection_methods', 'incident_status', 'environment_conditions',
        'action_status', 'measurement_units', 'damage_models', 'workgroups',
        'users', 'hazards', 'action_category', 'load_history', 'stakeholders',
        'rpn_detection', 'manufacturers', 'rpn_occurrence', 'failure_modes',
        'validation_types', 'damaging_conditions', 'measureable_parameters',
        'incident_types', 'rpn_severity', 'requirement_types',
        'incident_category', 'affinity_groups'
    ]
示例#5
0
def test_request_do_select_all(test_dao, test_common_dao, test_configuration):
    """ request_do_select_all() should return a Tree of RAMSTKPreferences data models. """
    DUT = dtcPreferences(
        test_dao, test_configuration, site_dao=test_common_dao, test='True')

    assert not DUT.request_do_select_all(site=True, user=True)
示例#6
0
    def __init__(self, **kwargs):
        """Initialize an instance of the RAMSTK data controller."""
        # Read the site configuration file.
        self.RAMSTK_CONFIGURATION.set_site_variables()
        if self.RAMSTK_CONFIGURATION.set_user_variables():
            _prompt = _(
                u"A user-specific configuration directory could not "
                u"be found at {0:s}.  You will be given the option to "
                u"create and populate this directory.  If you choose "
                u"not to, you will recieve this prompt every time you "
                u"execute RAMSTK.  Would you like to create and populate "
                u"a user-specific configuration directory?").format(
                    self.RAMSTK_CONFIGURATION.RAMSTK_HOME_DIR +
                    "/.config/RAMSTK")
            _dialog = ramstk.RAMSTKMessageDialog(_prompt, '', 'question')
            _response = _dialog.do_run()
            _dialog.do_destroy()

            if _response == gtk.RESPONSE_YES:
                self.RAMSTK_CONFIGURATION.create_user_configuration()

            self.RAMSTK_CONFIGURATION.set_user_variables(first_run=False)

        self.RAMSTK_CONFIGURATION.get_user_configuration()

        # Create loggers.
        (self.RAMSTK_CONFIGURATION.RAMSTK_DEBUG_LOG,
         self.RAMSTK_CONFIGURATION.RAMSTK_USER_LOG,
         self.RAMSTK_CONFIGURATION.RAMSTK_IMPORT_LOG) = \
            _initialize_loggers(self.RAMSTK_CONFIGURATION)

        # Initialize private dictionary instance attributes.

        # Initialize private list instance attributes.
        self.__test = kwargs['test']
        self._lst_modules = [
            'requirement', 'function', 'hardware', 'validation'
        ]

        # Initialize private scalar instance attributes.

        # Initialize public dictionary instance attributes.
        self.dic_controllers = {
            'options': None,
            'allocation': None,
            'definition': None,
            'function': None,
            'revision': None,
            'requirement': None,
            'hardware': None,
            'validation': None,
            'matrices': None,
            'profile': None,
            'ffmea': None,
            'fmea': None,
            'stakeholder': None,
            'hazard': None,
            'similaritem': None,
            'pof': None,
            'imports': None,
            'exports': None,
        }
        self.dic_books = {
            'listbook': None,
            'modulebook': None,
            'workbook': None
        }

        # Define public list attributes.

        # Define public scalar attributes.
        self.icoStatus = gtk.StatusIcon()
        self.loaded = False

        # Connect to the RAMSTK Common database.
        _database = None
        if self.RAMSTK_CONFIGURATION.RAMSTK_COM_BACKEND == 'sqlite':
            _database = self.RAMSTK_CONFIGURATION.RAMSTK_COM_BACKEND + \
                        ':///' + \
                        self.RAMSTK_CONFIGURATION.RAMSTK_COM_INFO['database']
        _dao = DAO()
        _dao.db_connect(_database)

        # Create an instance of the RAMSTK Data Model and load global constants.
        self.ramstk_model = Model(_dao, DAO())
        self.request_do_load_globals()

        # Create an Options module instance and read the Site options.
        self.dic_controllers['options'] = dtcOptions(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            site_dao=_dao,
            test=False)
        self.dic_controllers['options'].request_do_select_all(site=True,
                                                              program=False)

        # Create a Preferences module instance and read the user preferences.
        self.dic_controllers['preferences'] = dtcPreferences(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            site_dao=_dao,
            test=False)
        self.dic_controllers['preferences'].request_do_select_all(site=True,
                                                                  user=True)

        # Create an Import module instance.
        self.dic_controllers['imports'] = dtcImports(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            test=False)

        # Create an Export module instance.
        self.dic_controllers['exports'] = dtcExports(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            test=False)

        # Validate the license.
        # if self._validate_license():
        #    sys.exit(2)

        # Create RAMSTK Books.  These need to be initialized after reading the
        # configuration.
        if self.RAMSTK_CONFIGURATION.RAMSTK_GUI_LAYOUT == 'basic':  # Single window.
            pass
        else:  # Multiple windows.
            self.dic_books['listbook'] = ListBook(self)
            self.dic_books['modulebook'] = ModuleBook(self)
            self.dic_books['workbook'] = WorkBook(self)

        _icon = self.RAMSTK_CONFIGURATION.RAMSTK_ICON_DIR + \
            '/32x32/db-disconnected.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 not currently connected to a "
              u"project database."))