Skip to content

Commit 5507b62

Browse files
committed
✅ [#469] Test queries
1 parent e2b8346 commit 5507b62

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.db import DEFAULT_DB_ALIAS, connections
2+
from django.test.utils import CaptureQueriesContext
3+
4+
5+
def executed_queries():
6+
conn = connections[DEFAULT_DB_ALIAS]
7+
8+
return CaptureQueriesContext(conn)

backend/src/openarchiefbeheer/zaken/tests/test_tasks.py

+44
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import date
22
from unittest.mock import patch
33

4+
from django.core.cache import cache
45
from django.test import TestCase, TransactionTestCase, tag
56
from django.utils.translation import gettext_lazy as _
67

@@ -13,6 +14,7 @@
1314

1415
from openarchiefbeheer.config.models import APIConfig
1516
from openarchiefbeheer.destruction.tests.factories import DestructionListItemFactory
17+
from openarchiefbeheer.utils.tests.get_queries import executed_queries
1618

1719
from ..models import Zaak
1820
from ..tasks import resync_zaken, retrieve_and_cache_zaken_from_openzaak
@@ -621,3 +623,45 @@ def test_resync_zaken_raises_error(self, m):
621623
_("Resyncing of the cases has failed with the following error: %(error)s")
622624
% {"error": "requests.exceptions.ConnectTimeout: Oh noes!\n"},
623625
)
626+
627+
628+
class RetrieveCachedZakenQueryTest(TestCase):
629+
def setUp(self):
630+
super().setUp()
631+
632+
self.addCleanup(cache.clear)
633+
634+
@Mocker()
635+
def test_queries_retrieve_zaken(self, m):
636+
ServiceFactory.create(
637+
api_type=APITypes.orc,
638+
api_root="https://selectielijst.openzaak.nl/api/v1/",
639+
)
640+
ServiceFactory.create(
641+
api_type=APITypes.zrc,
642+
api_root="http://zaken-api.nl/zaken/api/v1",
643+
)
644+
645+
m.get("http://zaken-api.nl/zaken/api/v1/zaken", json=PAGE_WITH_EXPAND)
646+
m.get(
647+
"https://selectielijst.openzaak.nl/api/v1/procestypen/e1b73b12-b2f6-4c4e-8929-94f84dd2a57d",
648+
json={
649+
"url": "https://selectielijst.openzaak.nl/api/v1/procestypen/e1b73b12-b2f6-4c4e-8929-94f84dd2a57d",
650+
"nummer": 1,
651+
},
652+
)
653+
654+
with executed_queries() as q:
655+
resync_zaken()
656+
657+
queries = q.captured_queries
658+
659+
self.assertEqual(
660+
1, len([q for q in queries if 'SELECT "zgw_consumers_service"' in q["sql"]])
661+
)
662+
self.assertEqual(
663+
1, len([q for q in queries if 'SELECT "config_apiconfig"' in q["sql"]])
664+
)
665+
self.assertEqual(
666+
1, len([q for q in queries if 'INSERT INTO "zaken_zaak"' in q["sql"]])
667+
)

0 commit comments

Comments
 (0)