-
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.
Changed the test_run_import_bag so that it only uses the first 5 lines
of the csv when importing. However the "Nummeraanduiding" csv cannot be imported as it depends on all other csv files to be imported complete. This is what makes the tests real slow. Updated the docker-compose to use healthchecks instead of the wait-for-it.sh file. Removed VCR package as it is not used. Updated the Makefile as it is no longer needed to have 2 test commands.
- Loading branch information
Showing
7 changed files
with
88 additions
and
71 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
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
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
64 changes: 49 additions & 15 deletions
64
src/importer/tests/test_run_import_bag.py
100644 → 100755
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,24 +1,58 @@ | ||
import logging | ||
import itertools | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
import vcr | ||
from django.core.management import call_command | ||
|
||
vcr_log = logging.getLogger("vcr") | ||
vcr_log.setLevel(logging.WARNING) | ||
|
||
my_vcr = vcr.VCR( | ||
serializer="yaml", | ||
cassette_library_dir="fixtures/cassettes", | ||
record_mode="new_episodes", | ||
match_on=["uri", "method"], | ||
from bag.bag_api import Zip | ||
from bag.models import ( | ||
Ligplaats, | ||
Nummeraanduiding, | ||
Openbareruimte, | ||
Pand, | ||
Standplaats, | ||
Verblijfsobject, | ||
Verblijfsobjectpandrelatie, | ||
) | ||
|
||
|
||
class TestBagImportBag: | ||
|
||
@my_vcr.use_cassette() | ||
@pytest.mark.django_db | ||
@pytest.mark.integration | ||
def test_import_bag_handle(self): | ||
call_command("run_import_bag") | ||
@pytest.mark.parametrize("model,endpoint", [ | ||
(Ligplaats, "bag_ligplaatsen.csv.zip"), | ||
(Openbareruimte, "bag_openbareruimtes.csv.zip"), | ||
(Standplaats, "bag_standplaatsen.csv.zip"), | ||
(Pand, "bag_panden.csv.zip"), | ||
(Verblijfsobject, "bag_verblijfsobjecten.csv.zip"), | ||
# (Nummeraanduiding, "bag_nummeraanduidingen.csv.zip"), # Skip this file as it depends on other CSV files being imported | ||
(Verblijfsobjectpandrelatie, "benkagg_bagpandbevatverblijfsobjecten.csv.zip"), | ||
]) | ||
def test_import_bag_handle(self, model, endpoint): | ||
""" | ||
This test verifies that the 'run_import_bag' command correctly handles | ||
the import process by patching the 'get_records' method of the 'Zip' class | ||
and the model_to_endpoint class variable. | ||
The patched method will return only the first five records from the original | ||
implementation, allowing for controlled testing of the import functionality. | ||
The patched class variable, using parameterize, makes sure that every csv is | ||
tested in a separate test. | ||
""" | ||
# Keep the original, unpatched, class method "get_records" | ||
original_get_records = Zip.get_records | ||
|
||
with (patch.object(Zip, "get_records", autospec=True) as mock_get_records, | ||
patch.object(Zip, "model_to_endpoint", new={model: endpoint})): | ||
|
||
def side_effect(self, bag_model): | ||
""" | ||
Call the original class methods get_records and only return the 5 first items as a generator | ||
""" | ||
original_result = original_get_records(self, bag_model=bag_model) | ||
return itertools.islice(original_result, 5) | ||
|
||
mock_get_records.side_effect = side_effect | ||
|
||
# Call the management command | ||
call_command("run_import_bag") |