def test_dao_db_delete_no_item(test_configuration): """ db_delete() should return a 1005 error code on failure. """ DUT = DAO() _database = (test_configuration.RAMSTK_BACKEND + ':///' + TEMPDIR + '/_ramstk_program_db.ramstk') DUT.db_connect(_database) _error_code, _msg = DUT.db_delete(None, DUT.session) assert _error_code == 1 assert _msg == ("RAMSTK ERROR: Deleting an item from the RAMSTK Program " "database.")
def test_dao_db_add(test_configuration): """ db_add() should return a zero error code on success when adding a single record to the database. """ DUT = DAO() _database = (test_configuration.RAMSTK_BACKEND + ':///' + TEMPDIR + '/_ramstk_program_db.ramstk') DUT.db_connect(_database) _error_code, _msg = DUT.db_add([ RAMSTKRevision(), ], DUT.session) assert _error_code == 0 assert _msg == ("RAMSTK SUCCESS: Adding one or more items to the RAMSTK " "Program database.")
def test_dao_db_add_no_item(test_configuration): """ db_add() should return a 1003 error code on failure. """ DUT = DAO() _database = (test_configuration.RAMSTK_BACKEND + ':///' + TEMPDIR + '/_ramstk_program_db.ramstk') DUT.db_connect(_database) _error_code, _msg = DUT.db_add([ None, ], DUT.session) assert _error_code == 1 assert _msg == ("RAMSTK ERROR: Adding one or more items to the RAMSTK " "Program database.")
def test_dao_db_connect(test_configuration): """ db_connect() should return False on success connecting to an SQLite database. """ DUT = DAO() _database = test_configuration.RAMSTK_BACKEND + ':///' + \ test_configuration.RAMSTK_PROG_INFO['database'] assert not DUT.db_connect(_database)
def test_dao_db_delete(test_configuration): """ db_delete() should return a zero error code on success. """ DUT = DAO() _database = (test_configuration.RAMSTK_BACKEND + ':///' + TEMPDIR + '/_ramstk_program_db.ramstk') DUT.db_connect(_database) _revision = RAMSTKRevision() DUT.db_add([ _revision, ], DUT.session) _error_code, _msg = DUT.db_delete(_revision, DUT.session) assert _error_code == 0 assert _msg == ("RAMSTK SUCCESS: Deleting an item from the RAMSTK Program " "database.")
def test_dao_db_update(test_configuration): """ db_update() should return a zero error code on success. """ DUT = DAO() _database = (test_configuration.RAMSTK_BACKEND + ':///' + TEMPDIR + '/_ramstk_program_db.ramstk') DUT.db_connect(_database) _revision = RAMSTKRevision() DUT.db_add([ _revision, ], DUT.session) _revision.availability_logistics = 0.9959 _revision.availability_mission = 0.9999 _error_code, _msg = DUT.db_update(DUT.session) assert _error_code == 0 assert _msg == ("RAMSTK SUCCESS: Updating the RAMSTK Program database.")
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."))