def testCreateUpdateDeleteContactAndUpdatePhoto(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testCreateUpdateDeleteContactAndUpdatePhoto') DeleteTestContact(self.gd_client) # Create a new entry new_entry = gdata.contacts.ContactEntry() new_entry.title = atom.Title(text='Elizabeth Bennet') new_entry.content = atom.Content(text='Test Notes') new_entry.email.append(gdata.contacts.Email( rel='http://schemas.google.com/g/2005#work', primary='true', address='*****@*****.**')) new_entry.phone_number.append(gdata.contacts.PhoneNumber( rel='http://schemas.google.com/g/2005#work', text='(206)555-1212')) new_entry.organization = gdata.contacts.Organization( org_name=gdata.contacts.OrgName(text='TestCo.'), rel='http://schemas.google.com/g/2005#work') entry = self.gd_client.CreateContact(new_entry) # Generate and parse the XML for the new entry. self.assertEquals(entry.title.text, new_entry.title.text) self.assertEquals(entry.content.text, 'Test Notes') self.assertEquals(len(entry.email), 1) self.assertEquals(entry.email[0].rel, new_entry.email[0].rel) self.assertEquals(entry.email[0].address, '*****@*****.**') self.assertEquals(len(entry.phone_number), 1) self.assertEquals(entry.phone_number[0].rel, new_entry.phone_number[0].rel) self.assertEquals(entry.phone_number[0].text, '(206)555-1212') self.assertEquals(entry.organization.org_name.text, 'TestCo.') # Edit the entry. entry.phone_number[0].text = '(555)555-1212' updated = self.gd_client.UpdateContact(entry.GetEditLink().href, entry) self.assertEquals(updated.content.text, 'Test Notes') self.assertEquals(len(updated.phone_number), 1) self.assertEquals(updated.phone_number[0].rel, entry.phone_number[0].rel) self.assertEquals(updated.phone_number[0].text, '(555)555-1212') # Change the contact's photo. updated_photo = self.gd_client.ChangePhoto( conf.settings.ContactsConfig.get_image_location(), updated, content_type='image/jpeg') # Refetch the contact so that it has the new photo link updated = self.gd_client.GetContact(updated.GetSelfLink().href) self.assert_(updated.GetPhotoLink() is not None) # Fetch the photo data. hosted_image = self.gd_client.GetPhoto(updated) self.assert_(hosted_image is not None) # Delete the entry. self.gd_client.DeleteContact(updated.GetEditLink().href)
def testCreateUpdateDeleteContactAndUpdatePhoto(self): if not conf.options.get_value('runlive') == 'true': return conf.configure_service_cache(self.gd_client, 'testCreateUpdateDeleteContactAndUpdatePhoto') DeleteTestContact(self.gd_client) # Create a new entry new_entry = gdata.contacts.ContactEntry() new_entry.title = atom.Title(text='Elizabeth Bennet') new_entry.content = atom.Content(text='Test Notes') new_entry.email.append(gdata.contacts.Email( rel='http://schemas.google.com/g/2005#work', primary='true', address='*****@*****.**')) new_entry.phone_number.append(gdata.contacts.PhoneNumber( rel='http://schemas.google.com/g/2005#work', text='(206)555-1212')) new_entry.organization = gdata.contacts.Organization( org_name=gdata.contacts.OrgName(text='TestCo.'), rel='http://schemas.google.com/g/2005#work') entry = self.gd_client.CreateContact(new_entry) # Generate and parse the XML for the new entry. self.assertEqual(entry.title.text, new_entry.title.text) self.assertEqual(entry.content.text, 'Test Notes') self.assertEqual(len(entry.email), 1) self.assertEqual(entry.email[0].rel, new_entry.email[0].rel) self.assertEqual(entry.email[0].address, '*****@*****.**') self.assertEqual(len(entry.phone_number), 1) self.assertEqual(entry.phone_number[0].rel, new_entry.phone_number[0].rel) self.assertEqual(entry.phone_number[0].text, '(206)555-1212') self.assertEqual(entry.organization.org_name.text, 'TestCo.') # Edit the entry. entry.phone_number[0].text = '(555)555-1212' updated = self.gd_client.UpdateContact(entry.GetEditLink().href, entry) self.assertEqual(updated.content.text, 'Test Notes') self.assertEqual(len(updated.phone_number), 1) self.assertEqual(updated.phone_number[0].rel, entry.phone_number[0].rel) self.assertEqual(updated.phone_number[0].text, '(555)555-1212') # Change the contact's photo. updated_photo = self.gd_client.ChangePhoto( conf.options.get_value('imgpath'), updated, content_type='image/jpeg') # Refetch the contact so that it has the new photo link updated = self.gd_client.GetContact(updated.GetSelfLink().href) self.assertTrue(updated.GetPhotoLink() is not None) # Fetch the photo data. hosted_image = self.gd_client.GetPhoto(updated) self.assertTrue(hosted_image is not None) # Delete the entry. self.gd_client.DeleteContact(updated.GetEditLink().href)
def testCustomContactList(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testCustomContactList') self.gd_client.contact_list = conf.settings.ContactsConfig.email() feed = self.gd_client.GetContactsFeed() self.assert_(isinstance(feed, gdata.contacts.ContactsFeed))
def testCustomContactList(self): if not conf.options.get_value('runlive') == 'true': return conf.configure_service_cache(self.gd_client, 'testCustomContactList') self.gd_client.contact_list = conf.options.get_value('username') feed = self.gd_client.GetContactsFeed() self.assertTrue(isinstance(feed, gdata.contacts.ContactsFeed))
def testCustomContactList(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testCustomContactList') self.gd_client.contact_list = conf.settings.ContactsConfig.email() feed = self.gd_client.GetContactsFeed() self.assert_(isinstance(feed, gdata.contacts.ContactsFeed))
def testCreateAndDeleteContactUsingBatch(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testCreateAndDeleteContactUsingBatch') # Get random data for creating contact random_contact_number = 'notRandom5' random_contact_title = 'Random Contact %s' % ( random_contact_number) # Set contact data contact = gdata.contacts.ContactEntry() contact.title = atom.Title(text=random_contact_title) contact.email = gdata.contacts.Email( address='*****@*****.**' % random_contact_number, primary='true', rel=gdata.contacts.REL_WORK) contact.content = atom.Content(text='Contact created by ' 'gdata-python-client automated test ' 'suite.') # Form a batch request batch_request = gdata.contacts.ContactsFeed() batch_request.AddInsert(entry=contact) # Execute the batch request to insert the contact. default_batch_url = gdata.contacts.service.DEFAULT_BATCH_URL batch_result = self.gd_client.ExecuteBatch(batch_request, default_batch_url) self.assertEquals(len(batch_result.entry), 1) self.assertEquals(batch_result.entry[0].title.text, random_contact_title) self.assertEquals(batch_result.entry[0].batch_operation.type, gdata.BATCH_INSERT) self.assertEquals(batch_result.entry[0].batch_status.code, '201') expected_batch_url = re.compile('default').sub( urllib.quote(self.gd_client.email), gdata.contacts.service.DEFAULT_BATCH_URL) self.failUnless(batch_result.GetBatchLink().href, expected_batch_url) # Create a batch request to delete the newly created entry. batch_delete_request = gdata.contacts.ContactsFeed() batch_delete_request.AddDelete(entry=batch_result.entry[0]) batch_delete_result = self.gd_client.ExecuteBatch( batch_delete_request, batch_result.GetBatchLink().href) self.assertEquals(len(batch_delete_result.entry), 1) self.assertEquals(batch_delete_result.entry[0].batch_operation.type, gdata.BATCH_DELETE) self.assertEquals(batch_result.entry[0].batch_status.code, '201')
def testCreateAndDeleteContactUsingBatch(self): if not conf.options.get_value('runlive') == 'true': return conf.configure_service_cache(self.gd_client, 'testCreateAndDeleteContactUsingBatch') # Get random data for creating contact random_contact_number = 'notRandom12' random_contact_title = 'Random Contact %s' % ( random_contact_number) # Set contact data contact = gdata.contacts.ContactEntry() contact.title = atom.Title(text=random_contact_title) contact.email = gdata.contacts.Email( address='*****@*****.**' % random_contact_number, primary='true', rel=gdata.contacts.REL_WORK) contact.content = atom.Content(text='Contact created by ' 'gdata-python-client automated test ' 'suite.') # Form a batch request batch_request = gdata.contacts.ContactsFeed() batch_request.AddInsert(entry=contact) # Execute the batch request to insert the contact. default_batch_url = gdata.contacts.service.DEFAULT_BATCH_URL batch_result = self.gd_client.ExecuteBatch(batch_request, default_batch_url) self.assertEqual(len(batch_result.entry), 1) self.assertEqual(batch_result.entry[0].title.text, random_contact_title) self.assertEqual(batch_result.entry[0].batch_operation.type, gdata.BATCH_INSERT) self.assertEqual(batch_result.entry[0].batch_status.code, '201') expected_batch_url = re.compile('default').sub( urllib.parse.quote(self.gd_client.email), gdata.contacts.service.DEFAULT_BATCH_URL) self.assertTrue(batch_result.GetBatchLink().href, expected_batch_url) # Create a batch request to delete the newly created entry. batch_delete_request = gdata.contacts.ContactsFeed() batch_delete_request.AddDelete(entry=batch_result.entry[0]) batch_delete_result = self.gd_client.ExecuteBatch( batch_delete_request, batch_result.GetBatchLink().href) self.assertEqual(len(batch_delete_result.entry), 1) self.assertEqual(batch_delete_result.entry[0].batch_operation.type, gdata.BATCH_DELETE) self.assertEqual(batch_result.entry[0].batch_status.code, '201')
def testCreateUpdateDeleteGroup(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testCreateUpdateDeleteGroup') test_group = gdata.contacts.GroupEntry(title=atom.Title( text='test group py')) new_group = self.gd_client.CreateGroup(test_group) self.assert_(isinstance(new_group, gdata.contacts.GroupEntry)) self.assertEquals(new_group.title.text, 'test group py') # Change the group's title new_group.title.text = 'new group name py' updated_group = self.gd_client.UpdateGroup(new_group.GetEditLink().href, new_group) self.assertEquals(updated_group.title.text, new_group.title.text) # Remove the group self.gd_client.DeleteGroup(updated_group.GetEditLink().href)
def testCreateUpdateDeleteGroup(self): if not conf.options.get_value('runlive') == 'true': return conf.configure_service_cache(self.gd_client, 'testCreateUpdateDeleteGroup') test_group = gdata.contacts.GroupEntry(title=atom.Title( text='test group py')) new_group = self.gd_client.CreateGroup(test_group) self.assertTrue(isinstance(new_group, gdata.contacts.GroupEntry)) self.assertEqual(new_group.title.text, 'test group py') # Change the group's title new_group.title.text = 'new group name py' updated_group = self.gd_client.UpdateGroup(new_group.GetEditLink().href, new_group) self.assertEqual(updated_group.title.text, new_group.title.text) # Remove the group self.gd_client.DeleteGroup(updated_group.GetEditLink().href)
def testCreateUpdateDeleteGroup(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testCreateUpdateDeleteGroup') test_group = gdata.contacts.GroupEntry(title=atom.Title( text='test group py')) new_group = self.gd_client.CreateGroup(test_group) self.assert_(isinstance(new_group, gdata.contacts.GroupEntry)) self.assertEquals(new_group.title.text, 'test group py') # Change the group's title new_group.title.text = 'new group name py' updated_group = self.gd_client.UpdateGroup( new_group.GetEditLink().href, new_group) self.assertEquals(updated_group.title.text, new_group.title.text) # Remove the group self.gd_client.DeleteGroup(updated_group.GetEditLink().href)
def testGetContactsFeed(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testGetContactsFeed') feed = self.gd_client.GetContactsFeed() self.assert_(isinstance(feed, gdata.contacts.ContactsFeed))
def testGetContactsFeed(self): if not conf.options.get_value('runlive') == 'true': return conf.configure_service_cache(self.gd_client, 'testGetContactsFeed') feed = self.gd_client.GetContactsFeed() self.assert_(isinstance(feed, gdata.contacts.ContactsFeed))
def testGetContactsFeed(self): if not conf.settings.RUN_LIVE_TESTS: return conf.configure_service_cache(self.gd_client, 'testGetContactsFeed') feed = self.gd_client.GetContactsFeed() self.assert_(isinstance(feed, gdata.contacts.ContactsFeed))
def testGetContactsFeed(self): if not conf.options.get_value('runlive') == 'true': return conf.configure_service_cache(self.gd_client, 'testGetContactsFeed') feed = self.gd_client.GetContactsFeed() self.assert_(isinstance(feed, gdata.contacts.ContactsFeed))