Skip to content

Commit ef8ee8d

Browse files
annashamraySonnyBA
authored andcommitted
♻️ [maykinmedia/open-api-framework#66] update old tests with new client
1 parent 339581e commit ef8ee8d

File tree

6 files changed

+15
-32
lines changed

6 files changed

+15
-32
lines changed

src/objects/conf/base.py

-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@
6666
# Relying Party name for WebAuthn (hardware tokens)
6767
TWO_FACTOR_WEBAUTHN_RP_NAME = "objects api"
6868

69-
70-
# VNG API Common
71-
CUSTOM_CLIENT_FETCHER = "objects.utils.client.get_client"
72-
7369
# settings for sending notifications
7470
NOTIFICATIONS_KANAAL = "objecten"
7571

src/objects/core/tests/factories.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,11 @@
66

77
import factory
88
from factory.fuzzy import BaseFuzzyAttribute
9-
from zgw_consumers.constants import APITypes, AuthTypes
10-
from zgw_consumers.models import Service
9+
from zgw_consumers.test.factories import ServiceFactory
1110

1211
from ..models import Object, ObjectRecord, ObjectType
1312

1413

15-
class ServiceFactory(factory.django.DjangoModelFactory):
16-
label = factory.Faker("word")
17-
api_root = factory.Faker("url")
18-
api_type = APITypes.orc
19-
auth_type = AuthTypes.no_auth
20-
21-
class Meta:
22-
model = Service
23-
24-
2514
class ObjectTypeFactory(factory.django.DjangoModelFactory):
2615
service = factory.SubFactory(ServiceFactory)
2716
uuid = factory.LazyFunction(uuid.uuid4)

src/objects/fixtures/demodata.json

+1
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@
805805
"pk": 1,
806806
"fields": {
807807
"label": "Objecttypen API",
808+
"slug": "objecttypen-api",
808809
"api_type": "orc",
809810
"api_root": "http://localhost:8001/api/v1/",
810811
"client_id": "",

src/objects/tests/commands/test_setup_configuration.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import requests_mock
99
from rest_framework import status
10+
from zgw_consumers.client import build_client
1011
from zgw_consumers.models import Service
1112

1213
from objects.config.demo import DemoUserStep
@@ -70,10 +71,13 @@ def test_setup_configuration(self, m):
7071
self.assertEqual(site.name, "Objects ACME")
7172

7273
with self.subTest("Objects can query Objecttypes API"):
73-
client = Service.get_client("https://objecttypes.example.com/api/v2/")
74+
client = build_client(
75+
Service.objects.get(api_root="https://objecttypes.example.com/api/v2/")
76+
)
77+
7478
self.assertIsNotNone(client)
7579

76-
client.list("objecttype")
80+
client.get("objecttypes")
7781

7882
list_call = m.last_request
7983
self.assertEqual(

src/objects/tests/v2/test_notifications_kanaal.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_kanaal_create_with_name(self, mock_get_client):
4747
Test is request to create kanaal is send with specified kanaal name
4848
"""
4949
client = mock_get_client.return_value
50-
client.list.return_value = []
50+
client.get.return_value = []
5151

5252
stdout = StringIO()
5353
call_command(
@@ -56,9 +56,9 @@ def test_kanaal_create_with_name(self, mock_get_client):
5656
stdout=stdout,
5757
)
5858

59-
client.create.assert_called_once_with(
59+
client.post.assert_called_once_with(
6060
"kanaal",
61-
{
61+
json={
6262
"naam": "kanaal_test",
6363
"documentatieLink": "https://example.com/ref/kanalen/#kanaal_test",
6464
"filters": [],
@@ -72,27 +72,27 @@ def test_kanaal_create_without_name(self, mock_get_client):
7272
Test is request to create kanaal is send with default kanaal name
7373
"""
7474
client = mock_get_client.return_value
75-
client.list.return_value = []
75+
client.get.return_value = []
7676

7777
stdout = StringIO()
7878
call_command(
7979
"register_kanalen",
8080
stdout=stdout,
8181
)
8282

83-
client.create.assert_has_calls(
83+
client.post.assert_has_calls(
8484
[
8585
call(
8686
"kanaal",
87-
{
87+
json={
8888
"naam": "kanaal_test",
8989
"documentatieLink": "https://example.com/ref/kanalen/#kanaal_test",
9090
"filters": [],
9191
},
9292
),
9393
call(
9494
"kanaal",
95-
{
95+
json={
9696
"naam": "objecten",
9797
"documentatieLink": "https://example.com/ref/kanalen/#objecten",
9898
"filters": ["object_type"],

src/objects/utils/client.py

-7
This file was deleted.

0 commit comments

Comments
 (0)