當前位置: 首頁>>代碼示例>>Python>>正文


Python DbClient._getProfileTable方法代碼示例

本文整理匯總了Python中dbclient.DbClient._getProfileTable方法的典型用法代碼示例。如果您正苦於以下問題:Python DbClient._getProfileTable方法的具體用法?Python DbClient._getProfileTable怎麽用?Python DbClient._getProfileTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dbclient.DbClient的用法示例。


在下文中一共展示了DbClient._getProfileTable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testSharedContacts

# 需要導入模塊: from dbclient import DbClient [as 別名]
# 或者: from dbclient.DbClient import _getProfileTable [as 別名]
	def testSharedContacts(self):
		# Delete whole profiles table
		DbClient._getProfileTable().remove({})
		self.assertEqual(DbClient._getProfileTable().count(), 0, "Profiles table should be empty")
		# Add own profile
		myTorId = "ABC123DEF456GH78"
		myprofile = {"name" : "Constantin Taylor", "keyid" : "someKeyId", "displayName" : "Me",
					"status" : "self", "ownprofile" : True}
		DbClient.updateContact(myTorId, myprofile)
		# Add friend who doesn't list any contacts
		person1TorId = "DEF123GHI456JK78"
		person1profile = {"name" : "Jeremy Flintstone", "keyid" : "someKeyId", "displayName" : "Uncle Jez",
					"status" : "trusted"}
		DbClient.updateContact(person1TorId, person1profile)
		(shared, possIdsForThem, possIdsForMe, _) = ContactMaker.getSharedAndPossibleContacts(person1TorId)
		self.assertFalse(shared, "person1 shouldn't have any shared contacts")
		self.assertFalse(possIdsForThem, "person1 shouldn't have any possible contacts")
		self.assertFalse(possIdsForMe, "I shouldn't have any possible contacts")
		# Add second friend who lists first one as contact
		person2TorId = "GHI123JKL456MN78"
		person2profile = {"name" : "Karen Millhouse", "keyid" : "someKeyId", "displayName" : "Mum",
					"status" : "trusted", "contactlist":"DEF123GHI456JK78Jeremy,ABC123DEF456GH78Constantin,"}
		DbClient.updateContact(person2TorId, person2profile)
		(shared, possIdsForThem, possIdsForMe, _) = ContactMaker.getSharedAndPossibleContacts(person1TorId)
		self.assertEqual(len(shared), 1, "person1 should have exactly one shared contact now")
		self.assertTrue(person2TorId in shared, "person1 should have p2 as shared contact now")
		self.assertFalse(possIdsForThem, "person1 shouldn't have any possible contacts")
		self.assertFalse(possIdsForMe, "I shouldn't have any possible contacts from p1")
		(shared, possIdsForThem, possIdsForMe, _) = ContactMaker.getSharedAndPossibleContacts(person2TorId)
		self.assertEqual(len(shared), 1, "person2 should have exactly one shared contact now")
		self.assertTrue(person1TorId in shared, "person2 should have p1 as shared contact now")
		self.assertFalse(possIdsForThem, "person2 shouldn't have any possible contacts")
		self.assertFalse(possIdsForMe, "I shouldn't have any possible contacts from p2")
		# Person 2 gets a new friend
		DbClient.updateContact(person2TorId, {"contactlist":"DEF123GHI456JK78Jeremy,ABC123DEF456GH78Constantin,MNO123PQR456ST78Scarlet Pimpernel"})
		(shared, possIdsForThem, possIdsForMe, _) = ContactMaker.getSharedAndPossibleContacts(person1TorId)
		self.assertEqual(len(shared), 1, "person1 should still have one shared contact")
		self.assertTrue(person2TorId in shared, "person1 should have p2 as shared contact")
		self.assertFalse(possIdsForThem, "person1 shouldn't have any possible contacts")
		(shared, possIdsForThem, possIdsForMe, _) = ContactMaker.getSharedAndPossibleContacts(person2TorId)
		self.assertEqual(len(shared), 1, "person2 should still have one shared contact")
		self.assertTrue(person1TorId in shared, "person2 should have p1 as shared contact")
		self.assertFalse(possIdsForThem, "person2 shouldn't have any possible contacts")
		# We now make friends with MNO
		person3TorId = "MNO123PQR456ST78"
		person3profile = {"name" : "Scarlet Pimpernel", "keyid" : "someKeyId", "displayName" : "Stranger",
					"status" : "trusted"}
		DbClient.updateContact(person3TorId, person3profile)
		(shared, possIdsForThem, possIdsForMe, _) = ContactMaker.getSharedAndPossibleContacts(person1TorId)
		self.assertEqual(len(shared), 1, "person1 should still have one shared contact")
		self.assertTrue(person2TorId in shared, "person1 should have p2 as shared contact")
		self.assertEqual(len(possIdsForThem), 1, "person1 should have one possible contact now")
		self.assertTrue(person3TorId in possIdsForThem, "person1 should have p3 as possible contact")
		(shared, possIdsForThem, possIdsForMe, _) = ContactMaker.getSharedAndPossibleContacts(person2TorId)
		self.assertEqual(len(shared), 2, "person2 should now have 2 shared contacts")
		self.assertTrue(person1TorId in shared, "person2 should have p1 as shared contact")
		self.assertTrue(person3TorId in shared, "person2 should have p3 as shared contact")
		self.assertFalse(possIdsForThem, "person2 shouldn't have any possible contacts")
開發者ID:activityworkshop,項目名稱:Murmeli,代碼行數:60,代碼來源:databasetest.py

示例2: testGetProfile

# 需要導入模塊: from dbclient import DbClient [as 別名]
# 或者: from dbclient.DbClient import _getProfileTable [as 別名]
	def testGetProfile(self):
		# Delete whole profiles table
		DbClient._getProfileTable().remove({})
		self.assertEqual(DbClient._getProfileTable().count(), 0, "Profiles table should be empty")
		# Add own profile
		myTorId = "ABC123DEF456GH78"
		myprofile = {"name" : "Constantin Taylor", "keyid" : "someKeyId", "displayName" : "Me",
					"status" : "self", "ownprofile" : True}
		DbClient.updateContact(myTorId, myprofile)
		self.assertEqual(DbClient._getProfileTable().count(), 1, "Profiles table should have my profile in it")

		profileFromDb = DbClient.getProfile(None)
		self.assertIsNotNone(profileFromDb, "Couldn't retrieve own profile")
		profileFromDb = DbClient.getProfile(myTorId)
		self.assertIsNotNone(profileFromDb, "Couldn't retrieve profile using own id")

		# Initiate contact with a new person
		otherTorId = "PQR123STU456VWX78"
		otherName = "Olivia Barnacles"
		DbClient.updateContact(otherTorId, {"status" : "untrusted", "keyid" : "donotknow", "name" : otherName})
		self.assertEqual(DbClient._getProfileTable().count(), 2, "Profiles table should have 2 profiles")
		self.assertEqual(DbClient.getMessageableContacts().count(), 1, "Profiles table should have 1 messageable")
		self.assertEqual(DbClient.getTrustedContacts().count(), 0, "Profiles table should have 0 trusted")
		profileFromDb = DbClient.getProfile(otherTorId)
		self.assertIsNotNone(profileFromDb, "Couldn't retrieve profile using other id")
		self.assertEqual(profileFromDb.get("name", None), otherName, "Profile name doesn't match what was stored")
		self.assertEqual(profileFromDb.get("status", None), "untrusted", "Profile status doesn't match what was stored")

		# Update existing record, change status
		DbClient.updateContact(otherTorId, {"status" : "trusted"})
		self.assertEqual(DbClient._getProfileTable().count(), 2, "Profiles table should still have 2 profiles")
		profileFromDb = DbClient.getProfile(otherTorId)
		self.assertIsNotNone(profileFromDb, "Couldn't retrieve profile using other id")
		self.assertEqual(profileFromDb.get("status", None), "trusted", "Profile status should have been updated")
		self.assertEqual(DbClient.getMessageableContacts().count(), 1, "Profiles table should have 1 messageable")
		self.assertEqual(DbClient.getTrustedContacts().count(), 1, "Profiles table should have 1 trusted")

		# Delete other contact
		DbClient.updateContact(otherTorId, {"status" : "deleted"})
		self.assertEqual(DbClient.getMessageableContacts().count(), 0, "Profiles table should have 0 messageable")
		self.assertEqual(DbClient.getTrustedContacts().count(), 0, "Profiles table should have 0 trusted")
		self.assertFalse(DbClient.hasFriends(), "Shouldn't have any friends any more")
開發者ID:activityworkshop,項目名稱:Murmeli,代碼行數:44,代碼來源:databasetest.py


注:本文中的dbclient.DbClient._getProfileTable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。