-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [#2149] Add/fix tests for new answer indicator mijn vragen
- Loading branch information
Showing
4 changed files
with
162 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import factory | ||
|
||
from open_inwoner.accounts.tests.factories import UserFactory | ||
|
||
|
||
class ContactFormSubjectFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = "openklant.ContactFormSubject" | ||
|
||
subject = factory.Faker("sentence") | ||
subject_code = factory.Faker("word") | ||
|
||
|
||
class KlantContactMomentLocalFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = "openklant.KlantContactMomentLocal" | ||
|
||
kcm_url = factory.Faker("url") | ||
user = factory.SubFactory(UserFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.test import TestCase | ||
|
||
import requests_mock | ||
|
||
from open_inwoner.openklant.models import KlantContactMomentLocal | ||
from open_inwoner.openklant.tests.data import MockAPIReadData | ||
from open_inwoner.openklant.wrap import ( | ||
fetch_klantcontactmomenten, | ||
get_local_kcm_mapping, | ||
) | ||
from open_inwoner.utils.test import ClearCachesMixin, DisableRequestLogMixin | ||
|
||
|
||
@requests_mock.Mocker() | ||
class HelpersTestCase(ClearCachesMixin, DisableRequestLogMixin, TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
super().setUpTestData() | ||
MockAPIReadData.setUpServices() | ||
|
||
def test_get_local_kcm_mapping(self, m): | ||
data = MockAPIReadData().install_mocks(m) | ||
|
||
kcms = fetch_klantcontactmomenten(user_bsn=data.user.bsn) | ||
|
||
with self.subTest("running the first time will create KlantContactMomentLocal"): | ||
mapping = get_local_kcm_mapping(kcms, data.user) | ||
|
||
self.assertEqual(KlantContactMomentLocal.objects.count(), 1) | ||
|
||
kcm_local = KlantContactMomentLocal.objects.get() | ||
|
||
self.assertEqual(mapping, {kcms[0].url: kcm_local}) | ||
self.assertEqual(kcm_local.user, data.user) | ||
self.assertEqual(kcm_local.kcm_url, kcms[0].url) | ||
self.assertEqual(kcm_local.is_seen, False) | ||
|
||
with self.subTest("running function again will ignore existing entries"): | ||
mapping = get_local_kcm_mapping(kcms, data.user) | ||
|
||
self.assertEqual(KlantContactMomentLocal.objects.count(), 1) | ||
self.assertEqual(mapping, {kcms[0].url: kcm_local}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters