Esempio n. 1
0
def test_request_do_insert_function_primary_key_violation(
        test_dao, test_configuration, test_csv_file_function):
    """
    request_do_insert() should return a three error code and count of zero
    inserted entities when there is a primary key violation.
    """
    DUT = dtcImports(test_dao, test_configuration, test=True)

    DUT.request_do_read_input('csv', test_csv_file_function)

    for _idx, _key in enumerate(
            DUT._dtm_data_model._dic_field_map['Function']):
        DUT.request_do_map_to_field(
            'Function',
            list(DUT._dtm_data_model._input_data)[_idx], _key)

    _count, _error_code, _msg = DUT.request_do_insert('Function')

    assert _count == 0
    assert _error_code == 3
Esempio n. 2
0
def test_request_do_map_field_function(test_dao, test_configuration,
                                       test_csv_file_function):
    """request_do_map_field() should return None."""
    DUT = dtcImports(test_dao, test_configuration, test=True)

    DUT.request_do_read_input('csv', test_csv_file_function)

    for _idx, _key in enumerate(
            DUT._dtm_data_model._dic_field_map['Function']):
        DUT.request_do_map_to_field(
            'Function',
            list(DUT._dtm_data_model._input_data)[_idx], _key)

    assert DUT._dtm_data_model._dic_field_map['Function'] == OrderedDict([
        ('Revision ID', 'Revision ID'), ('Function ID', 'Function ID'),
        ('Level', 'Level'), ('Function Code', 'Function Code'),
        ('Function Name', 'Function Name'), ('Parent', 'Parent'),
        ('Remarks', 'Remarks'), ('Safety Critical', 'Safety Critical'),
        ('Type', 'Type')
    ])
Esempio n. 3
0
def test_request_do_read_input_csv(test_dao, test_configuration,
                                   test_csv_file_function):
    """
    request_do_read_input() should return None when reading a CSV file."""
    DUT = dtcImports(test_dao, test_configuration, test=True)

    assert DUT.request_do_read_input('csv', test_csv_file_function) is None
    assert isinstance(DUT._dtm_data_model._input_data, pd.core.frame.DataFrame)
    assert list(DUT._dtm_data_model._input_data) == [
        'Revision ID', 'Function ID', 'Level', 'Function Code',
        'Function Name', 'Parent', 'Remarks', 'Safety Critical', 'Type'
    ]
    assert list(DUT._dtm_data_model._input_data.values[0]) == [
        1, 4, 1, 'PRESS-001', 'Maintain system pressure.', 0,
        'This is a function that is about system pressure.  This remarks box also needs to be larger.',
        1, 0
    ]
    assert list(DUT._dtm_data_model._input_data.values[1]) == [
        1, 5, 1, 'FLOW-001', 'Maintain system flow.', 0,
        'These are remarks associated with the function FLOW-001.  The remarks box needs to be bigger.',
        0, 0
    ]
Esempio n. 4
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."))
Esempio n. 5
0
def test_create_data_controller(test_dao, test_configuration):
    """__init__() should create and instance of the Import data controller."""
    DUT = dtcImports(test_dao, test_configuration, test=True)

    assert isinstance(DUT, dtcImports)
    assert isinstance(DUT._dtm_data_model, dtmImports)