Skip to content

Commit

Permalink
Test case for netCDF on S3
Browse files Browse the repository at this point in the history
  • Loading branch information
Belén Torrente committed Sep 13, 2024
1 parent e1458a0 commit f318648
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions data/config/datasets/adaguc.tests.s3file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration>

<Settings cache_age_volatileresources="60" cache_age_cacheableresources="7200" />

<Style name="testdata_style_manycontours">
<ContourLine width="2" linecolor="#0000EE" textcolor="#FFFFFF" textstrokecolor="#000000" textsize="20.0" textformatting="%2.2f" classes="0.15" dashing="21,7"/>
<ContourLine width="3" linecolor="#FF0000" textcolor="#808080" textstrokecolor="#FF0000" textsize="30.0" textformatting="%2.1f" classes="0.10"/>
<ContourLine width="5" linecolor="#00FF00" textcolor="#00FF00" textstrokecolor="#000000" textsize="40.0" textformatting="%2.2f" classes="0.20" dashing="5,5"/>
<RenderMethod>contour</RenderMethod>
</Style>

<!-- Layers -->

<Layer type="database">
<Name>dashed_contour_lines</Name>
<FilePath filter="">s3://adaguc-test-bucket/testdata.nc</FilePath>
<Title>Dashed contourlines</Title>
<Variable>testdata</Variable>
<Styles>testdata_style_manycontours</Styles>
</Layer>

<!-- End of configuration /-->
</Configuration>
32 changes: 32 additions & 0 deletions tests/AdagucTests/TestWMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import datetime
from adaguc.AdagucTestTools import AdagucTestTools
from lxml import etree, objectify
from moto import mock_aws
import boto3

ADAGUC_PATH = os.environ["ADAGUC_PATH"]

Expand Down Expand Up @@ -2475,3 +2477,33 @@ def test_WMSGetCapabilities_no_error_on_existing_dataset_misconfigured_layer(sel
)
)

@mock_aws
def test_WMSGetMap_S3(self):

# Set up mock S3 bucket and copy test NetCDF file
print("Current Working Directory:", os.getcwd())
s3 = boto3.client("s3", region_name="eu-west-1")
bucket_name = "adaguc-test-bucket"
file_key = "testdata.nc"
s3.create_bucket(
Bucket=bucket_name,
CreateBucketConfiguration={"LocationConstraint": "eu-west-1"})
with open("../data/datasets/testdata.nc", "rb") as data:
s3.upload_fileobj(data, bucket_name, file_key)
# Bucket URL for the file (referenced in the adaguc-tests.s3file.xml config file)
s3_url = f"s3://{bucket_name}/{file_key}"

# Set up Adaguc to
AdagucTestTools().cleanTempDir()
filename = "test_WMSGetMap_S3_testdatanc.png"
# pylint: disable=unused-variable
status, data, headers = AdagucTestTools().runADAGUCServer(
"DATASET=adaguc.tests.s3file&SERVICE=WMS&request=GetCapabilities",
env=self.env,
)
AdagucTestTools().writetofile(self.testresultspath + filename, data.getvalue())
self.assertEqual(status, 0)
self.assertEqual(
data.getvalue(),
AdagucTestTools().readfromfile(self.expectedoutputsspath + filename),
)

0 comments on commit f318648

Please sign in to comment.