-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
56 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
Empty file.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,16 +1,64 @@ | ||
from apps.homeownerassociation.models import HomeownerAssociation | ||
from django.core import management | ||
from django.test import TestCase | ||
from model_bakery import baker | ||
from unittest.mock import patch | ||
from apps.homeownerassociation.models import HomeownerAssociation | ||
|
||
|
||
class HomeownerAssociationModelTest(TestCase): | ||
|
||
@patch("apps.homeownerassociation.models.DsoClient") | ||
def test_get_or_create_hoa_by_bag_id_existing_hoa(self, MockDsoClient): | ||
# Mock the DsoClient and its methods | ||
mock_client = MockDsoClient.return_value | ||
mock_client.get_hoa_name_by_bag_id.return_value = "Test HOA" | ||
|
||
# Create an existing HOA | ||
existing_hoa = HomeownerAssociation.objects.create( | ||
name="Test HOA", build_year=2000, number_of_appartments=10 | ||
) | ||
|
||
# Call the method | ||
result = HomeownerAssociation.get_or_create_hoa_by_bag_id("some_bag_id") | ||
|
||
# Assert the existing HOA is returned | ||
self.assertEqual(result, existing_hoa) | ||
mock_client.get_hoa_name_by_bag_id.assert_called_once_with("some_bag_id") | ||
|
||
@patch("apps.homeownerassociation.models.DsoClient") | ||
def test_get_or_create_hoa_by_bag_id_new_hoa(self, MockDsoClient): | ||
# Mock the DsoClient and its methods | ||
mock_client = MockDsoClient.return_value | ||
mock_client.get_hoa_name_by_bag_id.return_value = "New HOA" | ||
mock_client.get_hoa_by_name.return_value = [ | ||
{"pndOorspronkelijkBouwjaar": 2010}, | ||
{"pndOorspronkelijkBouwjaar": 2010}, | ||
] | ||
|
||
# Call the method | ||
result = HomeownerAssociation.get_or_create_hoa_by_bag_id("some_bag_id") | ||
|
||
# Assert a new HOA is created | ||
self.assertIsInstance(result, HomeownerAssociation) | ||
self.assertEqual(result.name, "New HOA") | ||
self.assertEqual(result.build_year, 2010) | ||
self.assertEqual(result.number_of_appartments, 2) | ||
mock_client.get_hoa_name_by_bag_id.assert_called_once_with("some_bag_id") | ||
mock_client.get_hoa_by_name.assert_called_once_with("New HOA") | ||
|
||
@patch("apps.homeownerassociation.models.DsoClient") | ||
def test_get_or_create_hoa_by_bag_id_existing_hoa_no_new_hoa(self, MockDsoClient): | ||
# Mock the DsoClient and its methods | ||
mock_client = MockDsoClient.return_value | ||
mock_client.get_hoa_name_by_bag_id.return_value = "Test HOA" | ||
|
||
# Create an existing HOA | ||
existing_hoa = HomeownerAssociation.objects.create( | ||
name="Test HOA", build_year=2000, number_of_appartments=10 | ||
) | ||
|
||
class HomeownerAssociationTest(TestCase): | ||
def setUp(self): | ||
management.call_command("flush", verbosity=0, interactive=False) | ||
super().setUp() | ||
# Call the method | ||
result = HomeownerAssociation.get_or_create_hoa_by_bag_id("some_bag_id") | ||
|
||
def test_can_create_hoa(self): | ||
"""A case can be created""" | ||
self.assertEqual(HomeownerAssociation.objects.count(), 0) | ||
baker.make(HomeownerAssociation) | ||
self.assertEqual(HomeownerAssociation.objects.count(), 1) | ||
# Assert the existing HOA is returned | ||
self.assertEqual(result, existing_hoa) | ||
mock_client.get_hoa_name_by_bag_id.assert_called_once_with("some_bag_id") | ||
mock_client.get_hoa_by_name.assert_not_called() |
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