def new(cls, user_id: str, message_id: str): if not isinstance(user_id, str): raise ValueError('user_id is not str') if not isinstance(message_id, str): raise ValueError('message_id is not str') return cls(RecordID(cls.record_type, Receipt.consistent_id(user_id, message_id)), user_id, None, data={ 'user': Reference(RecordID('user', user_id)), 'message': Reference(RecordID('message', message_id)) })
def __init__(self, user_id: str, message_id: str): if not isinstance(user_id, str): raise ValueError('user_id is not str') if not isinstance(message_id, str): raise ValueError('message_id is not str') self.record = Record( RecordID('receipt', Receipt.consistent_id(user_id, message_id)), user_id, None, data={ 'user_id': Reference(RecordID('user', user_id)), 'message_id': Reference(RecordID('message', message_id)) } )
def new(cls, conversation, user_id): record = cls(None, user_id, conversation.get_user_conversation_acl()) record['user'] = Reference(RecordID('user', user_id)) record['conversation'] = Reference(conversation.id) record['unread_count'] = 0 record['is_admin'] = False return record
def hello(): """ This lamda returns some skydb types to the caller. This demonstrates the lambda can return skydb types. ``` curl -X "POST" "http://localhost:3000" \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "api_key": "secret", "action": "hello" }' ``` """ return [ 1, 2, True, "hello", Location(1, 2), Record( id=RecordID("note", "99D92DBA-74D5-477F-B35E-F735E21B2DD5"), owner_id="OWNER_ID", acl=None, data={ "content": "Hello World!", } ), { 'location': Location(1, 2) } ]
def test_reference(self): value = { "$type": "ref", "$id": "note/c1d0e8d4-648c-4c88-86c6-22feb1a6e734" } assert deserialize_value(value) == \ Reference(RecordID("note", "c1d0e8d4-648c-4c88-86c6-22feb1a6e734"))
def new(cls, conversation_id, user_id): return Conversation(RecordID(cls.record_type, conversation_id), user_id, [RoleAccessControlEntry( cls.get_admin_role(conversation_id), ACCESS_CONTROL_ENTRY_LEVEL_WRITE), RoleAccessControlEntry( cls.get_participant_role(conversation_id), ACCESS_CONTROL_ENTRY_LEVEL_READ)])
def __init__(self, message): super().__init__(RecordID(self.record_type, str(uuid.uuid4())), current_user_id(), message.acl) for key in [ 'attachment', 'body', 'metadata', 'conversation', 'message_status', 'edited_by', 'edited_at' ]: if key in message: self[key] = message.get(key, None) self['parent'] = Reference(message.id)
def test_forgot_password_email(email, text_template=None, html_template=None, subject=None, sender=None, reply_to=None, sender_name=None, reply_to_name=None): access_key_type = current_context().get('access_key_type') if not access_key_type or access_key_type != 'master': raise SkygearException('master key is required', skyerror.AccessKeyNotAccepted) url_prefix = settings.url_prefix if url_prefix.endswith('/'): url_prefix = url_prefix[:-1] dummy_user = namedtuple('User', ['id', 'email'])('dummy-id', '*****@*****.**') dummy_record_id = RecordID('user', 'dummy-id') dummy_record = Record(dummy_record_id, dummy_record_id.key, None) template_params = { 'appname': settings.app_name, 'code': 'dummy-reset-code', 'url_prefix': url_prefix, 'link': '{}/example-reset-password-link'.format(url_prefix), 'user_record': dummy_record, 'user': dummy_user, 'email': dummy_user.email, 'user_id': dummy_user.id } email_sender = (sender_name, sender) if sender \ else (settings.sender_name, settings.sender) email_subject = subject if subject else settings.subject email_reply_to = (reply_to_name, reply_to) if reply_to \ else (settings.reply_to_name, settings.reply_to) try: mail_sender.send(email_sender, email, email_subject, reply_to=email_reply_to, text_template_string=text_template, html_template_string=html_template, template_params=template_params) except Exception as ex: logger.exception('An error occurred sending test reset password' ' email to user.') raise SkygearException(str(ex), skyerror.UnexpectedError) return {'status': 'OK'}
def test_record(self): value = Record(id=RecordID("note", "99D92DBA-74D5-477F-B35E-F735E21B2DD5"), owner_id="OWNER_ID", acl=None, data={ "content": "Hello World!", }) assert serialize_value(value) == \ { "$type": "record", "$record": { "_access": None, "_id": "note/99D92DBA-74D5-477F-B35E-F735E21B2DD5", "_ownerID": "OWNER_ID", "content": "Hello World!", } }
def test_normal(self): r = Record( id=RecordID('note', '99D92DBA-74D5-477F-B35E-F735E21B2DD5'), owner_id='OWNER_ID', acl=None, data={ "content": "Hello World!", "noteOrder": 1, "money": UnknownValue("money"), }) rdata = serialize_record(r) assert rdata == { "_access": None, "_id": "note/99D92DBA-74D5-477F-B35E-F735E21B2DD5", "_ownerID": "OWNER_ID", "content": "Hello World!", "noteOrder": 1, "money": {'$type': 'unknown', '$underlying_type': 'money'}, }
def id(self): return RecordID(self.record_type, self.get_hash())