From 7627464e582df2ab7824418df245e37012043152 Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Tue, 18 Mar 2014 19:57:01 +0200 Subject: [PATCH] 7212: vcard: only convert non-empty BDAY to text Discovered in #7530. 1) Previously, tests expected invalid BDAY with DD-MM-YYYY format to be ignored. Now they are wrapped with datestr (see #7212), and that is already covered by test_birthday_invalid_format_converted_to_datestr Corrected test expectations by removing the obsolete test. 2) Test expects that an empty BDAY record won't create any event objects. Modified import code accordingly -- we used to create an event object without date, regression in #7212. --- gramps/plugins/importer/importvcard.py | 17 +++++++++-------- .../plugins/importer/test/importvcard_test.py | 4 ---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gramps/plugins/importer/importvcard.py b/gramps/plugins/importer/importvcard.py index 9c0104fdb..20d216279 100644 --- a/gramps/plugins/importer/importvcard.py +++ b/gramps/plugins/importer/importvcard.py @@ -20,8 +20,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id$ - "Import from vCard (RFC 2426)" #------------------------------------------------------------------------- @@ -484,12 +482,15 @@ class VCardParser(object): ).format(date=e.date.to_struct(), vcard_snippet=data)) date.set(modifier=Date.MOD_TEXTONLY, text=data) else: - # TRANSLATORS: leave the {vcard_snippet} untranslated. - LOG.warning(_( - "Date {vcard_snippet} not in appropriate format yyyy-mm-dd, " - "preserving date as text." - ).format(vcard_snippet=date_str)) - date.set(modifier=Date.MOD_TEXTONLY, text=date_str) + if date_str: + # TRANSLATORS: leave the {vcard_snippet} untranslated. + LOG.warning(_( + "Date {vcard_snippet} not in appropriate format yyyy-mm-dd, " + "preserving date as text." + ).format(vcard_snippet=date_str)) + date.set(modifier=Date.MOD_TEXTONLY, text=date_str) + else: # silently ignore an empty BDAY record + return event = Event() event.set_type(EventType(EventType.BIRTH)) event.set_date_object(date) diff --git a/gramps/plugins/importer/test/importvcard_test.py b/gramps/plugins/importer/test/importvcard_test.py index 6db458c63..ee3e5139d 100644 --- a/gramps/plugins/importer/test/importvcard_test.py +++ b/gramps/plugins/importer/test/importvcard_test.py @@ -486,10 +486,6 @@ class VCardCheck(unittest.TestCase): ET.SubElement(event, 'dateval', {'val': '2001-09-28'}) self.do_test("\r\n".join(self.vcard), self.gramps) - def test_add_birthday_ddmmyyyy(self): - self.vcard.insert(4, "BDAY:28-09-2001") - self.do_test("\r\n".join(self.vcard), self.gramps) - def test_add_birthday_empty(self): self.vcard.insert(4, "BDAY: ") self.do_test("\r\n".join(self.vcard), self.gramps)