Merge pull request 'fix: don't send emails to VMs that were requested but not created' (#54) from fix-dead-instance-invoices into master
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
Reviewed-on: https://gitea.gna.org/Hostea/dashboard/pulls/54fix-dead-instance-invoices
commit
98973301c3
|
@ -22,6 +22,7 @@ from oauth2_provider.generators import generate_client_id, generate_client_secre
|
||||||
|
|
||||||
from accounts.utils import gen_secret
|
from accounts.utils import gen_secret
|
||||||
from dash.models import Instance
|
from dash.models import Instance
|
||||||
|
from infrastructure.models import InstanceCreated
|
||||||
from billing.utils import generate_invoice, payment_fullfilled
|
from billing.utils import generate_invoice, payment_fullfilled
|
||||||
|
|
||||||
Application = get_application_model()
|
Application = get_application_model()
|
||||||
|
@ -33,10 +34,12 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
instances = Instance.objects.all()
|
instances = Instance.objects.all()
|
||||||
if instances:
|
if instances:
|
||||||
for instance in Instance.objects.all():
|
for paid_instance in InstanceCreated.objects.all():
|
||||||
self.stdout.write(f"Found instance: {instance}")
|
self.stdout.write(f"Found instance: {paid_instance.instance}")
|
||||||
if not payment_fullfilled(instance=instance):
|
if not payment_fullfilled(instance=paid_instance.instance):
|
||||||
self.stdout.write(f"Payment not fulfilled for instance: {instance}")
|
self.stdout.write(
|
||||||
payment = generate_invoice(instance=instance)
|
f"Payment not fulfilled for instance: {paid_instance.instance}"
|
||||||
|
)
|
||||||
|
payment = generate_invoice(instance=paid_instance.instance)
|
||||||
else:
|
else:
|
||||||
self.stdout.write("No instances available")
|
self.stdout.write("No instances available")
|
||||||
|
|
|
@ -148,6 +148,44 @@ class GenerateInvoiceCommand(TestCase):
|
||||||
register_util(t=self, username=self.username)
|
register_util(t=self, username=self.username)
|
||||||
create_configurations(t=self)
|
create_configurations(t=self)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
HOSTEA=infra_custom_config(
|
||||||
|
test_name="test_dont_send_invoices_to_not_created_vms"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
def test_dont_send_invoices_to_not_created_vms(self):
|
||||||
|
|
||||||
|
c = Client()
|
||||||
|
login_util(self, c, "accounts.home")
|
||||||
|
|
||||||
|
instance_name = "tnoinvonocrevm"
|
||||||
|
|
||||||
|
payload = {"name": instance_name, "configuration": self.instance_config[0].name}
|
||||||
|
|
||||||
|
resp = c.post(reverse("dash.instances.new"), payload)
|
||||||
|
self.assertEqual(resp.status_code, 302)
|
||||||
|
self.assertEqual(
|
||||||
|
resp.headers["location"],
|
||||||
|
reverse("billing.invoice.generate", args=(instance_name,)),
|
||||||
|
)
|
||||||
|
|
||||||
|
stdout = StringIO()
|
||||||
|
stderr = StringIO()
|
||||||
|
|
||||||
|
instance = Instance.objects.get(name=instance_name)
|
||||||
|
self.assertEqual(payment_fullfilled(instance=instance), False)
|
||||||
|
prev_len = len(mail.outbox)
|
||||||
|
|
||||||
|
# username exists
|
||||||
|
call_command(
|
||||||
|
"generate_invoice",
|
||||||
|
stdout=stdout,
|
||||||
|
stderr=stderr,
|
||||||
|
)
|
||||||
|
out = stdout.getvalue()
|
||||||
|
print(out)
|
||||||
|
self.assertEqual(instance_name not in out, True)
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
HOSTEA=infra_custom_config(test_name="test_generate_invoice_cmd")
|
HOSTEA=infra_custom_config(test_name="test_generate_invoice_cmd")
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue