Changeset - ae8f39381f4a
[Not reviewed]
0 6 0
Christopher Neugebauer - 8 years ago 2016-04-08 09:49:18
chrisjrn@gmail.com
Flake8 fixes
6 files changed with 4 insertions and 8 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -133,25 +133,24 @@ class InvoiceController(object):
 

	
 
        if user == self.invoice.user:
 
            return True
 

	
 
        if user.is_staff:
 
            return True
 

	
 
        if self.invoice.user.attendee.access_code == access_code:
 
            return True
 

	
 
        return False
 

	
 

	
 
    def _refresh(self):
 
        ''' Refreshes the underlying invoice and cart objects. '''
 
        self.invoice.refresh_from_db()
 
        if self.invoice.cart:
 
            self.invoice.cart.refresh_from_db()
 

	
 
    def validate_allowed_to_pay(self):
 
        ''' Passes cleanly if we're allowed to pay, otherwise raise
 
        a ValidationError. '''
 

	
 
        self._refresh()
 

	
registrasion/tests/controller_helpers.py
Show inline comments
 
from registrasion.controllers.cart import CartController
 
from registrasion.controllers.invoice import InvoiceController
 
from registrasion import models as rego
 

	
 
from django.core.exceptions import ObjectDoesNotExist
 
from django.core.exceptions import ValidationError
 

	
 

	
 
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
...
 
@@ -32,19 +31,19 @@ class TestingCartController(CartController):
 
        self.cart.save()
 

	
 

	
 
class TestingInvoiceController(InvoiceController):
 

	
 
    def pay(self, reference, amount):
 
        ''' Testing method for simulating an invoice paymenht by the given
 
        amount. '''
 

	
 
        self.validate_allowed_to_pay()
 

	
 
        ''' Adds a payment '''
 
        payment = rego.ManualPayment.objects.create(
 
        rego.ManualPayment.objects.create(
 
            invoice=self.invoice,
 
            reference=reference,
 
            amount=amount,
 
        )
 

	
 
        self.update_status()
registrasion/tests/test_discount.py
Show inline comments
 
import pytz
 

	
 
from decimal import Decimal
 

	
 
from registrasion import models as rego
 
from registrasion.controllers import discount
 
from controller_helpers import TestingCartController
 
from controller_helpers import TestingInvoiceController
 

	
 
from test_cart import RegistrationCartTestCase
 

	
 
UTC = pytz.timezone('UTC')
 

	
 

	
 
class DiscountTestCase(RegistrationCartTestCase):
 

	
 
    @classmethod
 
    def add_discount_prod_1_includes_prod_2(
 
            cls,
 
            amount=Decimal(100),
registrasion/tests/test_invoice.py
Show inline comments
...
 
@@ -188,33 +188,31 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        # Should be able to create an invoice after the product is added
 
        current_cart.add_to_cart(self.PROD_1, 1)
 
        invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
 

	
 
        invoice_1.pay("Reference", invoice_1.invoice.value)
 

	
 
        with self.assertRaises(ValidationError):
 
            invoice_1.void()
 

	
 
    def test_cannot_generate_blank_invoice(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        with self.assertRaises(ValidationError):
 
            invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
 
            TestingInvoiceController.for_cart(current_cart.cart)
 

	
 
    def test_cannot_pay_implicitly_void_invoice(self):
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_1, 1)
 
        invoice = TestingInvoiceController.for_cart(self.reget(cart.cart))
 

	
 
        # Implicitly void the invoice
 
        cart.add_to_cart(self.PROD_1, 1)
 

	
 
        with self.assertRaises(ValidationError):
 
            invoice.validate_allowed_to_pay()
 

	
 

	
 

	
 
    # TODO: test partially paid invoice cannot be void until payments
 
    # are refunded
 

	
 
    # TODO: test overpaid invoice results in credit note
 

	
 
    # TODO: test credit note generation more generally
registrasion/util.py
Show inline comments
 
import string
 

	
 
from django.utils.crypto import get_random_string
 

	
 

	
 
def generate_access_code():
 
    ''' Generates an access code for users' payments as well as their
 
    fulfilment code for check-in.
 
    The access code will 4 characters long, which allows for 1,500,625
 
    unique codes, which really should be enough for anyone. '''
 

	
 
    length = 4
 
    # all upper-case letters + digits 1-9 (no 0 vs O confusion)
 
    chars = string.uppercase + string.digits[1:]
 
    # 4 chars => 35 ** 4 = 1500625 (should be enough for anyone)
 
    return get_random_string(length=length, allowed_chars=chars)
registrasion/views.py
Show inline comments
...
 
@@ -475,25 +475,25 @@ def invoice(request, invoice_id, access_code=None):
 
    the user the invoice belongs to; staff; or a request made with the correct
 
    access code.
 
    '''
 

	
 
    invoice_id = int(invoice_id)
 
    inv = rego.Invoice.objects.get(pk=invoice_id)
 

	
 
    current_invoice = InvoiceController(inv)
 

	
 
    if not current_invoice.can_view(
 
            user=request.user,
 
            access_code=access_code,
 
        ):
 
            ):
 
        raise Http404()
 

	
 
    data = {
 
        "invoice": current_invoice.invoice,
 
    }
 

	
 
    return render(request, "registrasion/invoice.html", data)
 

	
 

	
 
@login_required
 
def manual_payment(request, invoice_id):
 
    ''' Allows staff to make manual payments or refunds on an invoice.'''
0 comments (0 inline, 0 general)