def perform_group_read(intent): msg = {'name': intent.name} ret = yield Effect(BackendCmd('group_read', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label']) return Group(intent.name, ret['admins'], ret['users'])
def test_perform_group_create(): eff = perform_group_create(EBackendGroupCreate('teamA')) backend_response = {'status': 'ok'} sequence = [(BackendCmd('group_create', {'name': 'teamA'}), const(backend_response))] ret = perform_sequence(sequence, eff) assert ret is None
def perform_pubkey_get(intent): msg = {'id': intent.id} ret = yield Effect(BackendCmd('pubkey_get', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label']) return PubKey(intent.id, from_jsonb64(ret['key']))
def perform_vlob_create(intent): msg = {'blob': to_jsonb64(intent.blob)} ret = yield Effect(BackendCmd('vlob_create', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label']) return VlobAccess(ret['id'], ret['read_trust_seed'], ret['write_trust_seed'])
def perform_user_vlob_read(intent): msg = {} if intent.version is not None: msg['version'] = intent.version ret = yield Effect(BackendCmd('user_vlob_read', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label']) return UserVlobAtom(ret['version'], from_jsonb64(ret['blob']))
def test_perform_vlob_update(): eff = perform_user_vlob_update(EBackendUserVlobUpdate(3, b'bar')) backend_response = {'status': 'ok'} sequence = [(BackendCmd('user_vlob_update', { 'version': 3, 'blob': to_jsonb64(b'bar') }), const(backend_response))] ret = perform_sequence(sequence, eff) assert ret is None
def test_perform_message_new(): eff = perform_message_new(EBackendMessageNew('John', b'my body')) backend_response = {'status': 'ok'} sequence = [ (BackendCmd('message_new', {'recipient': 'John', 'body': to_jsonb64(b'my body')}), const(backend_response)) ] ret = perform_sequence(sequence, eff) assert ret is None
def perform_message_get(intent): msg = {'recipient': intent.recipient, 'offset': intent.offset} ret = yield Effect(BackendCmd('message_get', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label']) return [ Message(msg['count'], from_jsonb64(msg['body'])) for msg in ret['messages'] ]
def perform_vlob_read(intent): assert isinstance(intent.id, str) msg = {'id': intent.id, 'trust_seed': intent.trust_seed} if intent.version is not None: msg['version'] = intent.version ret = yield Effect(BackendCmd('vlob_read', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label']) return VlobAtom(ret['id'], ret['version'], from_jsonb64(ret['blob']))
def test_perform_group_remove_identities(): eff = perform_group_remove_identities( EBackendGroupRemoveIdentities('teamA', ['John'], False)) backend_response = {'status': 'ok'} sequence = [(BackendCmd('group_remove_identities', { 'name': 'teamA', 'identities': ['John'], 'admin': False }), const(backend_response))] ret = perform_sequence(sequence, eff) assert ret is None
async def test_perform_blockstore_get_url_local_to_backend(args): backend_url, raw_blockstore_url, cooked_blockstore_url = args backend = BackendComponent(url=backend_url) eff = backend.perform_blockstore_get_url(None) sequence = [(BackendCmd('blockstore_get_url'), const({ 'status': 'ok', 'url': raw_blockstore_url }))] ret = perform_sequence(sequence, eff) assert ret == cooked_blockstore_url
def test_perform_vlob_read(): eff = perform_user_vlob_read(EBackendUserVlobRead(3)) backend_response = { 'status': 'ok', 'version': 3, 'blob': to_jsonb64(b'fooo') } sequence = [(BackendCmd('user_vlob_read', {'version': 3}), const(backend_response))] ret = perform_sequence(sequence, eff) assert ret == UserVlobAtom(3, b'fooo')
def test_perform_group_read(): eff = perform_group_read(EBackendGroupRead('teamA')) backend_response = { 'status': 'ok', 'admins': ['John'], 'users': ['Bob', 'Alice'] } sequence = [(BackendCmd('group_read', {'name': 'teamA'}), const(backend_response))] ret = perform_sequence(sequence, eff) assert ret == Group('teamA', ['John'], ['Bob', 'Alice'])
def perform_vlob_update(intent): msg = { 'id': intent.id, 'version': intent.version, 'trust_seed': intent.trust_seed, 'blob': to_jsonb64(intent.blob) } ret = yield Effect(BackendCmd('vlob_update', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label'])
def test_perform_pubkey_get_missing_key(): eff = perform_pubkey_get(EBackendPubKeyGet('*****@*****.**')) backend_response = { 'status': 'pubkey_not_found', 'label': 'Public key not found' } sequence = [ (BackendCmd('pubkey_get', {'id': '*****@*****.**'}), const(backend_response)) ] with pytest.raises(PubKeyNotFound): perform_sequence(sequence, eff)
def test_perform_pubkey_get(): eff = perform_pubkey_get(EBackendPubKeyGet('*****@*****.**')) backend_response = { 'status': 'ok', 'id': '*****@*****.**', 'key': to_jsonb64(b"<alice's key>"), } sequence = [ (BackendCmd('pubkey_get', {'id': '*****@*****.**'}), const(backend_response)) ] ret = perform_sequence(sequence, eff) assert ret == PubKey('*****@*****.**', b"<alice's key>")
def test_perform_vlob_update(): eff = perform_vlob_update(EBackendVlobUpdate('42', 'WTS42', 3, b'bar')) backend_response = { 'status': 'ok', } sequence = [ (BackendCmd('vlob_update', {'id': '42', 'trust_seed': 'WTS42', 'version': 3, 'blob': to_jsonb64(b'bar')}), const(backend_response)) ] ret = perform_sequence(sequence, eff) assert ret is None
def test_perform_vlob_create(): eff = perform_vlob_create(EBackendVlobCreate(b'fooo')) backend_response = { 'status': 'ok', 'id': '42', 'read_trust_seed': 'RTS42', 'write_trust_seed': 'WTS42', } sequence = [ (BackendCmd('vlob_create', {'blob': to_jsonb64(b'fooo')}), const(backend_response)) ] ret = perform_sequence(sequence, eff) assert ret == VlobAccess('42', 'RTS42', 'WTS42')
def test_perform_message_get(): eff = perform_message_get(EBackendMessageGet('John', 1)) backend_response = { 'status': 'ok', 'messages': [ {'count': 1, 'body': to_jsonb64(b'body 1')}, {'count': 2, 'body': to_jsonb64(b'body 2')} ] } sequence = [ (BackendCmd('message_get', {'offset': 1, 'recipient': 'John'}), const(backend_response)) ] ret = perform_sequence(sequence, eff) assert ret == [Message(1, b'body 1'), Message(2, b'body 2')]
def test_perform_vlob_read(): eff = perform_vlob_read(EBackendVlobRead('42', 'RTS42', 3)) backend_response = { 'status': 'ok', 'id': '42', 'version': 3, 'blob': to_jsonb64(b'fooo') } sequence = [ (BackendCmd('vlob_read', {'id': '42', 'trust_seed': 'RTS42', 'version': 3}), const(backend_response)) ] ret = perform_sequence(sequence, eff) assert ret == VlobAtom('42', 3, b'fooo')
def perform_message_new(intent): msg = {'recipient': intent.recipient, 'body': to_jsonb64(intent.body)} ret = yield Effect(BackendCmd('message_new', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label'])
def perform_group_create(intent): msg = {'name': intent.name} ret = yield Effect(BackendCmd('group_create', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label'])
def perform_group_remove_identities(intent): msg = {'name': intent.name, 'identities': intent.identities, 'admin': intent.admin} ret = yield Effect(BackendCmd('group_remove_identities', msg)) status = ret['status'] if status != 'ok': raise exception_from_status(status)(ret['label'])