Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Farcy committed Aug 28, 2023
1 parent 1464bec commit 38ffeef
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion project/geosource/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ def test_postgis_source_creation_no_geom_field_good_geom(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertDictContainsSubset(self.source_example, response.json())

def test_wmts_source_creation(self):
@patch(
"project.geosource.serializers.requests.get",
retun_value={"status": status.HTTP_201_CREATED},
)
def test_wmts_source_creation(self, mocked_request_get):
wmts_source = {
"_type": "WMTSSource",
"name": "Test Source",
Expand Down
21 changes: 21 additions & 0 deletions project/geosource/tests/test_model_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ def test_valueerror_raised_in_extract_coordinate_create_report_if_none(
)
self.assertIsInstance(source.report, SourceReporting)

def test_coordinate_separator_exceptions(self, mocked_es_create, mocked_es_delete):
source = CSVSource.objects.create(
name="csv-source",
file=get_file("source.csv"),
geom_type=0,
id_field="identifier",
settings={
"coordinates_separator": "comma",
"coordinates_field_count": "xy",
},
)
with self.assertRaisesRegex(
CSVSourceException,
'Cannot split coordinate "69,420.42,069" with separator ","',
):
source._extract_coordinates(
["69,420.42,069", "identifier", "some value"],
[],
["0"],
)


@patch("elasticsearch.client.IndicesClient.create")
@patch("elasticsearch.client.IndicesClient.delete")
Expand Down
16 changes: 16 additions & 0 deletions project/geosource/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from rest_framework.exceptions import ValidationError

from project.geosource.models import CSVSource
from project.geosource.serializers import CSVSourceSerializer
Expand Down Expand Up @@ -156,3 +157,18 @@ def test_missing_lnglat_separator_and_field_info_raise_errors(self):
with self.assertRaises(KeyError):
serializer.is_valid()
self.assertEqual(len(serializer.errors), 3)

@patch(
"project.geosource.serializers.CSVSource._get_records",
side_effect=ValueError("ValueError mocked"),
)
def test_validate_fields_exceptions(self, get_record_mock):
data = {
"name": "soure-csv",
"file": get_file("source.csv"),
"_type": "CSVSource",
}
serializer = CSVSourceSerializer(data=data)

with self.assertRaises(ValidationError):
serializer._validate_field_infos(serializer.initial_data)

0 comments on commit 38ffeef

Please sign in to comment.