Skip to content

Commit

Permalink
chore: Merge remote-tracking branch 'origin-https/main' into feat/pro…
Browse files Browse the repository at this point in the history
…ject-change-intervals-on-preset-change
  • Loading branch information
David Code Howard committed Dec 19, 2023
2 parents 83c83fb + ea8e9be commit a2a6a61
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 198 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
setup-python-dependencies: false
Expand All @@ -65,7 +65,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -78,6 +78,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
282 changes: 149 additions & 133 deletions requirements-dev.txt

Large diffs are not rendered by default.

52 changes: 28 additions & 24 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ aniso8601==9.0.1 \
--hash=sha256:1d2b7ef82963909e93c4f24ce48d4de9e66009a21bf1c1e1c85bdd0812fe412f \
--hash=sha256:72e3117667eedf66951bb2d93f4296a56b94b078a8a95905a052611fb3f1b973
# via graphene
anyio==4.1.0 \
--hash=sha256:56a415fbc462291813a94528a779597226619c8e78af7de0507333f700011e5f \
--hash=sha256:5a0bec7085176715be77df87fc66d6c9d70626bd752fcc85f57cdbee5b3760da
anyio==4.2.0 \
--hash=sha256:745843b39e829e108e518c489b31dc757de7d2131d53fac32bd8df268227bfee \
--hash=sha256:e1875bb4b4e2de1669f4bc7869b6d3f54231cdced71605e6e64c9be77e3be50f
# via httpx
asgiref==3.7.2 \
--hash=sha256:89b2ef2247e3b562a16eef663bc0e2e703ec6468e2fa8a5cd61cd449786d4f6e \
Expand All @@ -28,15 +28,15 @@ attrs==23.1.0 \
# cattrs
# ddtrace
# fiona
boto3==1.33.13 \
--hash=sha256:0e966b8a475ecb06cc0846304454b8da2473d4c8198a45dfb2c5304871986883 \
--hash=sha256:5f278b95fb2b32f3d09d950759a05664357ba35d81107bab1537c4ddd212cd8c
boto3==1.34.2 \
--hash=sha256:970fd9f9f522eb48f3cd5574e927b369279ebf5bcf0f2fae5ed9cc6306e58558 \
--hash=sha256:aad3f305fe3cd4f2bba545c9580cd460c366af56a8aabb6094528dd32317f8d2
# via
# -r requirements/base.in
# django-ses
botocore==1.33.13 \
--hash=sha256:aeadccf4b7c674c7d47e713ef34671b834bc3e89723ef96d994409c9f54666e6 \
--hash=sha256:fb577f4cb175605527458b04571451db1bd1a2036976b626206036acd4496617
botocore==1.34.2 \
--hash=sha256:655b1ea2a5d7b989a0eb6006c16137f785bc7334f31378115668c4be5d4b00eb \
--hash=sha256:8a9f4ad438ba814b9b7a22b24de3004f8aa232e7ae86e0087aea4d7792dc3a2a
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -351,9 +351,9 @@ django-filter==23.5 \
--hash=sha256:67583aa43b91fe8c49f74a832d95f4d8442be628fd4c6d65e9f811f5153a4e5c \
--hash=sha256:99122a201d83860aef4fe77758b69dda913e874cc5e0eaa50a86b0b18d708400
# via -r requirements/base.in
django-ipware==5.0.2 \
--hash=sha256:838b7aede77734603bd32ebd08ad7957304266580b646f8cbe982c4833b71c84 \
--hash=sha256:ab3ab7645e674df682c1146a5bddfa5151b1b7be7be9210872c3156bd836aad4
django-ipware==6.0.3 \
--hash=sha256:0f682dd4f3afef7909bb3dd396949c355982539bd4392d4e9df0b0b31604484d \
--hash=sha256:e54b6050af037406f05327890e742f99451dce96951223dea9cdd824e95859b6
# via django-structlog
django-naomi==0.8 \
--hash=sha256:145b7bd54443a7062cc2b48c5572c526641c01233f697a7e8be96e1c11a082da \
Expand All @@ -375,9 +375,9 @@ django-storages==1.14.2 \
--hash=sha256:1db759346b52ada6c2efd9f23d8241ecf518813eb31db9e2589207174f58f6ad \
--hash=sha256:51b36af28cc5813b98d5f3dfe7459af638d84428c8df4a03990c7d74d1bea4e5
# via -r requirements/base.in
django-structlog==6.0.1 \
--hash=sha256:75ec2385b817d10fffaccc4f4280193ae364b6839f4dda1f6639b3f0c13435ea \
--hash=sha256:ce52d54b952a7a56c185141409f618e0aa6775653e4c947213bca3e7911dd5f0
django-structlog==7.0.0 \
--hash=sha256:14c393d35224c1ce5e9d5890a177067afbb9be089bb053e5d3c9b970b071900a \
--hash=sha256:64ad349b17089799f96ed2ac3cf44a045105e8e1453e7113485f9e0c6d8af7b8
# via -r requirements/base.in
envier==0.5.0 \
--hash=sha256:5fed6099ee5d7ad4cf664f8bb99d1281d4ab5fadeec8f40ba9458610938293be \
Expand Down Expand Up @@ -501,9 +501,9 @@ openpyxl==3.1.2 \
--hash=sha256:a6f5977418eff3b2d5500d54d9db50c8277a368436f4e4f8ddb1be3422870184 \
--hash=sha256:f91456ead12ab3c6c2e9491cf33ba6d08357d802192379bb482f1033ade496f5
# via -r requirements/base.in
opentelemetry-api==1.21.0 \
--hash=sha256:4bb86b28627b7e41098f0e93280fe4892a1abed1b79a19aec6f928f39b17dffb \
--hash=sha256:d6185fd5043e000075d921822fd2d26b953eba8ca21b1e2fa360dd46a7686316
opentelemetry-api==1.22.0 \
--hash=sha256:15ae4ca925ecf9cfdfb7a709250846fbb08072260fca08ade78056c502b86bed \
--hash=sha256:43621514301a7e9f5d06dd8013a1b450f30c2e9372b8e30aaeb4562abf2ce034
# via ddtrace
packaging==23.2 \
--hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \
Expand Down Expand Up @@ -621,6 +621,10 @@ python-dateutil==2.8.2 \
# via
# botocore
# pandas
python-ipware==2.0.1 \
--hash=sha256:1992920ef553165dfa35e6ea5a90762f64f3b943cc22ee6b4ec02e2c86d31178 \
--hash=sha256:9ba4805152ebb85ad5b53797185cd1ce6231e1db60155834f326c8cd61e8af34
# via django-ipware
python-magic==0.4.27 \
--hash=sha256:c1ba14b08e4a5f5c31a302b7721239695b2f0f058d125bd5ce1ee36b9d9d3c3b \
--hash=sha256:c212960ad306f700aa0d01e5d7a325d20548ff97eb9920dcd29513174f0294d3
Expand All @@ -639,13 +643,13 @@ rules==3.3 \
--hash=sha256:12c8bbab5f54560e68528fcca7abc0e162c35ac882e3cc0daed40ac49c963070 \
--hash=sha256:bf7bea8b724b73c36a622714c1b3557620c187a2ee05321a2ac8ab7472dc4464
# via -r requirements/base.in
s3transfer==0.8.2 \
--hash=sha256:368ac6876a9e9ed91f6bc86581e319be08188dc60d50e0d56308ed5765446283 \
--hash=sha256:c9e56cbe88b28d8e197cf841f1f0c130f246595e77ae5b5a05b69fe7cb83de76
s3transfer==0.9.0 \
--hash=sha256:01d4d2c35a016db8cb14f9a4d5e84c1f8c96e7ffc211422555eed45c11fa7eb1 \
--hash=sha256:9e1b186ec8bb5907a1e82b51237091889a9973a2bb799a924bcd9f301ff79d3d
# via boto3
sentry-sdk[django]==1.39.0 \
--hash=sha256:67f62238af273eebd6432f85116dc6cd5422d4bc02df886514e8139e755f48e4 \
--hash=sha256:9d3644b7c36a2c290f0d3275cba250202773f37545ef9097c8bcf561c6f5cdea
sentry-sdk[django]==1.39.1 \
--hash=sha256:320a55cdf9da9097a0bead239c35b7e61f53660ef9878861824fd6d9b2eaf3b5 \
--hash=sha256:81b5b9ffdd1a374e9eb0c053b5d2012155db9cbe76393a8585677b753bd5fdc1
# via -r requirements/base.in
shapely==2.0.2 \
--hash=sha256:03e63a99dfe6bd3beb8d5f41ec2086585bb969991d603f9aeac335ad396a06d4 \
Expand Down
6 changes: 2 additions & 4 deletions terraso_backend/apps/core/gis/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import json
import os
import shutil
import uuid
import zipfile

Expand Down Expand Up @@ -157,10 +158,7 @@ def parse_shapefile(file):
gdf_transformed = gdf.to_crs(crs=DEFAULT_CRS)

# Delete extracted files
os.remove(os.path.join(tmp_folder, shp_filenames[0]))
os.remove(os.path.join(tmp_folder, shx_filenames[0]))
os.remove(os.path.join(tmp_folder, prj_filenames[0]))
os.rmdir(tmp_folder)
shutil.rmtree(tmp_folder)

return json.loads(gdf_transformed.to_json())

Expand Down
49 changes: 15 additions & 34 deletions terraso_backend/tests/core/gis/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
import json
import os
import tempfile
import zipfile
from importlib import resources

import geopandas as gpd
import pytest

from apps.core.gis.parsers import parse_file_to_geojson
from apps.core.gis.utils import DEFAULT_CRS

KML_TEST_FILES = [
("resources/gis/kml_sample_1.kml", "resources/gis/kml_sample_1_geojson.json"),
("resources/gis/kml_sample_2.kml", "resources/gis/kml_sample_2_geojson.json"),
("resources/gis/kml_sample_3.kml", "resources/gis/kml_sample_3_geojson.json"),
]
SHAPEFILE_TEST_FILES = [
("resources/gis/shapefile_sample_1.zip", "resources/gis/shapefile_sample_1_geojson.json"),
("resources/gis/shapefile_sample_2.zip", "resources/gis/shapefile_sample_2_geojson.json"),
]

GPX_CONTENT = """<?xml version="1.0" standalone="yes"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1"
Expand Down Expand Up @@ -188,41 +189,21 @@
}


@pytest.fixture
def shapefile_zip(request):
shp, shx, prj = request.param
zip_file = tempfile.NamedTemporaryFile(suffix=".zip")
return zip_file


@pytest.mark.parametrize(
"shapefile_zip",
[
(b"<shapefile component 1>", b"<shapefile component 2>", b"<shapefile component 3>"),
(b"<shapefile component 4>", b"<shapefile component 5>", b"<shapefile component 6>"),
],
indirect=True,
"file_path_expected",
SHAPEFILE_TEST_FILES,
)
def test_parse_shapefile(shapefile_zip):
# Create a GeoDataFrame with a single point
gdf = gpd.GeoDataFrame({"geometry": gpd.points_from_xy([0], [0])}, crs=DEFAULT_CRS)

# Convert the GeoDataFrame to a Shapefile
with tempfile.TemporaryDirectory() as tmpdir:
shapefile_path = os.path.join(tmpdir, "test.shp")
gdf.to_file(shapefile_path)

# Zip the Shapefile components
with zipfile.ZipFile(shapefile_zip.name, "w") as zf:
for component in ["shp", "shx", "prj"]:
zf.write(os.path.join(tmpdir, f"test.{component}"), f"test.{component}")
def test_parse_shapefile(file_path_expected):
file_path = file_path_expected[0]
with open(resources.files("tests").joinpath(file_path), "rb") as file:
shapefile_json = parse_file_to_geojson(file)

with open(shapefile_zip.name, "rb") as file:
shapefile_json = parse_file_to_geojson(file)
expected_file_path = file_path_expected[1]
with open(resources.files("tests").joinpath(expected_file_path), "rb") as file:
expected_json = json.load(file)

# Verify that the parsed Shapefile is equivalent to the original GeoDataFrame
gdf_json = json.loads(gdf.to_json())
assert shapefile_json == gdf_json
print(f"shapefile_json: {shapefile_json}")
assert json.dumps(shapefile_json) == json.dumps(expected_json)


@pytest.mark.parametrize(
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type":"FeatureCollection",
"features":[
{
"id":"0",
"type":"Feature",
"properties":{

},
"geometry":{
"type":"Point",
"coordinates":[
-78.48247445411837,
-0.16708426936664011
]
}
}
],
"crs":{
"type":"name",
"properties":{
"name":"urn:ogc:def:crs:OGC::CRS84"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type":"FeatureCollection",
"features":[
{
"id":"0",
"type":"Feature",
"properties":{

},
"geometry":{
"type":"Point",
"coordinates":[
-78.48247445411837,
-0.16708426936664011
]
}
}
],
"crs":{
"type":"name",
"properties":{
"name":"urn:ogc:def:crs:OGC::CRS84"
}
}
}

0 comments on commit a2a6a61

Please sign in to comment.