diff --git a/Tests/Integration/carddav.py b/Tests/Integration/carddav.py index 68a859723..c9385cb17 100644 --- a/Tests/Integration/carddav.py +++ b/Tests/Integration/carddav.py @@ -70,7 +70,11 @@ class Carddav: if not self.cards: url = "/SOGo/so/%s/Contacts/personal/view" % (self.login) content = self._get(url) - self.cards = content['cards'] + #print "\nCONTENT:", content + if 'cards' in content: + self.cards = content['cards'] + else: + self.cards = [] return self.cards def get_cards(self, pattern): diff --git a/Tests/Integration/test-carddav.py b/Tests/Integration/test-carddav.py index 5748730ed..0d642d683 100755 --- a/Tests/Integration/test-carddav.py +++ b/Tests/Integration/test-carddav.py @@ -85,6 +85,13 @@ class JsonDavPhoneTests(unittest.TestCase): self.allphones = list(self.newphone) self.allphones.extend(self.newphones_difftype) self.allphones.extend(self.newphones_sametype) + #- In case there are no cards for this user + try: + self._get_card() + except IndexError: + path = 'Contacts/personal' + (card, path, gid) = self._create_new_card(path) + self._save_card(card) def tearDown(self): self._connect_as_user() @@ -102,6 +109,23 @@ class JsonDavPhoneTests(unittest.TestCase): def _connect_as_user(self, newuser=username, newpassword=password): self.dv = carddav.Carddav(newuser, newpassword) + def _create_new_card(self, path): + gid = self.dv.newguid(path) + card = {'c_categories': None, + 'c_cn': 'John Doe', + 'c_component': 'vcard', + 'c_givenname': 'John Doe', + 'c_mail': 'johndoe@nothere.com', + 'c_name': gid, + 'c_o': '', + 'c_screenname': '', + 'c_sn': '', + 'c_telephonenumber': '123.456.7890', + 'emails': [{'type': 'pref', 'value': 'johndoe@nothere.com'}], + 'phones': [{'type': 'home', 'value': '111.222.3333'}], + 'id': gid} + return (card, path, gid) + def _get_card(self, name="John Doe"): tmp_card = self.dv.get_cards(name)[0] self.card = self.dv.get_card(tmp_card['c_name'])