async def test_has_data(self): infos, invoices = await self.prepair_complex_data() secret = helpers.get_config()['custom']['data_protector']['secret'] request = await self.client.post( '/data-protection-delete-data', data=data_protector_pb2.PluginDeletionRequest( account_id=str(infos[0].id), secret=secret).SerializeToString()) response = await self.check_success( request, data_protector_pb2.PluginDeletionResponse, raw=True) self.assertEqual( response.result, data_protector_pb2.PluginDeletionResponse.ResultType.Value( 'SUCCESS')) data = await logic.get_data_report(infos[0].id) self.assertCountEqual( data, [('account_info', { 'email': None, 'name': None }), ('invoice', { 'purchased_amount': invoices[0].purchased_amount, 'xsolla_id': invoices[0].xsolla_id }), ('invoice', { 'purchased_amount': invoices[2].purchased_amount, 'xsolla_id': invoices[2].xsolla_id })])
async def test_wrong_secret(self): secret = 'wrong.secret' request = await self.client.post( '/data-protection-delete-data', data=data_protector_pb2.PluginDeletionRequest( account_id='777', secret=secret).SerializeToString()) await self.check_error( request, 'discord.data_protection_delete_data.wrong_secret')
async def test_has_data(self): # prepair data message_1_id = await operations.send_message(sender_id=1, recipients_ids=[2, 3, 4], body='1') message_2_id = await operations.send_message(sender_id=2, recipients_ids=[3, 4, 5], body='2') message_3_id = await operations.send_message(sender_id=3, recipients_ids=[4, 5, 6], body='3') message_4_id = await operations.send_message(sender_id=4, recipients_ids=[2], body='4') messages_ids = [message_1_id, message_2_id, message_3_id, message_4_id] for message_id, account_id in [(messages_ids[0], 1), (messages_ids[0], 2), (messages_ids[0], 3), (messages_ids[0], 4), (messages_ids[1], 2), (messages_ids[2], 4), (messages_ids[2], 5), (messages_ids[2], 6), (messages_ids[3], 4), (messages_ids[3], 2)]: await operations.hide_message(account_id, message_id) removed_messages_ids = await operations.candidates_to_remove_ids() self.assertNotEqual(removed_messages_ids, []) await operations.remove_messages(removed_messages_ids) test_account_id = 3 # request data secret = helpers.get_config()['custom']['data_protector']['secret'] request = await self.client.post( '/data-protection-delete-data', data=data_protector_pb2.PluginDeletionRequest( account_id=str(test_account_id), secret=secret).SerializeToString()) response = await self.check_success( request, data_protector_pb2.PluginDeletionResponse, raw=True) self.assertEqual( response.result, data_protector_pb2.PluginDeletionResponse.ResultType.Value( 'SUCCESS')) removed_messages_ids = await operations.candidates_to_remove_ids() self.assertCountEqual(removed_messages_ids, [messages_ids[2]])
async def test_no_data(self): secret = helpers.get_config()['custom']['data_protector']['secret'] request = await self.client.post( '/data-protection-delete-data', data=data_protector_pb2.PluginDeletionRequest( account_id='777', secret=secret).SerializeToString()) response = await self.check_success( request, data_protector_pb2.PluginDeletionResponse, raw=True) self.assertEqual( response.result, data_protector_pb2.PluginDeletionResponse.ResultType.Value( 'SUCCESS'))
async def test_has_data(self): # prepair data await operations.set_properties([ helpers.property(object_id=100, type=200, value='x.1', mode=relations.MODE.APPEND), helpers.property(object_id=200, type=200, value='x.2', mode=relations.MODE.APPEND), helpers.property(object_id=100, type=200, value='y.1', mode=relations.MODE.APPEND), helpers.property(object_id=300, type=200, value='y.2', mode=relations.MODE.APPEND), helpers.property(object_id=100, type=400, value='x.4', mode=relations.MODE.APPEND) ]) # request data secret = helpers.get_config()['custom']['data_protector']['secret'] request = await self.client.post( '/data-protection-delete-data', data=data_protector_pb2.PluginDeletionRequest( account_id='100', secret=secret).SerializeToString()) response = await self.check_success( request, data_protector_pb2.PluginDeletionResponse, raw=True) self.assertEqual( response.result, data_protector_pb2.PluginDeletionResponse.ResultType.Value( 'SUCCESS')) report = await operations.get_data_report(object_id=100) self.assertCountEqual(report, []) report = await operations.get_data_report(object_id=200) self.assertCountEqual(report, [('property', { 'type': 200, 'value': 'x.2' })])
async def test_has_data(self): # prepair data accounts_infos = await helpers.create_accounts(game_ids=(666, 777, 888) ) await helpers.force_bind(accounts_infos[1].id, discord_id=100500) await helpers.force_bind(accounts_infos[2].id, discord_id=100501) code_1_1 = await operations.get_bind_code(accounts_infos[0].id, expire_timeout=60) code_2 = await operations.get_bind_code(accounts_infos[2].id, expire_timeout=60) code_1_2 = await operations.get_bind_code(accounts_infos[0].id, expire_timeout=60) new_info = await operations.get_account_info_by_id(accounts_infos[2].id ) # request data secret = helpers.get_config()['custom']['data_protector']['secret'] with self.check_event_setupped(True): request = await self.client.post( '/data-protection-delete-data', data=data_protector_pb2.PluginDeletionRequest( account_id='888', secret=secret).SerializeToString()) response = await self.check_success( request, data_protector_pb2.PluginDeletionResponse, raw=True) self.assertEqual( response.result, data_protector_pb2.PluginDeletionResponse.ResultType.Value( 'SUCCESS')) new_info = await operations.get_account_info_by_id(accounts_infos[2].id ) self.assertEqual( new_info, objects.AccountInfo(id=accounts_infos[2].id, game_id=None, discord_id=100501))
async def request_deletion(self, account_id, logger): try: async with aiohttp.ClientSession() as session: data = data_protector_pb2.PluginDeletionRequest( account_id=account_id, secret=self.secret) logger.info('request %s', self.deletion_url) async with session.post( self.deletion_url, data=data.SerializeToString()) as response: logger.info('answer status: %s', response.status) if response.status != 200: return None content = await response.read() except Exception: logger.exception('error while doing request') return None logger.info('answer received') return data_protector_pb2.PluginDeletionResponse.FromString(content)