Skip to content

Commit

Permalink
♻️ [maykinmedia/open-api-framework#66] update old tests with new client
Browse files Browse the repository at this point in the history
  • Loading branch information
annashamray committed Nov 25, 2024
1 parent 329cc59 commit ad08c38
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/objects/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
# Relying Party name for WebAuthn (hardware tokens)
TWO_FACTOR_WEBAUTHN_RP_NAME = "objects api"


# VNG API Common
CUSTOM_CLIENT_FETCHER = "objects.utils.client.get_client"

# settings for sending notifications
NOTIFICATIONS_KANAAL = "objecten"

Expand Down
13 changes: 1 addition & 12 deletions src/objects/core/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@

import factory
from factory.fuzzy import BaseFuzzyAttribute
from zgw_consumers.constants import APITypes, AuthTypes
from zgw_consumers.models import Service
from zgw_consumers.test.factories import ServiceFactory

from ..models import Object, ObjectRecord, ObjectType


class ServiceFactory(factory.django.DjangoModelFactory):
label = factory.Faker("word")
api_root = factory.Faker("url")
api_type = APITypes.orc
auth_type = AuthTypes.no_auth

class Meta:
model = Service


class ObjectTypeFactory(factory.django.DjangoModelFactory):
service = factory.SubFactory(ServiceFactory)
uuid = factory.LazyFunction(uuid.uuid4)
Expand Down
1 change: 1 addition & 0 deletions src/objects/fixtures/demodata.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@
"pk": 1,
"fields": {
"label": "Objecttypen API",
"slug": "objecttypen-api",
"api_type": "orc",
"api_root": "http://localhost:8001/api/v1/",
"client_id": "",
Expand Down
8 changes: 6 additions & 2 deletions src/objects/tests/commands/test_setup_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import requests_mock
from rest_framework import status
from zgw_consumers.client import build_client
from zgw_consumers.models import Service

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

with self.subTest("Objects can query Objecttypes API"):
client = Service.get_client("https://objecttypes.example.com/api/v2/")
client = build_client(
Service.objects.get(api_root="https://objecttypes.example.com/api/v2/")
)

self.assertIsNotNone(client)

client.list("objecttype")
client.get("objecttypes")

list_call = m.last_request
self.assertEqual(
Expand Down
14 changes: 7 additions & 7 deletions src/objects/tests/v2/test_notifications_kanaal.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_kanaal_create_with_name(self, mock_get_client):
Test is request to create kanaal is send with specified kanaal name
"""
client = mock_get_client.return_value
client.list.return_value = []
client.get.return_value = []

stdout = StringIO()
call_command(
Expand All @@ -56,9 +56,9 @@ def test_kanaal_create_with_name(self, mock_get_client):
stdout=stdout,
)

client.create.assert_called_once_with(
client.post.assert_called_once_with(
"kanaal",
{
json={
"naam": "kanaal_test",
"documentatieLink": "https://example.com/ref/kanalen/#kanaal_test",
"filters": [],
Expand All @@ -72,27 +72,27 @@ def test_kanaal_create_without_name(self, mock_get_client):
Test is request to create kanaal is send with default kanaal name
"""
client = mock_get_client.return_value
client.list.return_value = []
client.get.return_value = []

stdout = StringIO()
call_command(
"register_kanalen",
stdout=stdout,
)

client.create.assert_has_calls(
client.post.assert_has_calls(
[
call(
"kanaal",
{
json={
"naam": "kanaal_test",
"documentatieLink": "https://example.com/ref/kanalen/#kanaal_test",
"filters": [],
},
),
call(
"kanaal",
{
json={
"naam": "objecten",
"documentatieLink": "https://example.com/ref/kanalen/#objecten",
"filters": ["object_type"],
Expand Down
7 changes: 0 additions & 7 deletions src/objects/utils/client.py

This file was deleted.

0 comments on commit ad08c38

Please sign in to comment.