|
From: Stas Z. <sta...@us...> - 2005-06-15 14:48:48
|
Update of /cvsroot/gmailagent/GA-libgmail2/frontend In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12120 Modified Files: Contrgcm.py GuiQTgcm.py MainWinContacts.ui MainWinContacts_forms.py Added Files: testContrgcm.py Log Message: More work on the contacts stuff Added a unittest Index: GuiQTgcm.py =================================================================== RCS file: /cvsroot/gmailagent/GA-libgmail2/frontend/GuiQTgcm.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GuiQTgcm.py 15 Jun 2005 11:14:01 -0000 1.3 --- GuiQTgcm.py 15 Jun 2005 14:48:39 -0000 1.4 *************** *** 26,30 **** from MainWinContacts_forms import FormMainWin from Observers import Observer,Observable ! from QLogin import Login import Contrgcm --- 26,30 ---- from MainWinContacts_forms import FormMainWin from Observers import Observer,Observable ! from QgcmDialogs import Login import Contrgcm *************** *** 37,40 **** --- 37,41 ---- self.ga = None self.show() + # test stuff self.Myobs = Observer(self.test) self.addObserver(self.Myobs) *************** *** 44,47 **** --- 45,56 ---- print "args",args + def closeEvent(self,ev): + """Called by QT when the user closes the window""" + ans = QMessageBox.information(self, + "Question", "Do you really want to quit?", + QMessageBox.Cancel,QMessageBox.Ok) + if ans == 1: + ev.accept() + def editNewcontact_activated(self): print "FormMainWin.editNewcontact_activated(): Not implemented yet" *************** *** 62,66 **** def pushButtonClose_clicked(self): ! print "FormMainWin.pushButtonClose_clicked(): Not implemented yet" def pushButtonCloseSave_clicked(self): --- 71,75 ---- def pushButtonClose_clicked(self): ! self.contactsExit_activated() def pushButtonCloseSave_clicked(self): *************** *** 92,98 **** self.Myobs = Observer(self._import_contacts_observerCB) # See _import_contacts_observerCB for an explanation why we use this ! Login(self.Myobs,self.Qapplication,self) else: contacts = Contrgcm.import_contacts_gmail(self.ga) def contactsSave_activated(self): --- 101,109 ---- self.Myobs = Observer(self._import_contacts_observerCB) # See _import_contacts_observerCB for an explanation why we use this ! Login(self.Qapplication,self.Myobs,parent=self) else: contacts = Contrgcm.import_contacts_gmail(self.ga) + self._load(contacts) + return 1 def contactsSave_activated(self): *************** *** 106,110 **** def contactsExit_activated(self): ! print "FormMainWin.contactsExit_activated(): Not implemented yet" ####### Internal used methods ################ --- 117,121 ---- def contactsExit_activated(self): ! self.close(1) ####### Internal used methods ################ *************** *** 114,124 **** This is used when there's no libgmail login object. The problem is that we first must get a valid Gmail login but ! that the Login dialog isn't blocking the program execution.""" ! print "_import_contacts_observerCB",caller,data self.ga = data[0] - print self.ga contacts = Contrgcm.import_contacts_gmail(self.ga) ! def _load( self, conlist): """Loads a contacts list into the widget.""" self.listViewContacts.clear() --- 125,135 ---- This is used when there's no libgmail login object. The problem is that we first must get a valid Gmail login but ! that the Login dialog isn't blocking the program execution. ! A QT Dialog can be made to block but it can return a useable value.""" self.ga = data[0] contacts = Contrgcm.import_contacts_gmail(self.ga) + self._load(contacts) ! def _load(self,conlist): """Loads a contacts list into the widget.""" self.listViewContacts.clear() *************** *** 134,141 **** except Exception,info: if GQ_DEBUG: ! logging.warning("Reading addressbook failed, %s" % str(info)) ! print info return - self.parent._load(addrfile)# fill the parents view try: self.progress_dlg.update() --- 145,150 ---- except Exception,info: if GQ_DEBUG: ! logging.warning("Setting contacts failed, %s" % str(info)) return try: self.progress_dlg.update() Index: MainWinContacts.ui =================================================================== RCS file: /cvsroot/gmailagent/GA-libgmail2/frontend/MainWinContacts.ui,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MainWinContacts.ui 12 Jun 2005 06:17:01 -0000 1.1 --- MainWinContacts.ui 15 Jun 2005 14:48:39 -0000 1.2 *************** *** 16,19 **** --- 16,60 ---- <string>GCM - Gmail Contacts Manager</string> </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButtonClose</cstring> + </property> + <property name="geometry"> + <rect> + <x>410</x> + <y>330</y> + <width>120</width> + <height>26</height> + </rect> + </property> + <property name="text"> + <string>Close</string> + </property> + <property name="toolTip" stdset="0"> + <string>Close without saving</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButtonCloseSave</cstring> + </property> + <property name="geometry"> + <rect> + <x>40</x> + <y>330</y> + <width>120</width> + <height>26</height> + </rect> + </property> + <property name="text"> + <string>Close and Save</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Close and save your contacts</string> + </property> + </widget> <widget class="QListView"> <column> *************** *** 50,64 **** </property> </column> - <column> - <property name="text"> - <string>Gmail ID</string> - </property> - <property name="clickable"> - <bool>false</bool> - </property> - <property name="resizable"> - <bool>true</bool> - </property> - </column> <item> <property name="text"> --- 91,94 ---- *************** *** 71,80 **** <string></string> </property> - <property name="text"> - <string></string> - </property> - <property name="pixmap"> - <pixmap></pixmap> - </property> <property name="pixmap"> <pixmap></pixmap> --- 101,104 ---- *************** *** 114,158 **** </property> </widget> - <widget class="QPushButton"> - <property name="name"> - <cstring>pushButtonClose</cstring> - </property> - <property name="geometry"> - <rect> - <x>410</x> - <y>330</y> - <width>120</width> - <height>26</height> - </rect> - </property> - <property name="text"> - <string>Close</string> - </property> - <property name="toolTip" stdset="0"> - <string>Close without saving</string> - </property> - </widget> - <widget class="QPushButton"> - <property name="name"> - <cstring>pushButtonCloseSave</cstring> - </property> - <property name="geometry"> - <rect> - <x>40</x> - <y>330</y> - <width>120</width> - <height>26</height> - </rect> - </property> - <property name="text"> - <string>Close and Save</string> - </property> - <property name="default"> - <bool>true</bool> - </property> - <property name="toolTip" stdset="0"> - <string>Close and save your contacts</string> - </property> - </widget> </widget> <menubar> --- 138,141 ---- --- NEW FILE: testContrgcm.py --- # -*- coding: latin-1 -*- # Copyright (c) 2005 Stas Zykiewicz <st...@li...> # # testContrgcm.py # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import unittest,os import getpass import libgmail2 import Contrgcm class TestsContrgcmDB(unittest.TestCase): """ Set of tests that exercise the database portion of Contrgcm.py. """ def test1_cleanup_and_setup(self): """Delete all entries in the addressbook and add 5 new contacts. """ contacts = account.getContacts().getAllContacts() for contact in contacts: account.removeContact(contact) # add 5 contacts con1 = ('1','1@1','text1') con2 = ('2','2@2','text2') con3 = ('3','3@3','text3') con4 = ('4','4@4','text4') con5 = ('5','5@5','text5') conlist_org = [con1,con2,con3,con4,con5] for item in conlist_org: account.addContact(item[0],item[1],item[2]) conlist_gmail = account.getContacts().getAllContacts() self.assertEqual(len(conlist_org),len(conlist_gmail),\ "Number of contacts differ") def test2_setup_DB(self): """Create a new database""" filename = '/tmp/testdatabase' if os.path.exists(filename): os.remove(filename) DB = Contrgcm.DBase(filename) Contrgcm._DBase = DB self.assertEqual(os.path.exists(filename),1,"Failed to create database") def test3_store_contacts_DB(self): """Check if the Gmail contacts and the entries in the database are equal""" con1 = ('1','1@1','text1') con2 = ('2','2@2','text2') con3 = ('3','3@3','text3') con4 = ('4','4@4','text4') con5 = ('5','5@5','text5') conlist_org = [con1,con2,con3,con4,con5] conlist_gmail = Contrgcm.import_contacts_gmail(account) conlist_db = Contrgcm._DBase._get_all_values() len_db = len(conlist_db) len_gm = len(conlist_gmail) self.assertEqual(len_db,len_gm,\ "Number of contacts differ, db:%s ,gm:%s" % (len_db,len_gm)) def test4_check_keys_ids(self): """Check if the gmail id's and db keys equal""" keylist_gm = [] keylist_db = Contrgcm._DBase._get_all_keys() for item in account.getContacts().getAllContacts(): self.assertEqual(1, item.getId() in keylist_db,"Database keys and Gmail ids differ") def test5_compare_every_DBvalue(self): """Compare db entries and gmail contacts""" for item in account.getContacts().getAllContacts(): id = item.getId() db_con = Contrgcm._DBase._get_value(id) gm_con = (item.getName(),item.getEmail(),item.getNotes()) self.assertEqual(True,(db_con[0] == gm_con[0] and\ db_con[1] == gm_con[1] and\ db_con[2] == gm_con[2]) ,\ "DBase and contacts differ %s\n%s" % (db_con,gm_con)) if __name__ == '__main__': print "\n==============================================" print "Start 'Contrgcm database' testsuite" print "------------------------------------------------\n" print "WARNING: THIS WILL DELETE/REARRANGE" print " YOUR ADDRESSBOOK/EMAILS" print " BE SURE TO RUN THIS TEST ONLY ON A 'test' ACCOUNT" name = raw_input("Gmail account name:") pw = getpass.getpass("Password: ") account = libgmail2.GmailAccount(name, pw) try: account.login() print "Login successful.\n" except libgmail2.GmailLoginFailure,e: print "\nLogin failed. (%s)" % e.message else: suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestsContrgcmDB)) unittest.TextTestRunner(verbosity=2).run(suite) Index: Contrgcm.py =================================================================== RCS file: /cvsroot/gmailagent/GA-libgmail2/frontend/Contrgcm.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Contrgcm.py 15 Jun 2005 11:14:01 -0000 1.3 --- Contrgcm.py 15 Jun 2005 14:48:39 -0000 1.4 *************** *** 19,23 **** # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! CG_DEBUG = 1 import libgmail2,logging,os,shelve,urllib2,ConfigParser --- 19,23 ---- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! CG_DEBUG = 0 import libgmail2,logging,os,shelve,urllib2,ConfigParser *************** *** 97,101 **** if not contacts: return None ! def import_contacts_db(): """import_contacts_db --> contacts in a list of tuples or None. --- 97,108 ---- if not contacts: return None ! conlist = [] ! for obj in contacts: ! conitem = (obj.getName(),obj.getEmail(),obj.getNotes(),obj.getId()) ! conlist.append(conitem) ! _DBase._store_value(conitem[3],conitem) ! if CG_DEBUG: logging.debug("Database values %s" % _DBase._get_all_values()) ! return conlist ! def import_contacts_db(): """import_contacts_db --> contacts in a list of tuples or None. *************** *** 147,165 **** class DBase: ! def __init__(self): ! self.db_name = '.gcm_dbase' self.DB_dict = shelve.open(self.db_name) def _get_all_values(self): ! pass def _get_all_keys(self): ! pass ! def _store_value(self,key,*args): ! pass def _get_value(self,key): ! pass def _close(self): ! pass ! ! ###### Old stuff, perhaps we can use parts of it ########### def upload_local_contacts(addrfile,ga): --- 154,178 ---- class DBase: ! def __init__(self,name=''): ! """@name is only meant for the unittest suite""" ! if not name: ! self.db_name = os.path.expanduser('~/.gcm_database') ! else: ! self.db_name = name self.DB_dict = shelve.open(self.db_name) def _get_all_values(self): ! return self.DB_dict.values() def _get_all_keys(self): ! return self.DB_dict.keys() ! def _store_value(self,key,value): ! self.DB_dict[key] = value def _get_value(self,key): ! return self.DB_dict[key] def _close(self): ! self.DB_dict.close() ! ! _DBase = DBase() ! if CG_DEBUG: logging.debug("Shelve DB created %s" % _DBase) ! ###### Old stuff, perhaps we can use parts of it ########### def upload_local_contacts(addrfile,ga): Index: MainWinContacts_forms.py =================================================================== RCS file: /cvsroot/gmailagent/GA-libgmail2/frontend/MainWinContacts_forms.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MainWinContacts_forms.py 15 Jun 2005 11:14:01 -0000 1.2 --- MainWinContacts_forms.py 15 Jun 2005 14:48:39 -0000 1.3 *************** *** 3,7 **** # Form implementation generated from reading ui file 'MainWinContacts.ui' # ! # Created: Wed Jun 15 10:23:18 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # --- 3,7 ---- # Form implementation generated from reading ui file 'MainWinContacts.ui' # ! # Created: Wed Jun 15 14:36:48 2005 # by: The PyQt User Interface Compiler (pyuic) 3.14.1 # *************** *** 1288,1297 **** self.setCentralWidget(QWidget(self,"qt_central_widget")) self.listViewContacts = QListView(self.centralWidget(),"listViewContacts") self.listViewContacts.addColumn(self.__tr("Name")) self.listViewContacts.addColumn(self.__tr("Email address")) self.listViewContacts.addColumn(self.__tr("Notes")) - self.listViewContacts.addColumn(self.__tr("Gmail ID")) - self.listViewContacts.header().setClickEnabled(0,self.listViewContacts.header().count() - 1) self.listViewContacts.setGeometry(QRect(10,10,560,310)) self.listViewContacts.setFrameShape(QListView.StyledPanel) --- 1288,1302 ---- self.setCentralWidget(QWidget(self,"qt_central_widget")) + self.pushButtonClose = QPushButton(self.centralWidget(),"pushButtonClose") + self.pushButtonClose.setGeometry(QRect(410,330,120,26)) + + self.pushButtonCloseSave = QPushButton(self.centralWidget(),"pushButtonCloseSave") + self.pushButtonCloseSave.setGeometry(QRect(40,330,120,26)) + self.pushButtonCloseSave.setDefault(1) + self.listViewContacts = QListView(self.centralWidget(),"listViewContacts") self.listViewContacts.addColumn(self.__tr("Name")) self.listViewContacts.addColumn(self.__tr("Email address")) self.listViewContacts.addColumn(self.__tr("Notes")) self.listViewContacts.setGeometry(QRect(10,10,560,310)) self.listViewContacts.setFrameShape(QListView.StyledPanel) *************** *** 1301,1311 **** self.listViewContacts.setShowSortIndicator(1) - self.pushButtonClose = QPushButton(self.centralWidget(),"pushButtonClose") - self.pushButtonClose.setGeometry(QRect(410,330,120,26)) - - self.pushButtonCloseSave = QPushButton(self.centralWidget(),"pushButtonCloseSave") - self.pushButtonCloseSave.setGeometry(QRect(40,330,120,26)) - self.pushButtonCloseSave.setDefault(1) - self.fileNewAction = QAction(self,"fileNewAction") self.fileNewAction.setIconSet(QIconSet(self.image0)) --- 1306,1309 ---- *************** *** 1430,1444 **** def languageChange(self): self.setCaption(self.__tr("GCM - Gmail Contacts Manager")) self.listViewContacts.header().setLabel(0,self.__tr("Name")) self.listViewContacts.header().setLabel(1,self.__tr("Email address")) self.listViewContacts.header().setLabel(2,self.__tr("Notes")) - self.listViewContacts.header().setLabel(3,self.__tr("Gmail ID")) self.listViewContacts.clear() item = QListViewItem(self.listViewContacts,None) - self.pushButtonClose.setText(self.__tr("Close")) - QToolTip.add(self.pushButtonClose,self.__tr("Close without saving")) - self.pushButtonCloseSave.setText(self.__tr("Close and Save")) - QToolTip.add(self.pushButtonCloseSave,self.__tr("Close and save your contacts")) self.fileNewAction.setText(self.__tr("New")) self.fileNewAction.setMenuText(self.__tr("&New")) --- 1428,1441 ---- def languageChange(self): self.setCaption(self.__tr("GCM - Gmail Contacts Manager")) + self.pushButtonClose.setText(self.__tr("Close")) + QToolTip.add(self.pushButtonClose,self.__tr("Close without saving")) + self.pushButtonCloseSave.setText(self.__tr("Close and Save")) + QToolTip.add(self.pushButtonCloseSave,self.__tr("Close and save your contacts")) self.listViewContacts.header().setLabel(0,self.__tr("Name")) self.listViewContacts.header().setLabel(1,self.__tr("Email address")) self.listViewContacts.header().setLabel(2,self.__tr("Notes")) self.listViewContacts.clear() item = QListViewItem(self.listViewContacts,None) self.fileNewAction.setText(self.__tr("New")) self.fileNewAction.setMenuText(self.__tr("&New")) |