# Path: registrasion/models/commerce.py
# class Cart(models.Model):
#     class Meta:
# class ProductItem(models.Model):
#     class Meta:
# class DiscountItem(models.Model):
#     class Meta:
# class Invoice(models.Model):
#     class Meta:
# class LineItem(models.Model):
#     class Meta:
# class PaymentBase(models.Model):
#     class Meta:
# class ManualPayment(PaymentBase):
#     class Meta:
# class CreditNote(PaymentBase):
#     class Meta:
# class CleanOnSave(object):
# class CreditNoteApplication(CleanOnSave, PaymentBase):
#     class Meta:
# class CreditNoteRefund(CleanOnSave, models.Model):
# class ManualCreditNoteRefund(CreditNoteRefund):
#     class Meta:
#     def __str__(self):
#     def reserved_carts(cls):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def clean(self):
#     def is_unpaid(self):
#     def is_void(self):
#     def is_paid(self):
#     def is_refunded(self):
#     def total_payments(self):
#     def balance_due(self):
#     def __str__(self):
#     def total_price(self):
#     def __str__(self):
#     def unclaimed(cls):
#     def refunded(cls):
#     def status(self):
#     def is_unclaimed(self):
#     def value(self):
#     def save(self, *a, **k):
#     def clean(self):
#     def clean(self):
#     STATUS_ACTIVE = 1
#     STATUS_PAID = 2
#     STATUS_RELEASED = 3
#     STATUS_TYPES = [
#         (STATUS_ACTIVE, _("Active")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_RELEASED, _("Released")),
#     ]
#     STATUS_UNPAID = 1
#     STATUS_PAID = 2
#     STATUS_REFUNDED = 3
#     STATUS_VOID = 4
#     STATUS_TYPES = [
#         (STATUS_UNPAID, _("Unpaid")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_REFUNDED, _("Refunded")),
#         (STATUS_VOID, _("VOID")),
#     ]
# 
# Path: registrasion/tests/controller_helpers.py
# class TestingCartController(CartController):
# 
#     def set_quantity(self, product, quantity, batched=False):
#         ''' Sets the _quantity_ of the given _product_ in the cart to the given
#         _quantity_. '''
# 
#         self.set_quantities(((product, quantity),))
# 
#     def add_to_cart(self, product, quantity):
#         ''' Adds _quantity_ of the given _product_ to the cart. Raises
#         ValidationError if constraints are violated.'''
# 
#         try:
#             product_item = commerce.ProductItem.objects.get(
#                 cart=self.cart,
#                 product=product)
#             old_quantity = product_item.quantity
#         except ObjectDoesNotExist:
#             old_quantity = 0
#         self.set_quantity(product, old_quantity + quantity)
# 
#     def next_cart(self):
#         if self.cart.status == commerce.Cart.STATUS_ACTIVE:
#             self.cart.status = commerce.Cart.STATUS_PAID
#             self.cart.save()
# 
# Path: registrasion/tests/controller_helpers.py
# class TestingCreditNoteController(CreditNoteController):
# 
#     def refund(self):
#         commerce.CreditNoteRefund.objects.create(
#             parent=self.credit_note,
#             reference="Whoops."
#         )
# 
# Path: registrasion/tests/controller_helpers.py
# class TestingInvoiceController(InvoiceController):
# 
#     def pay(self, reference, amount, pre_validate=True):
#         ''' Testing method for simulating an invoice paymenht by the given
#         amount. '''
# 
#         if pre_validate:
#             # Manual payments don't pre-validate; we should test that things
#             # still work if we do silly things.
#             self.validate_allowed_to_pay()
# 
#         ''' Adds a payment '''
#         commerce.PaymentBase.objects.create(
#             invoice=self.invoice,
#             reference=reference,
#             amount=amount,
#         )
# 
#         self.update_status()


import datetime
from registrasion.models import commerce
from registrasion.tests.controller_helpers import TestingCartController
from registrasion.tests.controller_helpers import TestingCreditNoteController
from registrasion.tests.controller_helpers import TestingInvoiceController




class TestHelperMixin(object):

    def _invoice_containing_prod_1(self, qty=1):
        cart = TestingCartController.for_user(self.USER_1)
        cart.add_to_cart(self.PROD_1, qty)

        return TestingInvoiceController.for_cart(self.reget(cart.cart))

    def _manual_invoice(self, value=1):
        items = [("Item", value)]
        due = datetime.timedelta(hours=1)

# Path: registrasion/models/commerce.py
# class Cart(models.Model):
#     class Meta:
# class ProductItem(models.Model):
#     class Meta:
# class DiscountItem(models.Model):
#     class Meta:
# class Invoice(models.Model):
#     class Meta:
# class LineItem(models.Model):
#     class Meta:
# class PaymentBase(models.Model):
#     class Meta:
# class ManualPayment(PaymentBase):
#     class Meta:
# class CreditNote(PaymentBase):
#     class Meta:
# class CleanOnSave(object):
# class CreditNoteApplication(CleanOnSave, PaymentBase):
#     class Meta:
# class CreditNoteRefund(CleanOnSave, models.Model):
# class ManualCreditNoteRefund(CreditNoteRefund):
#     class Meta:
#     def __str__(self):
#     def reserved_carts(cls):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def clean(self):
#     def is_unpaid(self):
#     def is_void(self):
#     def is_paid(self):
#     def is_refunded(self):
#     def total_payments(self):
#     def balance_due(self):
#     def __str__(self):
#     def total_price(self):
#     def __str__(self):
#     def unclaimed(cls):
#     def refunded(cls):
#     def status(self):
#     def is_unclaimed(self):
#     def value(self):
#     def save(self, *a, **k):
#     def clean(self):
#     def clean(self):
#     STATUS_ACTIVE = 1
#     STATUS_PAID = 2
#     STATUS_RELEASED = 3
#     STATUS_TYPES = [
#         (STATUS_ACTIVE, _("Active")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_RELEASED, _("Released")),
#     ]
#     STATUS_UNPAID = 1
#     STATUS_PAID = 2
#     STATUS_REFUNDED = 3
#     STATUS_VOID = 4
#     STATUS_TYPES = [
#         (STATUS_UNPAID, _("Unpaid")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_REFUNDED, _("Refunded")),
#         (STATUS_VOID, _("VOID")),
#     ]
# 
# Path: registrasion/tests/controller_helpers.py
# class TestingCartController(CartController):
# 
#     def set_quantity(self, product, quantity, batched=False):
#         ''' Sets the _quantity_ of the given _product_ in the cart to the given
#         _quantity_. '''
# 
#         self.set_quantities(((product, quantity),))
# 
#     def add_to_cart(self, product, quantity):
#         ''' Adds _quantity_ of the given _product_ to the cart. Raises
#         ValidationError if constraints are violated.'''
# 
#         try:
#             product_item = commerce.ProductItem.objects.get(
#                 cart=self.cart,
#                 product=product)
#             old_quantity = product_item.quantity
#         except ObjectDoesNotExist:
#             old_quantity = 0
#         self.set_quantity(product, old_quantity + quantity)
# 
#     def next_cart(self):
#         if self.cart.status == commerce.Cart.STATUS_ACTIVE:
#             self.cart.status = commerce.Cart.STATUS_PAID
#             self.cart.save()
# 
# Path: registrasion/tests/controller_helpers.py
# class TestingCreditNoteController(CreditNoteController):
# 
#     def refund(self):
#         commerce.CreditNoteRefund.objects.create(
#             parent=self.credit_note,
#             reference="Whoops."
#         )
# 
# Path: registrasion/tests/controller_helpers.py
# class TestingInvoiceController(InvoiceController):
# 
#     def pay(self, reference, amount, pre_validate=True):
#         ''' Testing method for simulating an invoice paymenht by the given
#         amount. '''
# 
#         if pre_validate:
#             # Manual payments don't pre-validate; we should test that things
#             # still work if we do silly things.
#             self.validate_allowed_to_pay()
# 
#         ''' Adds a payment '''
#         commerce.PaymentBase.objects.create(
#             invoice=self.invoice,
#             reference=reference,
#             amount=amount,
#         )
# 
#         self.update_status()


# Path: registrasion/tests/test_helpers.py
import datetime
from registrasion.models import commerce
from registrasion.tests.controller_helpers import TestingCartController
from registrasion.tests.controller_helpers import TestingCreditNoteController
from registrasion.tests.controller_helpers import TestingInvoiceController





class TestHelperMixin(object):

    def _invoice_containing_prod_1(self, qty=1):
        cart = TestingCartController.for_user(self.USER_1)
        cart.add_to_cart(self.PROD_1, qty)

        return TestingInvoiceController.for_cart(self.reget(cart.cart))

    def _manual_invoice(self, value=1):
        items = [("Item", value)]
        due = datetime.timedelta(hours=1)

        inv = TestingInvoiceController.manual_invoice(self.USER_1, due, items)