本文整理汇总了Python中rogerthat.bizz.friend_helper.FriendHelper类的典型用法代码示例。如果您正苦于以下问题:Python FriendHelper类的具体用法?Python FriendHelper怎么用?Python FriendHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FriendHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getStaticFlow
def getStaticFlow(request):
from rogerthat.dal.service import get_service_menu_item_by_coordinates
from rogerthat.rpc import users
service_identity_user = add_slash_default(users.User(request.service))
get_service_identity(service_identity_user) # azzerts
smd = get_service_menu_item_by_coordinates(service_identity_user, request.coords)
if not smd:
logging.info("No menu item found with coords %s" % request.coords)
return None
if smd.isBroadcastSettings:
response = GetStaticFlowResponseTO()
helper = FriendHelper.from_data_store(service_identity_user, FRIEND_TYPE_SERVICE)
response.staticFlow = generate_broadcast_settings_static_flow(helper, users.get_current_user())
return response
if not smd.staticFlowKey:
logging.info("Menu item %s doesn't reference a static flow" % request.coords)
return None
mfd = MessageFlowDesign.get(smd.staticFlowKey)
static_flow = mfd.js_flow_definitions.get_by_hash(request.staticFlowHash)
if not static_flow:
logging.info("No static flow found on MFD '%s' with hash %s" % (mfd.name, request.staticFlowHash))
return None
response = GetStaticFlowResponseTO()
response.staticFlow = static_flow.definition
return response
示例2: get
def get():
from rogerthat.dal.friend import get_friends_map
from rogerthat.models.properties.friend import FriendDetail
user = users.get_current_user()
friendMap = get_friends_map(user)
return [FriendTO.fromDBFriendDetail(FriendHelper.from_data_store(users.User(f.email), f.type), f)
for f in friendMap.friendDetails if f.type == FriendDetail.TYPE_USER]
示例3: get
def get():
from rogerthat.dal.friend import get_friends_map
user = users.get_current_user()
friendMap = get_friends_map(user)
return [FriendTO.fromDBFriendDetail(FriendHelper.from_data_store(users.User(f.email), f.type), f)
for f in friendMap.friendDetails
if f.type == FriendDetail.TYPE_SERVICE and f.existence == FriendDetail.FRIEND_EXISTENCE_ACTIVE]
示例4: test_invite_response_with_user_data
def test_invite_response_with_user_data(self):
user_data = {'test1': 'bla1', 'test2': 'bla2'}
# friend invites svc_identity_user
invitor = users.get_current_user()
svc_user = users.User(u's%[email protected]' % time.time())
si = create_service_profile(svc_user, u"Default name")[1]
self.assertIsNone(db.get(UserData.createKey(invitor, si.user)))
invite(invitor, remove_slash_default(si.user).email(), None, None, None,
None, origin=ORIGIN_USER_INVITE, app_id=App.APP_ID_ROGERTHAT)
invited_response_receiver(UNIT_TEST_REFS["invited"], json.dumps(user_data))
myFriendMap = get_friends_map(invitor)
assert remove_slash_default(si.user) in myFriendMap.friends
assert myFriendMap.generation > 0
assert get_friend_serviceidentity_connection(invitor, si.user)
ud = db.get(UserData.createKey(invitor, si.user))
self.assertIsNotNone(ud)
helper = FriendHelper.from_data_store(si.user, FRIEND_TYPE_SERVICE)
user_data_string = FriendTO.fromDBFriendMap(helper, myFriendMap, si.user, True, True, invitor).userData
self.assertIsNone(user_data_string)
ud_dict = ud.userData.to_json_dict()
ud_dict['__rt__disabledBroadcastTypes'] = ud_dict.get('__rt__disabledBroadcastTypes', [])
user_data['__rt__disabledBroadcastTypes'] = list()
self.assertDictEqual(user_data, ud_dict)
# test cleanup of UserData
breakFriendShip(invitor, si.user)
self.assertIsNone(db.get(UserData.createKey(invitor, si.user)))
示例5: test_cs_helper_for_user
def test_cs_helper_for_user(self):
helper = FriendHelper.serialize(self.john, FriendTO.TYPE_USER)
self.assertIsInstance(helper.get_profile_info(), UserProfile)
self.assertIsNone(helper.get_service_profile())
self.assertIsNone(helper.get_share_sid())
self.assertIsNone(helper.get_translator())
self.assertIsNone(helper.get_service_data())
self.assertListEqual(helper.list_service_menu_items(), [])
示例6: get_full_services_list
def get_full_services_list():
from rogerthat.dal.friend import get_friends_map_cached
app_user = users.get_current_user()
friendMap = get_friends_map_cached(app_user)
return [FriendTO.fromDBFriendDetail(FriendHelper.from_data_store(users.User(fd.email), fd.type),
fd, True, True, tagetUser=app_user)
for fd in (friendMap.friendDetails[friend.email()] for friend in friendMap.friends)
if fd.isService and fd.existence == fd.FRIEND_EXISTENCE_ACTIVE]
示例7: _serialize_and_update_friend_for_service_identity
def _serialize_and_update_friend_for_service_identity(service_identity_user, clear_broadcast_settings_cache,
get_fsics_query_function, get_fsics_query_function_args,
worker_queue=HIGH_LOAD_WORKER_QUEUE):
helper = FriendHelper.serialize(service_identity_user, FRIEND_TYPE_SERVICE)
run_job(get_fsics_query_function, get_fsics_query_function_args, _update_friend_via_friend_connection,
[helper, clear_broadcast_settings_cache],
worker_queue=worker_queue)
示例8: test_friend_to
def test_friend_to(self):
self._extend_service()
app_user = users.User(u'[email protected]')
create_user_profile(app_user, u"John Doe")
makeFriends(app_user, self.service_user, self.service_user, None, ORIGIN_USER_INVITE)
cs_helper = FriendHelper.serialize(self.service_identity_user, FriendTO.TYPE_SERVICE)
ds_helper = FriendHelper.from_data_store(self.service_user, FriendTO.TYPE_SERVICE)
friend_map = get_friends_map(app_user)
friend_detail = friend_map.friendDetails[self.service_user.email()]
status = UpdateFriendRequestTO.STATUS_MODIFIED
ds_friend = convert_friend(ds_helper, app_user, friend_detail, status)
cs_friend = convert_friend(cs_helper, app_user, friend_detail, status)
self.assertDictEqual(ds_friend.to_dict(), cs_friend.to_dict())
示例9: trans
def trans(user):
helper = FriendHelper.serialize(user, friend_type)
if friend_type == FRIEND_TYPE_SERVICE:
user = remove_slash_default(user)
else:
update_friend_service_identity_connections(UserProfile.createKey(user), changed_properties)
run_job(get_friends_friends_maps_keys_query, [user], _update_friend, [helper, clear_broadcast_settings_cache],
worker_queue=worker_queue)
示例10: get_full_service
def get_full_service(service):
from rogerthat.dal.friend import get_friends_map
user = users.get_current_user()
service_identity_user = add_slash_default(users.User(service))
azzert(get_friend_serviceidentity_connection(user, service_identity_user),
"%s tried to get full service %s, but is not connected to this service identity"
% (user.email(), service_identity_user.email()))
helper = FriendHelper.from_data_store(service_identity_user, FRIEND_TYPE_SERVICE)
return FriendTO.fromDBFriendMap(helper, get_friends_map(user), service_identity_user, includeServiceDetails=True,
targetUser=user)
示例11: test_generated_broadcast_settings_flow
def test_generated_broadcast_settings_flow(self):
user_profile, service_profile = self._prepare_users()
friend_user = user_profile.user
service_identity_user = add_slash_default(service_profile.user)
helper = FriendHelper.from_data_store(service_identity_user, FRIEND_TYPE_SERVICE)
helper.get_service_profile()
helper._service_profile = service_profile # because we modify the service_profile which is cached by the helper
makeFriends(friend_user, service_identity_user, service_identity_user, None, origin=ORIGIN_USER_INVITE)
# No broadcast types ==> no flow
self.assertFalse(generate_broadcast_settings_static_flow(helper, user_profile.user))
service_profile.broadcastTypes = ['Apes', 'Birds', 'Cats', 'Dogs']
service_profile.put()
friend_service_identity_connection = get_friend_serviceidentity_connection(friend_user, service_identity_user)
friend_service_identity_connection.enabled_broadcast_types = service_profile.broadcastTypes
friend_service_identity_connection.put()
self.assertTrue(generate_broadcast_settings_static_flow(helper, user_profile.user))
mfds = generate_broadcast_settings_flow_def(helper, user_profile)
self.assertEqual(1, len(mfds.definition))
mf_def = mfds.definition[0]
self.assertEqual(1, len(mf_def.formMessage))
fm = mf_def.formMessage[0]
self.assertEqual(len(service_profile.broadcastTypes), len(fm.form.widget.choice))
self.assertEqual(0, len(service_profile.broadcastTypes) - len(fm.form.widget.value)) # 0 disabled values
friend_service_identity_connection1 = get_friend_serviceidentity_connection(friend_user, service_identity_user)
friend_service_identity_connection1.enabled_broadcast_types = ['Birds', 'Cats', 'Dogs']
friend_service_identity_connection1.disabled_broadcast_types = ['Apes']
friend_service_identity_connection1.put()
mfds = generate_broadcast_settings_flow_def(helper, user_profile)
self.assertEqual(1, len(mfds.definition))
mf_def = mfds.definition[0]
self.assertEqual(1, len(mf_def.formMessage))
fm = mf_def.formMessage[0]
self.assertEqual(len(service_profile.broadcastTypes), len(fm.form.widget.choice))
self.assertEqual(1, len(service_profile.broadcastTypes) - len(fm.form.widget.value)) # 1 disabled values
friend_service_identity_connection2 = get_friend_serviceidentity_connection(friend_user, service_identity_user)
friend_service_identity_connection2.enabled_broadcast_types = ['Cats', 'Dogs']
friend_service_identity_connection2.disabled_broadcast_types = ['Apes', 'Birds']
friend_service_identity_connection2.put()
mfds = generate_broadcast_settings_flow_def(helper, user_profile)
self.assertEqual(1, len(mfds.definition))
mf_def = mfds.definition[0]
self.assertEqual(1, len(mf_def.formMessage))
fm = mf_def.formMessage[0]
self.assertEqual(len(service_profile.broadcastTypes), len(fm.form.widget.choice))
self.assertEqual(2, len(service_profile.broadcastTypes) - len(fm.form.widget.value)) # 2 disabled values
示例12: getFriendsList
def getFriendsList(request):
from rogerthat.rpc import users
from rogerthat.dal.friend import get_friends_map
user = users.get_current_user()
friendMap = get_friends_map(user)
response = GetFriendsListResponseTO()
get_helper = lambda f: FriendHelper.from_data_store(users.User(f.email), f.type)
response.friends = [FriendTO.fromDBFriendDetail(get_helper(f), f, True, True, targetUser=user)
for f in friendMap.friendDetails]
response.generation = friendMap.generation
return response
示例13: test_user_data
def test_user_data(self):
service_user = self._prepare_svc()
friend_email = u"a%[email protected]" % time.time()
data = json.dumps(dict(test="hihihi")).decode('utf8')
self.assertRaises(FriendNotFoundException, put_user_data, friend_email, data) # non-existing user
human_user = users.User(friend_email)
create_user_profile(human_user, friend_email, language=u'nl')
self.assertRaises(FriendNotFoundException, put_user_data, friend_email, data) # user is no friend
makeFriends(human_user, service_user, None, None, None)
data = json.dumps(dict(test="ikkel", moe="hahaha")).decode('utf8')
put_user_data(friend_email, data)
data = json.dumps(dict(test="tikkel", john="doe")).decode('utf8')
put_user_data(friend_email, data)
get_helper = lambda: FriendHelper.from_data_store(service_user, FRIEND_TYPE_SERVICE)
get_friendto = lambda: run_in_xg_transaction(lambda: FriendTO.fromDBFriendMap(get_helper(),
get_friends_map(human_user),
service_user,
True,
True,
human_user))
ud = db.get(UserData.createKey(human_user, create_service_identity_user(service_user)))
ud_dict = ud.userData.to_json_dict()
ud_dict['__rt__disabledBroadcastTypes'] = ud_dict.get('__rt__disabledBroadcastTypes', [])
self.assertDictEqual(dict(test="tikkel", moe="hahaha", john="doe", __rt__disabledBroadcastTypes=[]),
ud_dict)
self.assertTrue(get_friendto().hasUserData)
self.assertRaises(InvalidJsonStringException, put_user_data, friend_email, "invalid user data")
self.assertRaises(InvalidJsonStringException, put_user_data, friend_email, "")
del_user_data(friend_email, ["test"])
self.assertTrue(get_friendto().hasUserData)
del_user_data(friend_email, ["moe", "john"])
self.assertFalse(get_friendto().hasUserData)
japanese = u"スキーに行くのが好きです。"
data_dict = dict(test="ikkel", moe="hahaha", japanese=japanese)
data = json.dumps(data_dict).decode('utf8')
put_user_data(friend_email, data)
data = json.loads(get_user_data(friend_email, ["japanese"]))
self.assertEqual(japanese, data["japanese"])
data = json.loads(get_user_data(friend_email, ["japanese", "test", "moe"]))
self.assertDictEqual(data, data_dict)
示例14: test_menu_items
def test_menu_items(self):
user_profile, service_profile = self._prepare_users()
friend_user = user_profile.user
service_user = service_profile.user
service_identity = get_default_service_identity(service_profile.user)
makeFriends(friend_user, service_identity.user, service_identity.user, None, origin=ORIGIN_USER_INVITE)
helper = FriendHelper.from_data_store(service_identity.user, FRIEND_TYPE_SERVICE)
helper.get_service_profile()
helper._service_profile = service_profile # because we modify the service_profile which is cached by the helper
menu = ServiceMenuTO.from_model(helper, user_profile.language, user_profile)
self.assertEqual(0, len(menu.items))
# No broadcast types --> error
self.assertRaises(BusinessException, create_menu_item, service_user, "3d", "000000", "label", "tag", [1, 1, 1],
None, None, False, False, [], is_broadcast_settings=True, broadcast_branding=None)
service_profile.broadcastTypes = ['Apes', 'Birds', 'Cats', 'Dogs']
service_profile.put()
friend_service_identity_connection = get_friend_serviceidentity_connection(friend_user, service_identity.user)
friend_service_identity_connection.enabled_broadcast_types = service_profile.broadcastTypes
friend_service_identity_connection.put()
create_menu_item(service_user, "3d", "000000", "label", "tag", [1, 1, 1], None, None, False, False, [],
is_broadcast_settings=True, broadcast_branding=None)
def _test_1_bc_settings_item():
menu = ServiceMenuTO.from_model(helper, user_profile.language, user_profile)
self.assertEqual(1, len(menu.items))
smi = menu.items[0]
self.assertTrue(smi.staticFlowHash)
request = GetStaticFlowRequestTO()
request.service = service_user.email()
request.staticFlowHash = smi.staticFlowHash
request.coords = smi.coords
response = getStaticFlow(request)
self.assertTrue(response)
self.assertTrue(response.staticFlow)
_test_1_bc_settings_item()
move_menu_item(service_user, [1, 1, 1], [2, 2, 2])
_test_1_bc_settings_item()
# test Web-version of menu TO
WebServiceMenuTO.from_model(helper, user_profile.language, user_profile)
示例15: populate_friend_response
def populate_friend_response():
friend_detail = friend_map.friendDetails[friend.email()]
helper = FriendHelper.from_data_store(users.User(friend_detail.email), friend_detail.type)
response.friend = FriendTO.fromDBFriendDetail(helper, friend_detail, True, True, targetUser=user)
response.avatar = unicode(base64.b64encode(get_avatar(friend_detail.avatarId, avatar_size)))
if friend_detail.type == FRIEND_TYPE_SERVICE:
service_identity_user = add_slash_default(friend)
keys = [UserData.createKey(user, service_identity_user),
FriendServiceIdentityConnection.createKey(user, service_identity_user)]
user_data_model, fsic = db.get(keys)
to_put.extend(create_send_user_data_requests(mobiles, user_data_model, fsic, user, service_identity_user))
to_put.extend(
create_send_app_data_requests(mobiles, user, helper))