• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python factories.InvoiceFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中silver.tests.factories.InvoiceFactory的典型用法代码示例。如果您正苦于以下问题:Python InvoiceFactory类的具体用法?Python InvoiceFactory怎么用?Python InvoiceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了InvoiceFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_invoice

    def test_get_invoice(self):
        InvoiceFactory.reset_sequence(1)
        InvoiceFactory.create()

        url = reverse('invoice-detail', kwargs={'pk': 1})
        response = self.client.get(url)

        assert response.status_code == status.HTTP_200_OK
        assert response.data == {
            "id": 1,
            "series": "InvoiceSeries",
            "number": 1,
            "provider": "http://testserver/providers/1/",
            "customer": "http://testserver/customers/1/",
            "archived_provider": {},
            "archived_customer": {},
            "due_date": None,
            "issue_date": None,
            "paid_date": None,
            "cancel_date": None,
            "sales_tax_name": "VAT",
            "sales_tax_percent": '1.00',
            "currency": "RON",
            "state": "draft",
            "proforma": None,
            "invoice_entries": [],
            "pdf_url": None,
            "total": Decimal('0.00'),
        }
开发者ID:MaxMorais,项目名称:silver,代码行数:29,代码来源:test_invoice.py


示例2: test_actions_failed_no_log_entries

    def test_actions_failed_no_log_entries(self):
        InvoiceFactory.create()

        url = reverse('admin:silver_invoice_changelist')

        mock_log_entry = MagicMock()
        mock_log_action = MagicMock()
        mock_log_entry.objects.log_action = mock_log_action

        exceptions = cycle([ValueError, TransitionNotAllowed])

        def _exception_thrower(*args):
            raise exceptions.next()

        mock_action = MagicMock(side_effect=_exception_thrower)

        mock_invoice = MagicMock()
        mock_invoice.issue = mock_action
        mock_invoice.cancel = mock_action
        mock_invoice.pay = mock_action
        mock_invoice.clone_into_draft = mock_action
        mock_invoice.create_invoice = mock_action

        with patch.multiple('silver.admin',
                            LogEntry=mock_log_entry,
                            Invoice=mock_invoice):
            actions = ['issue', 'pay', 'cancel', 'clone']

            for action in actions:
                self.admin.post(url, {
                    'action': action,
                    '_selected_action': [u'1']
                })

                assert not mock_log_action.call_count
开发者ID:MaxMorais,项目名称:silver,代码行数:35,代码来源:test_invoice.py


示例3: test_issue_invoice_with_custom_issue_date_and_due_date

    def test_issue_invoice_with_custom_issue_date_and_due_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {
            'state': 'issued',
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20'
        }

        response = self.client.put(url, data=json.dumps(data),
                                     content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        mandatory_content = {
            'issue_date': '2014-01-01',
            'due_date': '2014-01-20',
            'state': 'issued'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
        assert response.data.get('archived_provider', {}) != {}
        assert response.data.get('archived_customer', {}) != {}

        invoice = get_object_or_None(Invoice, pk=1)
开发者ID:MaxMorais,项目名称:silver,代码行数:28,代码来源:test_invoice.py


示例4: test_pay_invoice_when_in_draft_state

    def test_pay_invoice_when_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {'state': 'paid'}
        response = self.client.put(url, data=json.dumps(data),
                                     content_type='application/json')
        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'An invoice can be paid only if it is in issued state.'}
开发者ID:MaxMorais,项目名称:silver,代码行数:11,代码来源:test_invoice.py


示例5: test_get_invoices

    def test_get_invoices(self):
        batch_size = 50
        InvoiceFactory.create_batch(batch_size)

        url = reverse('invoice-list')
        response = self.client.get(url)

        assert response.status_code == status.HTTP_200_OK

        response = self.client.get(url + '?page=2')

        assert response.status_code == status.HTTP_200_OK
开发者ID:MaxMorais,项目名称:silver,代码行数:12,代码来源:test_invoice.py


示例6: test_illegal_state_change_when_in_draft_state

    def test_illegal_state_change_when_in_draft_state(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        InvoiceFactory.create(provider=provider, customer=customer)

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {'state': 'illegal-state'}

        response = self.client.put(url, data=json.dumps(data),
                                     content_type='application/json')

        assert response.status_code == status.HTTP_403_FORBIDDEN
        assert response.data == {'detail': 'Illegal state value.'}
开发者ID:MaxMorais,项目名称:silver,代码行数:13,代码来源:test_invoice.py


示例7: test_invoice_total_with_tax_integrity

    def test_invoice_total_with_tax_integrity(self):
        invoice_entries = DocumentEntryFactory.create_batch(5)
        invoice = InvoiceFactory.create(invoice_entries=invoice_entries)

        invoice.sales_tax_percent = Decimal('20.00')

        self.assertEqual(invoice.total, invoice.total_before_tax + invoice.tax_value)
开发者ID:PressLabs,项目名称:silver,代码行数:7,代码来源:test_invoice.py


示例8: test_invoice_tax_value_decimal_places

    def test_invoice_tax_value_decimal_places(self):
        invoice_entries = DocumentEntryFactory.create_batch(3)
        invoice = InvoiceFactory.create(invoice_entries=invoice_entries)

        invoice.sales_tax_percent = Decimal('20.00')

        assert self._get_decimal_places(invoice.tax_value) == 2
开发者ID:PressLabs,项目名称:silver,代码行数:7,代码来源:test_invoice.py


示例9: test_documents_list_case_1

    def test_documents_list_case_1(self):
        """
            One proforma, one invoice, without related documents
        """
        proforma = ProformaFactory.create()
        invoice_entries = DocumentEntryFactory.create_batch(3)
        invoice = InvoiceFactory.create(invoice_entries=invoice_entries)
        invoice.issue()
        payment_method = PaymentMethodFactory.create(customer=invoice.customer)
        transaction = TransactionFactory.create(payment_method=payment_method,
                                                invoice=invoice)

        url = reverse('document-list')

        with patch('silver.utils.payments._get_jwt_token',
                   new=self._jwt_token):
            response = self.client.get(url)

        # ^ there's a bug where specifying format='json' doesn't work
        response_data = response.data

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response_data), 2)

        self.assertIn(self._get_expected_data(invoice, [transaction]),
                      response_data)

        self.assertIn(self._get_expected_data(proforma), response_data)
开发者ID:PressLabs,项目名称:silver,代码行数:28,代码来源:test_documents.py


示例10: test_generate_pdf_task

def test_generate_pdf_task(settings, tmpdir, monkeypatch):
    settings.MEDIA_ROOT = tmpdir.strpath

    invoice = InvoiceFactory.create()
    invoice.issue()

    assert invoice.pdf.dirty

    pisa_document_mock = MagicMock(return_value=MagicMock(err=False))

    monkeypatch.setattr('silver.models.documents.pdf.pisa.pisaDocument',
                        pisa_document_mock)

    generate_pdf(invoice.id, invoice.kind)

    # pdf needs to be refreshed as the invoice reference in the test is not the same with the one
    # in the task
    invoice.pdf.refresh_from_db()

    assert not invoice.pdf.dirty

    assert invoice.pdf.url == settings.MEDIA_URL + invoice.get_pdf_upload_path()

    assert pisa_document_mock.call_count == 1

    assert len(pisa_document_mock.mock_calls) == 1
开发者ID:PressLabs,项目名称:silver,代码行数:26,代码来源:test_generate_pdfs.py


示例11: test_invoice_due_today_queryset

    def test_invoice_due_today_queryset(self):
        invoices = InvoiceFactory.create_batch(5)

        invoices[0].state = Invoice.STATES.DRAFT
        invoices[0].due_date = date.today()
        invoices[0].save()

        invoices[1].state = Invoice.STATES.ISSUED
        invoices[1].due_date = date.today()
        invoices[1].save()

        invoices[2].state = Invoice.STATES.PAID
        invoices[2].due_date = date.today() - timedelta(days=1)
        invoices[2].save()

        invoices[3].state = Invoice.STATES.CANCELED
        invoices[3].due_date = date.today()
        invoices[3].save()

        invoices[4].state = Invoice.STATES.ISSUED
        invoices[4].due_date = date.today() + timedelta(days=1)
        invoices[4].save()

        queryset = Invoice.objects.due_today()

        assert queryset.count() == 1
        assert invoices[1] in queryset
开发者ID:oucsaw,项目名称:silver,代码行数:27,代码来源:test_invoice.py


示例12: test_patch_transaction_documents

    def test_patch_transaction_documents(self):
        payment_method = PaymentMethodFactory.create(
            payment_processor='someprocessor'
        )
        transaction = TransactionFactory.create(payment_method=payment_method)
        proforma = ProformaFactory.create()
        invoice = InvoiceFactory.create(proforma=proforma)
        proforma.invoice = invoice
        proforma.save()

        invoice_url = reverse('invoice-detail', args=[invoice.pk])
        proforma_url = reverse('proforma-detail', args=[proforma.pk])
        url = reverse('transaction-detail', args=[transaction.customer.pk,
                                                  transaction.uuid])

        data = {
            'proforma': proforma_url,
            'invoice': invoice_url
        }

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

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        self.assertEqual(response.data, {
            'proforma': [u'This field may not be modified.'],
            'invoice': [u'This field may not be modified.']
        })
开发者ID:oucsaw,项目名称:silver,代码行数:28,代码来源:test_transactions.py


示例13: test_add_transaction_with_unrelated_documents

    def test_add_transaction_with_unrelated_documents(self):
        customer = CustomerFactory.create()
        payment_method = PaymentMethodFactory.create(customer=customer)

        invoice = InvoiceFactory.create(customer=customer)
        proforma = ProformaFactory.create(customer=customer)
        valid_until = datetime.now()
        url = reverse('payment-method-transaction-list',
                      kwargs={'customer_pk': customer.pk, 'payment_method_id': payment_method.pk})
        invoice_url = reverse('invoice-detail', args=[invoice.pk])
        proforma_url = reverse('proforma-detail', args=[proforma.pk])
        data = {
            'payment_method': reverse('payment-method-detail', kwargs={'customer_pk': customer.pk,
                                                                       'payment_method_id': payment_method.id}),
            'valid_until': valid_until,
            'amount': 200.0,
            'invoice': invoice_url,
            'proforma': proforma_url
        }

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

        expected_data = {
            'non_field_errors': [u'Invoice and proforma are not related.']
        }
        self.assertEqual(response.data, expected_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
开发者ID:oucsaw,项目名称:silver,代码行数:27,代码来源:test_transactions.py


示例14: test_invoice_currency_used_for_transaction_currency

    def test_invoice_currency_used_for_transaction_currency(self):
        customer = CustomerFactory.create(currency=None)
        invoice = InvoiceFactory.create(customer=customer,
                                        currency='EUR',
                                        transaction_currency=None)

        self.assertEqual(invoice.transaction_currency, 'EUR')
开发者ID:PressLabs,项目名称:silver,代码行数:7,代码来源:test_invoice.py


示例15: test_cancel_invoice_with_provided_date

    def test_cancel_invoice_with_provided_date(self):
        provider = ProviderFactory.create()
        customer = CustomerFactory.create()
        invoice = InvoiceFactory.create(provider=provider, customer=customer)
        invoice.issue()
        invoice.save()

        url = reverse('invoice-state', kwargs={'pk': 1})
        data = {
            'state': 'canceled',
            'cancel_date': '2014-10-10'
        }

        response = self.client.put(url, data=json.dumps(data),
                                     content_type='application/json')

        assert response.status_code == status.HTTP_200_OK
        due_date = timezone.now().date() + timedelta(days=PAYMENT_DUE_DAYS)
        mandatory_content = {
            'issue_date': timezone.now().date().strftime('%Y-%m-%d'),
            'due_date': due_date.strftime('%Y-%m-%d'),
            'cancel_date': '2014-10-10',
            'state': 'canceled'
        }
        assert response.status_code == status.HTTP_200_OK
        assert all(item in response.data.items()
                   for item in mandatory_content.iteritems())
开发者ID:MaxMorais,项目名称:silver,代码行数:27,代码来源:test_invoice.py


示例16: test_add_single_invoice_entry

    def test_add_single_invoice_entry(self):
        InvoiceFactory.create_batch(10)

        url = reverse('invoice-entry-create', kwargs={'document_pk': 1})
        entry_data = {
            "description": "Page views",
            "unit_price": 10.0,
            "quantity": 20
        }
        response = self.client.post(url, data=json.dumps(entry_data),
                                    content_type='application/json')

        invoice = Invoice.objects.get(pk=1)
        total = Decimal(200.0) * Decimal(1 + invoice.sales_tax_percent / 100)

        assert response.status_code == status.HTTP_201_CREATED
        assert response.data == {
            'description': 'Page views',
            'unit': None,
            'quantity': '20.0000',
            'unit_price': '10.0000',
            'start_date': None,
            'end_date': None,
            'prorated': False,
            'product_code': None,
            'total': total,
            'total_before_tax': Decimal(200.0)
        }

        url = reverse('invoice-detail', kwargs={'pk': 1})
        response = self.client.get(url)

        invoice_entries = response.data.get('invoice_entries', None)
        assert len(invoice_entries) == 1
        assert invoice_entries[0] == {
            'description': 'Page views',
            'unit': None,
            'quantity': '20.0000',
            'unit_price': '10.0000',
            'start_date': None,
            'end_date': None,
            'prorated': False,
            'product_code': None,
            'total': total,
            'total_before_tax': Decimal(200.0)
        }
开发者ID:MaxMorais,项目名称:silver,代码行数:46,代码来源:test_invoice.py


示例17: handle

    def handle(self, *args, **options):
        proforma = ProformaFactory.create(proforma_entries=[DocumentEntryFactory.create()],
                                          state=Proforma.STATES.ISSUED)
        proforma.create_invoice()

        invoice = InvoiceFactory.create(invoice_entries=[DocumentEntryFactory.create()],
                                        state=Invoice.STATES.ISSUED,
                                        related_document=None)
        TransactionFactory.create(state=Transaction.States.Settled,
                                  invoice=invoice,
                                  payment_method__customer=invoice.customer,
                                  proforma=None)
        InvoiceFactory.create_batch(size=3,
                                    invoice_entries=[DocumentEntryFactory.create()],
                                    state=Invoice.STATES.PAID,
                                    related_document=None)
        InvoiceFactory.create_batch(size=3,
                                    invoice_entries=[DocumentEntryFactory.create()],
                                    state=Invoice.STATES.DRAFT,
                                    related_document=None)

        InvoiceFactory.create_batch(size=3,
                                    invoice_entries=[DocumentEntryFactory.create()],
                                    state=Invoice.STATES.CANCELED,
                                    related_document=None)
开发者ID:PressLabs,项目名称:silver,代码行数:25,代码来源:seed.py


示例18: test_draft_invoice_series_number

    def test_draft_invoice_series_number(self):
        invoice = InvoiceFactory.create()
        invoice.number = None

        assert invoice.series_number == '%s-draft-id:%d' % (invoice.series,
                                                            invoice.pk)

        invoice.series = None

        assert invoice.series_number == 'draft-id:%d' % invoice.pk
开发者ID:PressLabs,项目名称:silver,代码行数:10,代码来源:test_invoice.py


示例19: test_edit_invoice_in_issued_state

    def test_edit_invoice_in_issued_state(self):
        invoice = InvoiceFactory.create()
        invoice.issue()
        invoice.save()

        url = reverse('invoice-detail', kwargs={'pk': 1})
        data = {"description": "New Page views"}
        response = self.client.patch(url, data=json.dumps(data),
                                     content_type='application/json')

        assert response.status_code == status.HTTP_400_BAD_REQUEST
        assert response.data == {'non_field_errors': ['You cannot edit the document once it is in issued state.']}
开发者ID:MaxMorais,项目名称:silver,代码行数:12,代码来源:test_invoice.py


示例20: test_invoice_overdue_since_last_month_queryset

    def test_invoice_overdue_since_last_month_queryset(self):
        invoices = InvoiceFactory.create_batch(3)

        invoices[0].due_date = date.today().replace(day=1)
        invoices[0].issue()

        invoices[1].due_date = date.today() - timedelta(days=31)
        invoices[1].issue()

        queryset = Invoice.objects.overdue_since_last_month()

        assert queryset.count() == 1
        assert invoices[1] in queryset
开发者ID:PressLabs,项目名称:silver,代码行数:13,代码来源:test_invoice.py



注:本文中的silver.tests.factories.InvoiceFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python factories.ProformaFactory类代码示例发布时间:2022-05-27
下一篇:
Python factories.CustomerFactory类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap