def test_pictureroot2_not_chosen(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     presenter.pictureroot = "previously"
     presenter.on_pictureroot2_btnbrowse_clicked()
     self.assertEquals(presenter.pictureroot, "previously")
 def test_when_user_selects_different_type(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'type': 'SQLite',
                    'default': True,
                    'pictures': 'nugkui',
                    'file': 'nugkui.db'},
         'quisquis': {'type': 'PostgreSQL',
                      'passwd': False,
                      'pictures': '',
                      'db': 'quisquis',
                      'host': 'localhost',
                      'user': '******'}}
     presenter = ConnMgrPresenter(view)
     # T_0
     self.assertEquals(presenter.connection_name, 'nugkui')
     self.assertTrue(presenter.view.widget_get_visible(
         'sqlite_parambox'))
     # action
     view.widget_set_value('name_combo', 'quisquis')
     presenter.dbtype = 'PostgreSQL'  # who to trigger this in tests?
     presenter.on_name_combo_changed('name_combo')
     # result
     self.assertEquals(presenter.connection_name, 'quisquis')
     presenter.refresh_view()  # in reality this is triggered by gtk view
     self.assertEquals(presenter.dbtype, 'PostgreSQL')
     ## if the above succeeds, the following is riggered by the view!
     #presenter.on_combo_changed('type_combo', 'PostgreSQL')
     # T_1
     self.assertTrue(presenter.view.widget_get_visible(
         'dbms_parambox'))
 def test_when_user_selects_different_type(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     prefs.prefs[bauble.conn_default_pref] = "nugkui"
     prefs.prefs[bauble.conn_list_pref] = {
         "nugkui": {"type": "SQLite", "default": True, "pictures": "nugkui", "file": "nugkui.db"},
         "quisquis": {
             "type": "PostgreSQL",
             "passwd": False,
             "pictures": "",
             "db": "quisquis",
             "host": "localhost",
             "user": "******",
         },
     }
     presenter = ConnMgrPresenter(view)
     # T_0
     self.assertEquals(presenter.connection_name, "nugkui")
     self.assertTrue(presenter.view.widget_get_visible("sqlite_parambox"))
     # action
     view.widget_set_value("name_combo", "quisquis")
     presenter.dbtype = "PostgreSQL"  # who to trigger this in tests?
     presenter.on_name_combo_changed("name_combo")
     # result
     self.assertEquals(presenter.connection_name, "quisquis")
     presenter.refresh_view()  # in reality this is triggered by gtk view
     self.assertEquals(presenter.dbtype, "PostgreSQL")
     ## if the above succeeds, the following is riggered by the view!
     # presenter.on_combo_changed('type_combo', 'PostgreSQL')
     # T_1
     self.assertTrue(presenter.view.widget_get_visible("dbms_parambox"))
示例#4
0
    def test_on_dialog_response_ok_creates_picture_folders_half_exist(self):
        # make sure pictures and thumbs folders respectively do and do not
        # already exist as folders.
        import tempfile
        path = tempfile.mktemp()
        os.mkdir(path)
        view = MockView(combos={'name_combo': [],
                                'type_combo': []})
        prefs.prefs[bauble.conn_list_pref] = {
            'nugkui': {'default': False,
                       'pictures': path,
                       'type': 'SQLite',
                       'file': path + '.db'}}
        (prefs.prefs[prefs.picture_root_pref],
         prefs.prefs[bauble.conn_default_pref],
         ) = os.path.split(path)
        view.reply_file_chooser_dialog = []
        presenter = ConnMgrPresenter(view)
        dialog = MockDialog()
        view.invoked = []
        # invoke action
        presenter.on_dialog_response(dialog, RESPONSE_OK)

        # superfluous action is not performed, view is closed
        # check existence of pictures folder
        self.assertTrue(os.path.isdir(path))
        # check existence of thumbnails folder
        self.assertTrue(os.path.isdir(os.path.join(path, 'thumbs')))
示例#5
0
    def test_on_dialog_response_ok_creates_picture_folders_no_exist(self):
        # make sure thumbnails and pictures folder do not exist.
        import tempfile
        path = tempfile.mktemp()
        # create view and presenter.
        view = MockView(combos={'name_combo': [],
                                'type_combo': []})
        prefs.prefs[bauble.conn_list_pref] = {
            'nugkui': {'default': False,
                       'pictures': path,
                       'type': 'SQLite',
                       'file': path + '.db'}}
        (prefs.prefs[prefs.picture_root_pref],
         prefs.prefs[bauble.conn_default_pref],
         ) = os.path.split(path)
        view.reply_file_chooser_dialog = []
        presenter = ConnMgrPresenter(view)
        dialog = MockDialog()
        view.invoked = []
        # invoke action
        presenter.on_dialog_response(dialog, RESPONSE_OK)

        # check existence of pictures folder
        self.assertTrue(os.path.isdir(path))
        # check existence of thumbnails folder
        self.assertTrue(os.path.isdir(os.path.join(path, 'thumbs')))
示例#6
0
def start_institution_editor():
    glade_path = os.path.join(paths.lib_dir(), "plugins", "garden", "institution.glade")
    from bauble import prefs
    from bauble.editor import GenericEditorView, MockView

    if prefs.testing:
        view = MockView()
    else:
        view = GenericEditorView(glade_path, parent=None, root_widget_name="inst_dialog")
    view._tooltips = {
        "inst_name": _("The full name of the institution."),
        "inst_abbr": _("The standard abbreviation of the " "institution."),
        "inst_code": _("The intitution code should be unique among " "all institions."),
        "inst_contact": _("The name of the person to contact for " "information related to the institution."),
        "inst_tech": _(
            "The email address or phone number of the "
            "person to contact for technical "
            "information related to the institution."
        ),
        "inst_email": _("The email address of the institution."),
        "inst_tel": _("The telephone number of the institution."),
        "inst_fax": _("The fax number of the institution."),
        "inst_addr": _("The mailing address of the institition."),
    }

    o = Institution()
    inst_pres = InstitutionPresenter(o, view)
    response = inst_pres.start()
    if response == gtk.RESPONSE_OK:
        o.write()
        inst_pres.commit_changes()
    else:
        inst_pres.session.rollback()
    inst_pres.session.close()
 def test_file_not_chosen(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     presenter.filename = 'previously'
     presenter.on_file_btnbrowse_clicked()
     self.assertEquals(presenter.filename, 'previously')
示例#8
0
 def test_on_btnbrowse_clicked(self):
     view = MockView()
     exporter = JSONExporter(view)
     view.reply_file_chooser_dialog = ['/tmp/test.json']
     exporter.on_btnbrowse_clicked('button')
     exporter.on_text_entry_changed('filename')
     self.assertEquals(exporter.filename, '/tmp/test.json')
     self.assertEquals(JSONExporter.last_folder, '/tmp')
示例#9
0
 def test_when_selection_huge_ask(self):
     view = MockView()
     exporter = JSONExporter(view)
     exporter.selection_based_on == 'sbo_selection'
     view.selection = range(5000)
     view.reply_yes_no_dialog = [False]
     exporter.run()
     self.assertTrue('run_yes_no_dialog' in view.invoked)
     self.assertEquals(view.reply_yes_no_dialog, [])
 def test_on_dialog_response_cancel(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     dialog = MockDialog()
     view.reply_yes_no_dialog = [False]
     presenter.on_dialog_response(dialog, RESPONSE_CANCEL)
     self.assertFalse("run_message_dialog" in view.invoked)
     self.assertTrue(dialog.hidden)
 def test_on_dialog_response_ok_invalid_params(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     prefs.prefs[bauble.conn_list_pref] = {}
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     dialog = MockDialog()
     presenter.on_dialog_response(dialog, RESPONSE_OK)
     self.assertTrue("run_message_dialog" in view.invoked)
     self.assertTrue(dialog.hidden)
 def test_set_default_toggles_sensitivity(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     prefs.prefs[bauble.conn_default_pref] = "nugkui"
     prefs.prefs[bauble.conn_list_pref] = {
         "nugkui": {"type": "SQLite", "default": True, "pictures": "nugkui", "file": "nugkui.db"}
     }
     presenter = ConnMgrPresenter(view)
     view.widget_set_value("usedefaults_chkbx", True)
     presenter.on_usedefaults_chkbx_toggled("usedefaults_chkbx")
     self.assertFalse(view.widget_get_sensitive("file_entry"))
 def test_on_dialog_close_or_delete(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     # T_0
     self.assertFalse(view.get_window().hidden)
     # action
     presenter.on_dialog_close_or_delete("widget")
     # T_1
     self.assertTrue(view.get_window().hidden)
 def test_two_connection_initialize_default_second(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     prefs.prefs[bauble.conn_list_pref] = {
         "nugkui": {"default": True, "pictures": "nugkui", "type": "SQLite", "file": "nugkui.db"},
         "btuu": {"default": False, "pictures": "btuu", "type": "SQLite", "file": "btuu.db"},
     }
     prefs.prefs[bauble.conn_default_pref] = "bruu"
     presenter = ConnMgrPresenter(view)
     self.assertEquals(presenter.connection_name, "btuu")
     params = presenter.connections[presenter.connection_name]
     self.assertEquals(params["default"], False)
     self.assertFalse(view.widget_get_value("usedefaults_chkbx"))
示例#15
0
 def test_set_default_toggles_sensitivity(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'type': 'SQLite',
                    'default': True,
                    'pictures': 'nugkui',
                    'file': 'nugkui.db'},
         }
     presenter = ConnMgrPresenter(view)
     view.widget_set_value('usedefaults_chkbx', True)
     presenter.on_usedefaults_chkbx_toggled('usedefaults_chkbx')
     self.assertFalse(view.widget_get_sensitive('file_entry'))
 def test_on_dialog_response_ok_valid_params(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     prefs.prefs[bauble.conn_list_pref] = {
         "nugkui": {"default": False, "pictures": "/tmp/nugkui", "type": "SQLite", "file": "/tmp/nugkui.db"}
     }
     prefs.prefs[bauble.conn_default_pref] = "nugkui"
     prefs.prefs[prefs.picture_root_pref] = "/tmp"
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     dialog = MockDialog()
     view.invoked = []
     presenter.on_dialog_response(dialog, RESPONSE_OK)
     self.assertFalse("run_message_dialog" in view.invoked)
     self.assertTrue(dialog.hidden)
     self.assertEquals(prefs.prefs[prefs.picture_root_pref], "/tmp/nugkui")
示例#17
0
 def test_two_connection_initialize_default_second(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': True,
                    'pictures': 'nugkui',
                    'type': 'SQLite',
                    'file': 'nugkui.db'},
         'btuu': {'default': False,
                  'pictures': 'btuu',
                  'type': 'SQLite',
                  'file': 'btuu.db'}}
     prefs.prefs[bauble.conn_default_pref] = 'bruu'
     presenter = ConnMgrPresenter(view)
     self.assertEquals(presenter.connection_name, 'btuu')
     params = presenter.connections[presenter.connection_name]
     self.assertEquals(params['default'], False)
     self.assertFalse(view.widget_get_value('usedefaults_chkbx'))
示例#18
0
 def test_on_dialog_response_ok_valid_params(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': False,
                    'pictures': '/tmp/nugkui',
                    'type': 'SQLite',
                    'file': '/tmp/nugkui.db'}}
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     prefs.prefs[prefs.picture_root_pref] = '/tmp'
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     dialog = MockDialog()
     view.invoked = []
     presenter.on_dialog_response(dialog, RESPONSE_OK)
     self.assertFalse('run_message_dialog' in view.invoked)
     self.assertTrue(dialog.hidden)
     self.assertEquals(prefs.prefs[prefs.picture_root_pref], '/tmp/nugkui')
    def test_on_dialog_response_ok_creates_picture_folders_no_exist(self):
        # make sure thumbnails and pictures folder do not exist.
        import tempfile

        path = tempfile.mktemp()
        # create view and presenter.
        view = MockView(combos={"name_combo": [], "type_combo": []})
        prefs.prefs[bauble.conn_list_pref] = {
            "nugkui": {"default": False, "pictures": path, "type": "SQLite", "file": path + ".db"}
        }
        (prefs.prefs[prefs.picture_root_pref], prefs.prefs[bauble.conn_default_pref]) = os.path.split(path)
        view.reply_file_chooser_dialog = []
        presenter = ConnMgrPresenter(view)
        dialog = MockDialog()
        view.invoked = []
        # invoke action
        presenter.on_dialog_response(dialog, RESPONSE_OK)

        # check existence of pictures folder
        self.assertTrue(os.path.isdir(path))
        # check existence of thumbnails folder
        self.assertTrue(os.path.isdir(os.path.join(path, "thumbs")))
 def test_change_page(self):
     view = MockView()
     m = StoredQueriesModel()
     presenter = StoredQueriesPresenter(m, view)
     m.page = 2
     presenter.refresh_view()
     for i in range(1, 11):
         bname = 'stqr_%02d_button' % i
         self.assertTrue(('widget_set_active',
                          (bname,
                           i == m.page)) in presenter.view.invoked_detailed)
         lname = 'stqr_%02d_label' % i
         self.assertTrue(('widget_set_attributes',
                          (lname, presenter.weight[i == m.page]
                           )) in presenter.view.invoked_detailed)
 def test_one_connection_shown_and_selected_sqlite(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': True,
                    'pictures': 'nugkui',
                    'type': 'SQLite',
                    'file': 'nugkui.db'}}
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     presenter = ConnMgrPresenter(view)
     self.assertEquals(presenter.connection_name, 'nugkui')
     self.assertTrue(presenter.view.widget_get_visible(
         'expander'))
     self.assertFalse(presenter.view.widget_get_visible(
         'noconnectionlabel'))
示例#22
0
    def test_writes_full_taxonomic_info(self):
        "exporting one family: export full taxonomic information below family"

        selection = self.session.query(Family).filter(
            Family.family == u'Orchidaceae').all()
        exporter = JSONExporter(MockView())
        exporter.selection_based_on == 'sbo_selection'
        exporter.include_private = False
        exporter.view.selection = selection
        exporter.filename = self.temp_path
        exporter.run()
        result = json.load(open(self.temp_path))
        self.assertEquals(len(result), 1)
        self.assertEquals(result[0]['rank'], 'familia')
        self.assertEquals(result[0]['epithet'], 'Orchidaceae')
 def test_one_connection_on_remove_confirm_negative(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': True,
                    'pictures': 'nugkui',
                    'type': 'SQLite',
                    'file': 'nugkui.db'}}
     presenter = ConnMgrPresenter(view)
     presenter.view.reply_yes_no_dialog.append(False)
     presenter.on_remove_button_clicked('button')
     ## nothing changes
     self.assertTrue(presenter.view.widget_get_visible(
         'expander'))
     self.assertFalse(presenter.view.widget_get_visible(
         'noconnectionlabel'))
示例#24
0
    def test_writes_complete_database(self):
        "exporting without specifying what: export complete database"

        exporter = JSONExporter(MockView())
        exporter.view.selection = None
        exporter.selection_based_on == 'sbo_selection'
        exporter.include_private = False
        exporter.filename = self.temp_path
        exporter.run()
        ## must still check content of generated file!
        result = json.load(open(self.temp_path))
        self.assertEquals(len(result), 11)
        families = [i for i in result
                    if i['object'] == 'taxon' and i['rank'] == 'familia']
        self.assertEquals(len(families), 2)
        genera = [i for i in result
                  if i['object'] == 'taxon' and i['rank'] == 'genus']
        self.assertEquals(len(genera), 2)
        species = [i for i in result
                   if i['object'] == 'taxon' and i['rank'] == 'species']
        self.assertEquals(len(species), 1)
        target = [
            {"epithet": "Orchidaceae", "object": "taxon", "rank": "familia"},
            {"epithet": "Myrtaceae", "object": "taxon", "rank": "familia"},
            {"author": "R. Br.", "epithet": "Calopogon",
             "ht-epithet": "Orchidaceae", "ht-rank": "familia",
             "object": "taxon", "rank": "genus"},
            {"author": "", "epithet": "Panisea", "ht-epithet": "Orchidaceae",
             "ht-rank": "familia", "object": "taxon", "rank": "genus"},
            {"epithet": "tuberosus", "ht-epithet": "Calopogon",
             "ht-rank": "genus", "hybrid": False, "object": "taxon",
             "rank": "species"},
            {"code": "2015.0001", "object": "accession", "private": False,
             "species": "Calopogon tuberosus"},
            {"code": "2015.0002", "object": "accession", "private": False,
             "species": "Calopogon tuberosus"},
            {"code": "2015.0003", "object": "accession", "private": True,
             "species": "Calopogon tuberosus"},
            {"code": "1", "object": "location"},
            {"accession": "2015.0001", "code": "1", "location": "1",
             "memorial": False, "object": "plant", "quantity": 1},
            {"accession": "2015.0003", "code": "1", "location": "1",
             "memorial": False, "object": "plant", "quantity": 1}]
        for o1 in result:
            self.assertTrue(o1 in target)
        for o2 in target:
            self.assertTrue(o1 in result)
示例#25
0
    def test_writes_partial_taxonomic_info(self):
        "exporting one genus: all species below genus"

        selection = self.session.query(Genus).filter(
            Genus.genus == u'Calopogon').all()
        exporter = JSONExporter(MockView())
        exporter.view.selection = selection
        exporter.selection_based_on == 'sbo_selection'
        exporter.include_private = False
        exporter.filename = self.temp_path
        exporter.run()
        result = json.load(open(self.temp_path))
        self.assertEquals(len(result), 1)
        self.assertEquals(result[0]['rank'], 'genus')
        self.assertEquals(result[0]['epithet'], 'Calopogon')
        self.assertEquals(result[0]['ht-rank'], 'familia')
        self.assertEquals(result[0]['ht-epithet'], 'Orchidaceae')
        self.assertEquals(result[0]['author'], 'R. Br.')
 def test_two_connections_wrong_default_use_first_one(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': True,
                    'pictures': 'nugkui',
                    'type': 'SQLite',
                    'file': 'nugkui.db'},
         'quisquis': {'passwd': False,
                      'pictures': '',
                      'db': 'quisquis',
                      'host': 'localhost',
                      'user': '******',
                      'type': 'Oracle'}}
     prefs.prefs[bauble.conn_default_pref] = 'nonce'
     presenter = ConnMgrPresenter(view)
     as_list = presenter.connection_names
     self.assertEquals(presenter.connection_name, as_list[0])
 def test_one_connection_on_add_confirm_positive(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': True,
                    'pictures': 'nugkui',
                    'type': 'SQLite',
                    'file': 'nugkui.db'}}
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     presenter = ConnMgrPresenter(view)
     presenter.view.reply_entry_dialog.append('new_conn')
     presenter.on_add_button_clicked('button')
     presenter.refresh_view()  # this is done by gtk
     self.assertTrue(('combobox_prepend_text', ['name_combo', 'new_conn'])
                     in presenter.view.invoked_detailed)
     self.assertTrue(('widget_set_value', ['name_combo', 'new_conn', ()])
                     in presenter.view.invoked_detailed)
     print presenter.view.invoked_detailed
     raise SkipTest("related to issue #194")
示例#28
0
    def test_writes_partial_taxonomic_info_species(self):
        "exporting one species: all species below species"

        selection = self.session.query(
            Species).filter(Species.sp == u'tuberosus').join(
            Genus).filter(Genus.genus == u"Calopogon").all()
        exporter = JSONExporter(MockView())
        exporter.view.selection = selection
        exporter.selection_based_on == 'sbo_selection'
        exporter.include_private = False
        exporter.filename = self.temp_path
        exporter.run()
        result = json.load(open(self.temp_path))
        self.assertEquals(len(result), 1)
        self.assertEquals(result[0]['rank'], 'species')
        self.assertEquals(result[0]['epithet'], 'tuberosus')
        self.assertEquals(result[0]['ht-rank'], 'genus')
        self.assertEquals(result[0]['ht-epithet'], 'Calopogon')
        self.assertEquals(result[0]['hybrid'], False)
示例#29
0
 def test_one_connection_shown_and_selected_oracle(self):
     view = MockView(combos={'name_combo': [], 'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'quisquis': {
             'passwd': False,
             'pictures': '',
             'db': 'quisquis',
             'host': 'localhost',
             'user': '******',
             'type': 'Oracle'
         }
     }
     prefs.prefs[bauble.conn_default_pref] = 'quisquis'
     presenter = ConnMgrPresenter(view)
     self.assertEquals(presenter.connection_name, 'quisquis')
     self.assertTrue(presenter.view.widget_get_visible('expander'))
     self.assertTrue(presenter.view.widget_get_visible('dbms_parambox'))
     self.assertFalse(presenter.view.widget_get_visible('sqlite_parambox'))
     self.assertFalse(
         presenter.view.widget_get_visible('noconnectionlabel'))
示例#30
0
 def test_one_connection_shown_removed_message(self):
     view = MockView(combos={'name_combo': [], 'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {
             'default': True,
             'pictures': 'nugkui',
             'type': 'SQLite',
             'file': 'nugkui.db'
         }
     }
     presenter = ConnMgrPresenter(view)
     # T_0
     self.assertTrue(presenter.view.widget_get_visible('expander'))
     self.assertFalse(
         presenter.view.widget_get_visible('noconnectionlabel'))
     # action
     presenter.remove_connection('nugkui')
     # T_1
     self.assertTrue(presenter.view.widget_get_visible('noconnectionlabel'))
     self.assertFalse(presenter.view.widget_get_visible('expander'))
 def test_label_entry_change(self):
     view = MockView()
     m = StoredQueriesModel()
     presenter = StoredQueriesPresenter(m, view)
     bname = 'stqr_04_button'
     presenter.on_button_clicked(bname)
     self.assertEquals(m.page, 4)
     presenter.view.values['stqr_label_entry'] = 'abc'
     presenter.on_label_entry_changed('stqr_label_entry')
     print presenter.view.invoked_detailed
     self.assertEquals(m.label, 'abc')
     self.assertTrue(('widget_set_text',
                      ('stqr_04_label',
                       'abc')) in presenter.view.invoked_detailed)
     presenter.view.values['stqr_label_entry'] = ''
     presenter.on_label_entry_changed('stqr_label_entry')
     self.assertEquals(m.label, '')
     self.assertTrue(('widget_set_text',
                      ('stqr_04_label',
                       '<empty>')) in presenter.view.invoked_detailed)
 def test_two_connection_on_remove_confirm_positive(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': True,
                    'pictures': 'nugkui',
                    'type': 'SQLite',
                    'file': 'nugkui.db'},
         'btuu': {'default': True,
                  'pictures': 'btuu',
                  'type': 'SQLite',
                  'file': 'btuu.db'}}
     presenter = ConnMgrPresenter(view)
     presenter.view.reply_yes_no_dialog.append(True)
     presenter.on_remove_button_clicked('button')
     ## visibility same
     self.assertTrue(presenter.view.widget_get_visible(
         'expander'))
     self.assertFalse(presenter.view.widget_get_visible(
         'noconnectionlabel'))
     self.assertTrue('combobox_set_active' in view.invoked)
示例#33
0
 def test_check_parameters_valid(self):
     import copy
     view = MockView(combos={'name_combo': [], 'type_combo': []})
     prefs.prefs[bauble.conn_default_pref] = 'quisquis'
     prefs.prefs[bauble.conn_list_pref] = {
         'quisquis': {
             'type': 'PostgreSQL',
             'passwd': False,
             'pictures': '/tmp/',
             'db': 'quisquis',
             'host': 'localhost',
             'user': '******'
         }
     }
     presenter = ConnMgrPresenter(view)
     params = presenter.connections['quisquis']
     valid, message = presenter.check_parameters_valid(params)
     self.assertTrue(valid)
     params = copy.copy(presenter.connections['quisquis'])
     params['user'] = ''
     valid, message = presenter.check_parameters_valid(params)
     self.assertFalse(valid)
     params = copy.copy(presenter.connections['quisquis'])
     params['host'] = ''
     valid, message = presenter.check_parameters_valid(params)
     self.assertFalse(valid)
     sqlite_params = {
         'type': 'SQLite',
         'default': False,
         'file': '/tmp/test.db',
         'pictures': '/tmp/'
     }
     params = copy.copy(sqlite_params)
     valid, message = presenter.check_parameters_valid(params)
     self.assertTrue(valid)
     params = copy.copy(sqlite_params)
     params['file'] = '/usr/bin/sh'
     valid, message = presenter.check_parameters_valid(params)
     self.assertFalse(valid)
 def test_connection_uri_property(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_default_pref] = 'quisquis'
     prefs.prefs[bauble.conn_list_pref] = {
         'quisquis': {'type': 'PostgreSQL',
                      'passwd': False,
                      'pictures': '/tmp/',
                      'db': 'quisquis',
                      'host': 'localhost',
                      'user': '******'}}
     presenter = ConnMgrPresenter(view)
     self.assertEquals(presenter.connection_name, 'quisquis')
     self.assertEquals(presenter.dbtype, 'PostgreSQL')
     ## we need trigger all signals that would go by gtk
     p = presenter.connections[presenter.connection_name]
     presenter.view.widget_set_value('database_entry', p['db'])
     presenter.on_text_entry_changed('database_entry')
     presenter.view.widget_set_value('user_entry', p['user'])
     presenter.on_text_entry_changed('user_entry')
     presenter.view.widget_set_value('host_entry', p['host'])
     presenter.on_text_entry_changed('host_entry')
     self.assertEquals(presenter.connection_uri,
                       'postgresql://pg@localhost/quisquis')
 def test_on_dialog_response_cancel_params_changed(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': False,
                    'pictures': '/tmp/nugkui',
                    'type': 'SQLite',
                    'file': '/tmp/nugkui.db'}}
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     ## change something
     view.widget_set_value('usedefaults_chkbx', True)
     presenter.on_usedefaults_chkbx_toggled('usedefaults_chkbx')
     ## press escape
     dialog = MockDialog()
     view.reply_yes_no_dialog = [True]
     view.invoked = []
     presenter.on_dialog_response(dialog, RESPONSE_CANCEL)
     ## question was asked whether to save
     self.assertFalse('run_message_dialog' in view.invoked)
     self.assertTrue('run_yes_no_dialog' in view.invoked)
     self.assertTrue(dialog.hidden)
 def test_on_dialog_response_cancel_params_changed(self):
     view = MockView(combos={"name_combo": [], "type_combo": []})
     prefs.prefs[bauble.conn_list_pref] = {
         "nugkui": {"default": False, "pictures": "/tmp/nugkui", "type": "SQLite", "file": "/tmp/nugkui.db"}
     }
     prefs.prefs[bauble.conn_default_pref] = "nugkui"
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     ## change something
     view.widget_set_value("usedefaults_chkbx", True)
     presenter.on_usedefaults_chkbx_toggled("usedefaults_chkbx")
     ## press escape
     dialog = MockDialog()
     view.reply_yes_no_dialog = [True]
     view.invoked = []
     presenter.on_dialog_response(dialog, RESPONSE_CANCEL)
     ## question was asked whether to save
     self.assertFalse("run_message_dialog" in view.invoked)
     self.assertTrue("run_yes_no_dialog" in view.invoked)
     self.assertTrue(dialog.hidden)
示例#37
0
 def test_on_dialog_response_cancel_params_changed(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     prefs.prefs[bauble.conn_list_pref] = {
         'nugkui': {'default': False,
                    'pictures': '/tmp/nugkui',
                    'type': 'SQLite',
                    'file': '/tmp/nugkui.db'}}
     prefs.prefs[bauble.conn_default_pref] = 'nugkui'
     view.reply_file_chooser_dialog = []
     presenter = ConnMgrPresenter(view)
     ## change something
     view.widget_set_value('usedefaults_chkbx', True)
     presenter.on_usedefaults_chkbx_toggled('usedefaults_chkbx')
     ## press escape
     dialog = MockDialog()
     view.reply_yes_no_dialog = [True]
     view.invoked = []
     presenter.on_dialog_response(dialog, RESPONSE_CANCEL)
     ## question was asked whether to save
     self.assertFalse('run_message_dialog' in view.invoked)
     self.assertTrue('run_yes_no_dialog' in view.invoked)
     self.assertTrue(dialog.hidden)
 def test_can_create_presenter(self):
     view = MockView(combos={'name_combo': [],
                             'type_combo': []})
     presenter = ConnMgrPresenter(view)
     self.assertEquals(presenter.view, view)
 def test_create_presenter(self):
     view = MockView()
     m = StoredQueriesModel()
     presenter = StoredQueriesPresenter(m, view)
     self.assertEquals(presenter.view, view)
     self.assertEquals(id(presenter.model), id(m))
示例#40
0
 def test_parameters_to_uri_sqlite(self):
     view = MockView(combos={'name_combo': [], 'type_combo': []})
     prefs.prefs[bauble.conn_default_pref] = None
     prefs.prefs[bauble.conn_list_pref] = {}
     presenter = ConnMgrPresenter(view)
     params = {
         'type': 'SQLite',
         'default': False,
         'file': '/tmp/test.db',
         'pictures': '/tmp/'
     }
     self.assertEquals(presenter.parameters_to_uri(params),
                       'sqlite:////tmp/test.db')
     params = {
         'type': 'PostgreSQL',
         'passwd': False,
         'pictures': '/tmp/',
         'db': 'quisquis',
         'host': 'localhost',
         'user': '******'
     }
     self.assertEquals(presenter.parameters_to_uri(params),
                       'postgresql://pg@localhost/quisquis')
     params = {
         'type': 'PostgreSQL',
         'passwd': True,
         'pictures': '/tmp/',
         'db': 'quisquis',
         'host': 'localhost',
         'user': '******'
     }
     view.reply_entry_dialog.append('secret')
     self.assertEquals(presenter.parameters_to_uri(params),
                       'postgresql://*****:*****@localhost/quisquis')
     params = {
         'type': 'PostgreSQL',
         'passwd': False,
         'pictures': '/tmp/',
         'port': '9876',
         'db': 'quisquis',
         'host': 'localhost',
         'user': '******'
     }
     self.assertEquals(presenter.parameters_to_uri(params),
                       'postgresql://pg@localhost:9876/quisquis')
     params = {
         'type': 'PostgreSQL',
         'passwd': True,
         'pictures': '/tmp/',
         'port': '9876',
         'db': 'quisquis',
         'host': 'localhost',
         'user': '******'
     }
     view.reply_entry_dialog.append('secret')
     self.assertEquals(presenter.parameters_to_uri(params),
                       'postgresql://*****:*****@localhost:9876/quisquis')
     params = {
         'type': 'PostgreSQL',
         'passwd': False,
         'pictures': '/tmp/',
         'options': ['is_this_possible=no', 'why_do_we_test=because'],
         'db': 'quisquis',
         'host': 'localhost',
         'user': '******'
     }
     self.assertEquals(
         presenter.parameters_to_uri(params),
         'postgresql://pg@localhost/quisquis?'
         'is_this_possible=no&why_do_we_test=because')