def test_add_multiple_invoice_entries(authenticated_api_client, invoice): url = reverse('invoice-entry-create', kwargs={'document_pk': invoice.pk}) request_data = { "description": "Page views", "unit_price": 10.0, "quantity": '20.0', } entries_count = 10 for cnt in range(entries_count): response = authenticated_api_client.post( url, data=json.dumps(request_data), content_type='application/json') assert response.status_code == status.HTTP_201_CREATED, response.data entry = DocumentEntry.objects.get(id=response.data['id']) document_entry_definition.check_response(entry, response.data, request_data) url = reverse('invoice-detail', kwargs={'pk': invoice.pk}) response = authenticated_api_client.get(url) invoice_entries = response.data.get('invoice_entries', None) assert len(invoice_entries) == entries_count
def test_add_multiple_proforma_entries(self): proforma = ProformaFactory.create() url = reverse('proforma-entry-create', kwargs={'document_pk': proforma.pk}) request_data = { "description": "Page views", "unit_price": 10.0, "quantity": 20 } entries_count = 5 for cnt in range(entries_count): response = self.client.post(url, data=json.dumps(request_data), content_type='application/json') assert response.status_code == status.HTTP_201_CREATED, response.data entry = proforma.entries.get(id=response.data['id']) document_entry_definition.check_response(entry, response.data, request_data) # check proforma entries in new request url = reverse('proforma-detail', kwargs={'pk': proforma.pk}) response = self.client.get(url) proforma_entries = response.data.get('proforma_entries', []) assert len(proforma_entries) == entries_count
def test_add_single_invoice_entry(authenticated_api_client, invoice): url = reverse('invoice-entry-create', kwargs={'document_pk': invoice.pk}) request_data = { "description": "Page views", "unit_price": 10.0, "quantity": 20 } response = authenticated_api_client.post(url, data=json.dumps(request_data), content_type='application/json') invoice = Invoice.objects.all()[0] total = Decimal(200.0) * Decimal(1 + invoice.sales_tax_percent / 100) assert response.status_code == status.HTTP_201_CREATED, response.data entry = DocumentEntry.objects.get(id=response.data['id']) document_entry_definition.check_response(entry, response.data, request_data) url = reverse('invoice-detail', kwargs={'pk': invoice.pk}) response = authenticated_api_client.get(url) invoice_entries = response.data['invoice_entries'] assert invoice_entries == [spec_document_entry(entry)]