|
1 | 1 | import datetime |
| 2 | +import json |
2 | 3 | from unittest.mock import patch |
3 | 4 |
|
| 5 | +from django.contrib.auth import get_user_model |
4 | 6 | from django.http import FileResponse |
5 | 7 | from django.test import tag |
6 | | -from rest_framework.test import APIRequestFactory |
| 8 | +from django.urls import reverse |
| 9 | +from rest_framework.test import APIRequestFactory, force_authenticate |
7 | 10 |
|
8 | 11 | import geno.tests.data as geno_testdata |
9 | 12 | from finance.accounting import Account, AccountingManager, AccountKey |
10 | | -from geno.api_views import Akonto, QRBill |
| 13 | +from geno.api_views import Akonto, ContractViewSet, QRBill |
11 | 14 | from geno.billing import get_income_account, get_receivables_account |
12 | 15 | from geno.models import Contract, Invoice, InvoiceCategory |
13 | 16 |
|
@@ -319,3 +322,25 @@ def test_get_akonto_qrbill(self): |
319 | 322 | ], |
320 | 323 | ) |
321 | 324 | pdf_file.file_to_stream.close() |
| 325 | + |
| 326 | + |
| 327 | +class ContractViewSetTest(GenoAdminTestCase): |
| 328 | + @classmethod |
| 329 | + def setUpTestData(cls): |
| 330 | + super().setUpTestData() |
| 331 | + geno_testdata.create_contracts(cls) |
| 332 | + User = get_user_model() |
| 333 | + cls.user = User.objects.get(username="superuser") |
| 334 | + |
| 335 | + def test_subcontracts_are_excluded_in_api_view(self): |
| 336 | + Contract.objects.create( |
| 337 | + state="unterzeichnet", date=datetime.date(2020, 1, 1), main_contract=self.contracts[0] |
| 338 | + ) |
| 339 | + factory = APIRequestFactory() |
| 340 | + view = ContractViewSet.as_view({"get": "list"}) |
| 341 | + request = factory.get(reverse("contract-list")) |
| 342 | + force_authenticate(request, user=self.user) |
| 343 | + response = view(request) |
| 344 | + self.assertEqual(response.status_code, 200) |
| 345 | + data = json.loads(response.render().content) |
| 346 | + self.assertEqual(data["count"], 1) |
0 commit comments