Exemplo n.º 1
0
    def test_get_payment_list(self):
        initial_payment = PaymentFactory.create()
        initial_payment.amount = Decimal('10.00')
        initial_payment.save()

        customer = initial_payment.customer
        proforma = initial_payment.proforma
        invoice = initial_payment.invoice
        provider = initial_payment.provider

        url = reverse(
            'payment-list', kwargs={'customer_pk': initial_payment.customer.pk}
        )

        response = self.client.get(url, format='json')

        assert response.status_code == status.HTTP_200_OK

        assert response.data == [OrderedDict([
            ('id', initial_payment.pk),
            ('url', 'http://testserver/customers/%d/payments/%d/' % (
                customer.pk, initial_payment.pk
            )),
            ('customer', 'http://testserver/customers/%d/' % customer.pk),
            ('provider', 'http://testserver/providers/%d/' % provider.pk),
            ('amount', u'10.00'),
            ('currency', 'USD'),
            ('due_date', None),
            ('status', 'unpaid'),
            ('visible', True),
            ('proforma', 'http://testserver/proformas/%d/' % proforma.pk),
            ('invoice', 'http://testserver/invoices/%d/' % invoice.pk)
        ])]

        payments = PaymentFactory.create_batch(2)

        for payment in payments:
            payment.customer = initial_payment.customer
            payment.save()

        response = self.client.get(url, format='json')

        assert response.status_code == status.HTTP_200_OK

        assert len(response.data) == 3
Exemplo n.º 2
0
    def test_payment_overdue_since_last_month_queryset(self):
        payments = PaymentFactory.create_batch(3)

        payments[0].due_date = date.today().replace(day=1)
        payments[0].save()

        payments[1].status = Payment.Status.Pending
        payments[1].due_date = date.today().replace(day=1)
        payments[1].save()

        payments[2].status = Payment.Status.Unpaid
        payments[2].due_date = date.today() - timedelta(days=31)
        payments[2].save()

        queryset = Payment.objects.overdue_since_last_month()

        assert queryset.count() == 1
        assert payments[2] in queryset
Exemplo n.º 3
0
    def test_payment_overdue_queryset(self):
        payments = PaymentFactory.create_batch(3)

        payments[0].due_date = date.today() - timedelta(days=1)
        payments[0].save()

        payments[1].status = Payment.Status.Pending
        payments[1].due_date = date.today() - timedelta(days=3)
        payments[1].save()

        payments[2].status = Payment.Status.Paid
        payments[2].due_date = date.today() - timedelta(days=31)
        payments[2].save()

        queryset = Payment.objects.overdue()

        assert queryset.count() == 2
        for payment in payments[0:1]:
            assert payment in queryset
Exemplo n.º 4
0
    def test_payment_due_this_month_queryset(self):
        payments = PaymentFactory.create_batch(4)

        payments[0].due_date = date.today().replace(day=20)
        payments[0].save()

        payments[1].status = Payment.Status.Pending
        payments[1].due_date = date.today().replace(day=1)
        payments[1].save()

        payments[2].due_date = date.today() - timedelta(days=31)
        payments[2].save()

        payments[3].status = Payment.Status.Canceled
        payments[3].save()

        queryset = Payment.objects.due_this_month()

        assert queryset.count() == 2
        for payment in payments[0:1]:
            assert payment in queryset
Exemplo n.º 5
0
    def test_payment_diff(self):
        payment, other_payment = PaymentFactory.create_batch(2)
        payment.amount = 10

        other_payment.amount = 1010
        other_payment.status = Payment.Status.Paid
        other_payment.due_date = date(2016, 9, 11)
        other_payment.customer = CustomerFactory.create()

        self.maxDiff = None
        self.assertEqual(payment.diff(other_payment),
                         {
                             'status': {'to': 'paid', 'from': 'unpaid'},
                             'due_date': {'to': date(2016, 9, 11), 'from': None},
                             'amount': {'to': 1010, 'from': 10},
                             'customer': {'to': other_payment.customer,
                                          'from': payment.customer},
                             'invoice': {'to': other_payment.invoice,
                                         'from': payment.invoice},
                             'proforma': {'to': other_payment.proforma,
                                          'from': payment.proforma},
                             'provider': {'to': other_payment.provider,
                                          'from': payment.provider}
                        })