fix: re-enable billing app tests
ci/woodpecker/push/woodpecker Pipeline was successful Details

Commented out for debugging, forgot to enable(!!)
fix-ci-author-email-pr-buid-fail
Aravinth Manivannan 2022-07-08 19:31:06 +05:30
parent 2c8a5909cb
commit bebf18946a
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
3 changed files with 104 additions and 103 deletions

View File

@ -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): def setUp(self):
# self.username = "billing_user" self.username = "billing_user"
# 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_payments")) @override_settings(HOSTEA=infra_custom_config(test_name="test_payments"))
# def test_payments(self): def test_payments(self):
# c = Client() c = Client()
# login_util(self, c, "accounts.home") login_util(self, c, "accounts.home")
# instance_name = "test_payments" instance_name = "test_payments"
# create_instance_util( create_instance_util(
# t=self, c=c, instance_name=instance_name, config=self.instance_config[0] t=self, c=c, instance_name=instance_name, config=self.instance_config[0]
# ) )
#
# instance = Instance.objects.get(name=instance_name) instance = Instance.objects.get(name=instance_name)
#
# self.assertEqual(payment_fullfilled(instance=instance), True) self.assertEqual(payment_fullfilled(instance=instance), True)
#
# payment = get_payment_model().objects.get(paid_by=self.user) payment = get_payment_model().objects.get(paid_by=self.user)
# invoice_uri = reverse("billing.invoice.details", args=(payment.public_ref,)) invoice_uri = reverse("billing.invoice.details", args=(payment.public_ref,))
#
# # check if paid invoice is listed in paid invoice list view # check if paid invoice is listed in paid invoice list view
# resp = c.get(reverse("billing.invoice.paid")) resp = c.get(reverse("billing.invoice.paid"))
# self.assertEqual(str.encode(invoice_uri) in resp.content, True) 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 # check if the paid invoice is displayed in the pending invoice view, should not be displayed
# resp = c.get(reverse("billing.invoice.pending")) resp = c.get(reverse("billing.invoice.pending"))
# self.assertEqual(str.encode(invoice_uri) in resp.content, False) self.assertEqual(str.encode(invoice_uri) in resp.content, False)
#
# # check if the invoice details view is rendering paid invoice version # check if the invoice details view is rendering paid invoice version
# resp = c.get(invoice_uri) resp = c.get(invoice_uri)
# self.assertEqual(str.encode(instance_name) in resp.content, True) self.assertEqual(str.encode(instance_name) in resp.content, True)
# self.assertEqual( self.assertEqual(
# str.encode(str(self.instance_config[0].rent)) in resp.content, True str.encode(str(self.instance_config[0].rent)) in resp.content, True
# ) )
# self.assertEqual(str.encode("Paid on") 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 # 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 # shouldn't be possible since payment is already made for the duration
# payment_uri = reverse("billing.invoice.generate", args=(instance.name,)) payment_uri = reverse("billing.invoice.generate", args=(instance.name,))
# resp = c.get(payment_uri) resp = c.get(payment_uri)
# self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
#
# ## payment success page; no real functionality but user is redirected here ## payment success page; no real functionality but user is redirected here
# # by stripe if payment is successful # by stripe if payment is successful
# resp = c.get(reverse("billing.invoice.success", args=(payment.public_ref,))) resp = c.get(reverse("billing.invoice.success", args=(payment.public_ref,)))
# self.assertEqual( self.assertEqual(
# resp.headers["Location"], resp.headers["Location"],
# reverse("infra.create", args=(payment.instance_name,)), reverse("infra.create", args=(payment.instance_name,)),
# ) )
#
# # create_instance_util creates an instance and pays for it. An email is # 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 # 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) # So we are first checking for the last email that was sent(receipt)
# # and then the Gitea instance credentials notification followed by the # and then the Gitea instance credentials notification followed by the
# # invoice generation email. # invoice generation email.
# receipt_mail = mail.outbox.pop() receipt_mail = mail.outbox.pop()
# self.assertEqual( self.assertEqual(
# all( all(
# [ [
# receipt_mail.to[0] == self.email, receipt_mail.to[0] == self.email,
# "This is a receipt for your latest Hostea payment" "This is a receipt for your latest Hostea payment"
# in receipt_mail.body, in receipt_mail.body,
# ] ]
# ), ),
# True, True,
# ) )
#
# instance_notificaiton = mail.outbox.pop() instance_notificaiton = mail.outbox.pop()
# self.assertEqual( self.assertEqual(
# all( all(
# [ [
# instance_notificaiton.to[0] == self.email, instance_notificaiton.to[0] == self.email,
# "Congratulations on your new Gitea instance!" "Congratulations on your new Gitea instance!"
# in instance_notificaiton.body, in instance_notificaiton.body,
# ] ]
# ), ),
# True, True,
# ) )
#
# invoice_generated_mail = mail.outbox.pop() invoice_generated_mail = mail.outbox.pop()
# self.assertEqual( self.assertEqual(
# all( all(
# [ [
# invoice_generated_mail.to[0] == self.email, invoice_generated_mail.to[0] == self.email,
# "An invoice is generated" in invoice_generated_mail.body, "An invoice is generated" in invoice_generated_mail.body,
# ] ]
# ), ),
# True, True,
# ) )
#
# ## payment failure page; no real functionality but user is redirected here ## payment failure page; no real functionality but user is redirected here
# # by stripe if payment is successful # by stripe if payment is successful
# resp = c.get(reverse("billing.invoice.fail", args=(payment.public_ref,))) resp = c.get(reverse("billing.invoice.fail", args=(payment.public_ref,)))
# self.assertEqual(b"failed" in resp.content, True) self.assertEqual(b"failed" in resp.content, True)
class GenerateInvoiceCommand(TestCase): class GenerateInvoiceCommand(TestCase):

View File

@ -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,

View File

@ -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,
) )