fix: re-enable billing app tests
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
Commented out for debugging, forgot to enable(!!)fix-ci-author-email-pr-buid-fail
parent
2c8a5909cb
commit
bebf18946a
200
billing/tests.py
200
billing/tests.py
|
@ -35,107 +35,107 @@ from .models import Payment
|
||||||
from .utils import payment_fullfilled
|
from .utils import payment_fullfilled
|
||||||
|
|
||||||
|
|
||||||
# class BillingTest(TestCase):
|
class BillingTest(TestCase):
|
||||||
# """
|
"""
|
||||||
# Tests billing system
|
Tests billing system
|
||||||
# """
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.username = "billing_user"
|
||||||
|
register_util(t=self, username=self.username)
|
||||||
|
create_configurations(t=self)
|
||||||
|
|
||||||
|
@override_settings(HOSTEA=infra_custom_config(test_name="test_payments"))
|
||||||
|
def test_payments(self):
|
||||||
|
c = Client()
|
||||||
|
login_util(self, c, "accounts.home")
|
||||||
|
instance_name = "test_payments"
|
||||||
|
create_instance_util(
|
||||||
|
t=self, c=c, instance_name=instance_name, config=self.instance_config[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
instance = Instance.objects.get(name=instance_name)
|
||||||
|
|
||||||
|
self.assertEqual(payment_fullfilled(instance=instance), True)
|
||||||
|
|
||||||
|
payment = get_payment_model().objects.get(paid_by=self.user)
|
||||||
|
invoice_uri = reverse("billing.invoice.details", args=(payment.public_ref,))
|
||||||
|
|
||||||
|
# check if paid invoice is listed in paid invoice list view
|
||||||
|
resp = c.get(reverse("billing.invoice.paid"))
|
||||||
|
self.assertEqual(str.encode(invoice_uri) in resp.content, True)
|
||||||
|
|
||||||
|
# check if the paid invoice is displayed in the pending invoice view, should not be displayed
|
||||||
|
resp = c.get(reverse("billing.invoice.pending"))
|
||||||
|
self.assertEqual(str.encode(invoice_uri) in resp.content, False)
|
||||||
|
|
||||||
|
# check if the invoice details view is rendering paid invoice version
|
||||||
|
resp = c.get(invoice_uri)
|
||||||
|
self.assertEqual(str.encode(instance_name) in resp.content, True)
|
||||||
|
self.assertEqual(
|
||||||
|
str.encode(str(self.instance_config[0].rent)) in resp.content, True
|
||||||
|
)
|
||||||
|
self.assertEqual(str.encode("Paid on") in resp.content, True)
|
||||||
|
|
||||||
|
# try to generate an invoice for the second time on the same VM
|
||||||
|
# shouldn't be possible since payment is already made for the duration
|
||||||
|
payment_uri = reverse("billing.invoice.generate", args=(instance.name,))
|
||||||
|
resp = c.get(payment_uri)
|
||||||
|
self.assertEqual(resp.status_code, 400)
|
||||||
|
|
||||||
|
## payment success page; no real functionality but user is redirected here
|
||||||
|
# by stripe if payment is successful
|
||||||
|
resp = c.get(reverse("billing.invoice.success", args=(payment.public_ref,)))
|
||||||
|
self.assertEqual(
|
||||||
|
resp.headers["Location"],
|
||||||
|
reverse("infra.create", args=(payment.instance_name,)),
|
||||||
|
)
|
||||||
|
|
||||||
|
# create_instance_util creates an instance and pays for it. An email is
|
||||||
|
# sent when the invoice is generated and one after payment is made
|
||||||
#
|
#
|
||||||
# def setUp(self):
|
# So we are first checking for the last email that was sent(receipt)
|
||||||
# self.username = "billing_user"
|
# and then the Gitea instance credentials notification followed by the
|
||||||
# register_util(t=self, username=self.username)
|
# invoice generation email.
|
||||||
# create_configurations(t=self)
|
receipt_mail = mail.outbox.pop()
|
||||||
#
|
self.assertEqual(
|
||||||
# @override_settings(HOSTEA=infra_custom_config(test_name="test_payments"))
|
all(
|
||||||
# def test_payments(self):
|
[
|
||||||
# c = Client()
|
receipt_mail.to[0] == self.email,
|
||||||
# login_util(self, c, "accounts.home")
|
"This is a receipt for your latest Hostea payment"
|
||||||
# instance_name = "test_payments"
|
in receipt_mail.body,
|
||||||
# create_instance_util(
|
]
|
||||||
# t=self, c=c, instance_name=instance_name, config=self.instance_config[0]
|
),
|
||||||
# )
|
True,
|
||||||
#
|
)
|
||||||
# instance = Instance.objects.get(name=instance_name)
|
|
||||||
#
|
instance_notificaiton = mail.outbox.pop()
|
||||||
# self.assertEqual(payment_fullfilled(instance=instance), True)
|
self.assertEqual(
|
||||||
#
|
all(
|
||||||
# payment = get_payment_model().objects.get(paid_by=self.user)
|
[
|
||||||
# invoice_uri = reverse("billing.invoice.details", args=(payment.public_ref,))
|
instance_notificaiton.to[0] == self.email,
|
||||||
#
|
"Congratulations on your new Gitea instance!"
|
||||||
# # check if paid invoice is listed in paid invoice list view
|
in instance_notificaiton.body,
|
||||||
# resp = c.get(reverse("billing.invoice.paid"))
|
]
|
||||||
# self.assertEqual(str.encode(invoice_uri) in resp.content, True)
|
),
|
||||||
#
|
True,
|
||||||
# # check if the paid invoice is displayed in the pending invoice view, should not be displayed
|
)
|
||||||
# resp = c.get(reverse("billing.invoice.pending"))
|
|
||||||
# self.assertEqual(str.encode(invoice_uri) in resp.content, False)
|
invoice_generated_mail = mail.outbox.pop()
|
||||||
#
|
self.assertEqual(
|
||||||
# # check if the invoice details view is rendering paid invoice version
|
all(
|
||||||
# resp = c.get(invoice_uri)
|
[
|
||||||
# self.assertEqual(str.encode(instance_name) in resp.content, True)
|
invoice_generated_mail.to[0] == self.email,
|
||||||
# self.assertEqual(
|
"An invoice is generated" in invoice_generated_mail.body,
|
||||||
# str.encode(str(self.instance_config[0].rent)) in resp.content, True
|
]
|
||||||
# )
|
),
|
||||||
# self.assertEqual(str.encode("Paid on") in resp.content, True)
|
True,
|
||||||
#
|
)
|
||||||
# # try to generate an invoice for the second time on the same VM
|
|
||||||
# # shouldn't be possible since payment is already made for the duration
|
## payment failure page; no real functionality but user is redirected here
|
||||||
# payment_uri = reverse("billing.invoice.generate", args=(instance.name,))
|
# by stripe if payment is successful
|
||||||
# resp = c.get(payment_uri)
|
resp = c.get(reverse("billing.invoice.fail", args=(payment.public_ref,)))
|
||||||
# self.assertEqual(resp.status_code, 400)
|
self.assertEqual(b"failed" in resp.content, True)
|
||||||
#
|
|
||||||
# ## payment success page; no real functionality but user is redirected here
|
|
||||||
# # by stripe if payment is successful
|
|
||||||
# resp = c.get(reverse("billing.invoice.success", args=(payment.public_ref,)))
|
|
||||||
# self.assertEqual(
|
|
||||||
# resp.headers["Location"],
|
|
||||||
# reverse("infra.create", args=(payment.instance_name,)),
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# # create_instance_util creates an instance and pays for it. An email is
|
|
||||||
# # sent when the invoice is generated and one after payment is made
|
|
||||||
# #
|
|
||||||
# # So we are first checking for the last email that was sent(receipt)
|
|
||||||
# # and then the Gitea instance credentials notification followed by the
|
|
||||||
# # invoice generation email.
|
|
||||||
# receipt_mail = mail.outbox.pop()
|
|
||||||
# self.assertEqual(
|
|
||||||
# all(
|
|
||||||
# [
|
|
||||||
# receipt_mail.to[0] == self.email,
|
|
||||||
# "This is a receipt for your latest Hostea payment"
|
|
||||||
# in receipt_mail.body,
|
|
||||||
# ]
|
|
||||||
# ),
|
|
||||||
# True,
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# instance_notificaiton = mail.outbox.pop()
|
|
||||||
# self.assertEqual(
|
|
||||||
# all(
|
|
||||||
# [
|
|
||||||
# instance_notificaiton.to[0] == self.email,
|
|
||||||
# "Congratulations on your new Gitea instance!"
|
|
||||||
# in instance_notificaiton.body,
|
|
||||||
# ]
|
|
||||||
# ),
|
|
||||||
# True,
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# invoice_generated_mail = mail.outbox.pop()
|
|
||||||
# self.assertEqual(
|
|
||||||
# all(
|
|
||||||
# [
|
|
||||||
# invoice_generated_mail.to[0] == self.email,
|
|
||||||
# "An invoice is generated" in invoice_generated_mail.body,
|
|
||||||
# ]
|
|
||||||
# ),
|
|
||||||
# True,
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# ## payment failure page; no real functionality but user is redirected here
|
|
||||||
# # by stripe if payment is successful
|
|
||||||
# resp = c.get(reverse("billing.invoice.fail", args=(payment.public_ref,)))
|
|
||||||
# self.assertEqual(b"failed" in resp.content, True)
|
|
||||||
|
|
||||||
|
|
||||||
class GenerateInvoiceCommand(TestCase):
|
class GenerateInvoiceCommand(TestCase):
|
||||||
|
|
|
@ -34,11 +34,13 @@ def __get_delta():
|
||||||
delta = now - timedelta(seconds=(60 * 60 * 24 * 30)) # one month
|
delta = now - timedelta(seconds=(60 * 60 * 24 * 30)) # one month
|
||||||
return delta
|
return delta
|
||||||
|
|
||||||
|
|
||||||
def get_invoice_link(payment: Payment):
|
def get_invoice_link(payment: Payment):
|
||||||
invoice_link = reverse("billing.invoice.details", args=(payment.public_ref,))
|
invoice_link = reverse("billing.invoice.details", args=(payment.public_ref,))
|
||||||
parsed = urlparse(settings.PAYMENT_HOST)
|
parsed = urlparse(settings.PAYMENT_HOST)
|
||||||
return urlunparse((parsed.scheme, parsed.netloc, invoice_link, "", "", ""))
|
return urlunparse((parsed.scheme, parsed.netloc, invoice_link, "", "", ""))
|
||||||
|
|
||||||
|
|
||||||
def payment_fullfilled(instance: Instance) -> bool:
|
def payment_fullfilled(instance: Instance) -> bool:
|
||||||
delta = __get_delta()
|
delta = __get_delta()
|
||||||
|
|
||||||
|
@ -108,7 +110,6 @@ def generate_invoice(instance: Instance) -> Payment:
|
||||||
email = instance.owned_by.email
|
email = instance.owned_by.email
|
||||||
sender = settings.DEFAULT_FROM_EMAIL
|
sender = settings.DEFAULT_FROM_EMAIL
|
||||||
|
|
||||||
|
|
||||||
send_mail(
|
send_mail(
|
||||||
subject="[Hostea] An invoice is generated for your Hostea VM",
|
subject="[Hostea] An invoice is generated for your Hostea VM",
|
||||||
message=body,
|
message=body,
|
||||||
|
|
|
@ -33,7 +33,7 @@ from .utils import (
|
||||||
generate_invoice as generate_invoice_util,
|
generate_invoice as generate_invoice_util,
|
||||||
GenerateInvoiceErrorCode,
|
GenerateInvoiceErrorCode,
|
||||||
GenerateInvoiceException,
|
GenerateInvoiceException,
|
||||||
get_invoice_link
|
get_invoice_link,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue