def check_freeze(self, recipient_type, sender_type, amount, initial_accounts_number=0, recipient_amount=0, sender_amount=0): self.assertEqual(AccountPrototype._model_class.objects.all().count(), initial_accounts_number) invoice = self.create_invoice(recipient_type=recipient_type, sender_type=sender_type, amount=amount) invoice.freeze() self.assertTrue(invoice.state.is_FROZEN) self.assertEqual(AccountPrototype._model_class.objects.all().count(), 2) recipient = AccountPrototype(model=AccountPrototype._model_class. objects.all().order_by('created_at')[0]) self.assertEqual(recipient.amount, recipient_amount) self.assertEqual(recipient.entity_type, recipient_type) self.assertEqual(recipient.entity_id, self.recipient_id) self.assertTrue(recipient.currency.is_PREMIUM) sender = AccountPrototype(model=AccountPrototype._model_class.objects. all().order_by('created_at')[1]) self.assertEqual(sender.amount, sender_amount) self.assertEqual(sender.entity_type, sender_type) self.assertEqual(sender.entity_id, self.sender_id) self.assertTrue(sender.currency.is_PREMIUM)
def check_force(self, recipient_type, sender_type, initial_recipient_amount, initial_sender_amount, amount, result_recipient_amount, result_sender_amount): invoice = self.create_invoice(recipient_type=recipient_type, sender_type=sender_type, amount=amount) invoice.freeze() self.assertTrue(invoice.state.is_FROZEN) self.assertEqual(AccountPrototype._model_class.objects.all().count(), 2) recipient = AccountPrototype(model=AccountPrototype._model_class. objects.all().order_by('created_at')[0]) self.assertEqual(recipient.amount, initial_recipient_amount) self.assertEqual(recipient.entity_type, recipient_type) self.assertEqual(recipient.entity_id, self.recipient_id) self.assertTrue(recipient.currency.is_PREMIUM) sender = AccountPrototype(model=AccountPrototype._model_class.objects. all().order_by('created_at')[1]) self.assertEqual(sender.amount, initial_sender_amount) self.assertEqual(sender.entity_type, sender_type) self.assertEqual(sender.entity_id, self.sender_id) self.assertTrue(sender.currency.is_PREMIUM) invoice = self.create_invoice(recipient_type=recipient_type, recipient_id=self.recipient_id, sender_type=sender_type, sender_id=self.sender_id, amount=amount, force=True) invoice.force() self.assertTrue(invoice.state.is_CONFIRMED) recipient.reload() sender.reload() self.assertEqual(recipient.amount, result_recipient_amount) self.assertEqual(sender.amount, result_sender_amount)