本文整理汇总了Python中silver.tests.factories.InvoiceFactory类的典型用法代码示例。如果您正苦于以下问题:Python InvoiceFactory类的具体用法?Python InvoiceFactory怎么用?Python InvoiceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InvoiceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'),
}
示例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
示例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)
示例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.'}
示例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
示例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.'}
示例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)
示例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
示例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)
示例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
示例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
示例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.']
})
示例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)
示例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')
示例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())