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.
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user