def test_get_for_or_create__create(self): AccountPrototype.get_for_or_create(entity_type=ENTITY_TYPE.GAME_LOGIC, entity_id=self.entity_id, currency=CURRENCY_TYPE.PREMIUM) self.assertEqual( AccountPrototype._model_class.objects.filter( entity_id=self.entity_id).count(), 2)
def check_confirm(self, recipient_type, sender_type, initial_recipient_amount, initial_sender_amount, amount, result_recipient_amount, result_sender_amount): recipient = AccountPrototype.get_for_or_create(entity_type=recipient_type, entity_id=self.recipient_id, currency=CURRENCY_TYPE.PREMIUM) recipient.amount = initial_recipient_amount recipient.save() sender = AccountPrototype.get_for_or_create(entity_type=sender_type, entity_id=self.sender_id, currency=CURRENCY_TYPE.PREMIUM) sender.amount = initial_sender_amount sender.save() invoice = self.create_invoice(recipient_type=recipient_type, recipient_id=self.recipient_id, sender_type=sender_type, sender_id=self.sender_id, amount=amount) invoice.freeze() self.assertTrue(invoice.state.is_FROZEN) recipient.reload() sender.reload() self.assertEqual(recipient.amount, initial_recipient_amount) self.assertEqual(sender.amount, initial_sender_amount) invoice.confirm() recipient.reload() sender.reload() self.assertEqual(recipient.amount, result_recipient_amount) self.assertEqual(sender.amount, result_sender_amount) self.assertTrue(invoice.state.is_CONFIRMED)
def check_confirm(self, recipient_type, sender_type, initial_recipient_amount, initial_sender_amount, amount, result_recipient_amount, result_sender_amount): recipient = AccountPrototype.get_for_or_create( entity_type=recipient_type, entity_id=self.recipient_id, currency=CURRENCY_TYPE.PREMIUM) recipient.amount = initial_recipient_amount recipient.save() sender = AccountPrototype.get_for_or_create( entity_type=sender_type, entity_id=self.sender_id, currency=CURRENCY_TYPE.PREMIUM) sender.amount = initial_sender_amount sender.save() invoice = self.create_invoice(recipient_type=recipient_type, recipient_id=self.recipient_id, sender_type=sender_type, sender_id=self.sender_id, amount=amount) invoice.freeze() self.assertTrue(invoice.state.is_FROZEN) recipient.reload() sender.reload() self.assertEqual(recipient.amount, initial_recipient_amount) self.assertEqual(sender.amount, initial_sender_amount) invoice.confirm() recipient.reload() sender.reload() self.assertEqual(recipient.amount, result_recipient_amount) self.assertEqual(sender.amount, result_sender_amount) self.assertTrue(invoice.state.is_CONFIRMED)
def test_get_for_or_create__get(self): AccountPrototype.get_for_or_create( entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=self.entity_id, currency=CURRENCY_TYPE.PREMIUM ) self.assertEqual(AccountPrototype._model_class.objects.filter(entity_id=self.entity_id).count(), 1)