Skip to content

Commit

Permalink
chore(deps): refresh pip-compile outputs (#748)
Browse files Browse the repository at this point in the history
* chore(deps): refresh pip-compile outputs

* fix(boto): fixes aws mock methods

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: nazarfil <[email protected]>
  • Loading branch information
renovate[bot] and nazarfil authored Jul 19, 2024
1 parent ef8a4f4 commit e41e7d6
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 150 deletions.
5 changes: 2 additions & 3 deletions hexa/catalog/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.test import override_settings
from moto import mock_s3, mock_sts
from moto import mock_aws

from hexa.core.test import TestCase
from hexa.plugins.connector_s3.models import Bucket, BucketPermission
Expand Down Expand Up @@ -101,8 +101,7 @@ def setUpTestData(cls):
Membership.objects.create(team=cls.TEAM2, user=cls.USER_REGULAR_2)
cls.BUCKET = Bucket.objects.create(name="test-bucket")

@mock_s3
@mock_sts
@mock_aws
def test_permission_update(self):
# we start the test with one index: the bucket
self.assertEqual(Index.objects.count(), 1)
Expand Down
4 changes: 2 additions & 2 deletions hexa/files/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import botocore
from django.core.exceptions import ValidationError
from django.test import override_settings
from moto import mock_s3
from moto import mock_aws

from hexa.core.test import TestCase

Expand Down Expand Up @@ -32,7 +32,7 @@ def create_mock_client(*args, **kwargs):
self.addCleanup(patcher.stop)

if self.get_type() == "s3":
mock = mock_s3()
mock = mock_aws()

self.mock_backend = mock.start()
self.addCleanup(mock.stop)
Expand Down
8 changes: 3 additions & 5 deletions hexa/plugins/connector_accessmod/tests/schema/test_fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings
from django.test import override_settings
from moto import mock_s3, mock_sts
from moto import mock_aws

from hexa.core.test import GraphQLTestCase
from hexa.plugins.connector_accessmod.models import (
Expand Down Expand Up @@ -431,8 +431,7 @@ def test_accessmod_filesets_empty(self):
},
)

@mock_s3
@mock_sts
@mock_aws
def test_full_accessmod_upload_workflow(self):
self.client.force_login(self.USER_GREG)

Expand Down Expand Up @@ -853,8 +852,7 @@ def test_accessmod_fileset_roles(self):
r["data"]["accessmodFilesetRoles"][0],
)

@mock_s3
@mock_sts
@mock_aws
def test_prepare_fileset_visualization(self):
self.client.force_login(self.USER_GREG)

Expand Down
35 changes: 12 additions & 23 deletions hexa/plugins/connector_accessmod/tests/test_dataworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import boto3
import rasterio
from django.test import override_settings
from moto import mock_s3, mock_sts
from moto import mock_aws
from rasterio import DatasetReader

from hexa.core.test import TestCase
Expand Down Expand Up @@ -177,17 +177,15 @@ def setUpTestData(cls):
# S3 setup
cls.BUCKET = Bucket.objects.create(name="test-bucket")

@mock_s3
@mock_sts
@mock_aws
def test_validate_no_file(self):
validate_fileset_job(
None, MockJob(args={"fileset_id": str(self.dem_empty_fs.id)})
)
self.dem_empty_fs.refresh_from_db()
self.assertEqual(self.dem_empty_fs.status, FilesetStatus.INVALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_dem(self):
dem_file = os.path.dirname(__file__) + "/data/dem.tif"
dem_data = open(dem_file, "rb").read()
Expand Down Expand Up @@ -216,8 +214,7 @@ def test_validate_dem(self):
)
self.assertEqual(self.dem_fs.status, FilesetStatus.VALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_dem_wrong(self):
dem_file = os.path.dirname(__file__) + "/data/dem_invalid.tif"
dem_data = open(dem_file, "rb").read()
Expand All @@ -235,8 +232,7 @@ def test_validate_dem_wrong(self):
)
self.assertEqual(self.dem_fs.status, FilesetStatus.INVALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_facilities(self):
facilities_file = os.path.dirname(__file__) + "/data/facilities.gpkg"
facilities_data = open(facilities_file, "rb").read()
Expand All @@ -257,8 +253,7 @@ def test_validate_facilities(self):
)
self.assertEqual(self.facilities_fs.status, FilesetStatus.VALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_water(self):
water_file = os.path.dirname(__file__) + "/data/water.gpkg"
water_data = open(water_file, "rb").read()
Expand All @@ -277,8 +272,7 @@ def test_validate_water(self):
self.assertEqual(self.water_fs.metadata, {"length": 3})
self.assertEqual(self.water_fs.status, FilesetStatus.VALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_transport(self):
transport_file = os.path.dirname(__file__) + "/data/transport.gpkg"
transport_data = open(transport_file, "rb").read()
Expand Down Expand Up @@ -311,8 +305,7 @@ def test_validate_transport(self):
)
self.assertEqual(self.transport_fs.status, FilesetStatus.VALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_landcover(self):
landcover_file = os.path.dirname(__file__) + "/data/landcover.tif"
landcover_data = open(landcover_file, "rb").read()
Expand All @@ -339,8 +332,7 @@ def test_validate_landcover(self):
)
self.assertEqual(self.landcover_fs.status, FilesetStatus.VALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_stack(self):
stack_file = os.path.dirname(__file__) + "/data/stack.tif"
stack_data = open(stack_file, "rb").read()
Expand All @@ -365,8 +357,7 @@ def test_validate_stack(self):
)
self.assertEqual(self.stack_fs.status, FilesetStatus.VALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_travel_times(self):
travel_times_file = os.path.dirname(__file__) + "/data/travel.tif"
travel_times_data = open(travel_times_file, "rb").read()
Expand Down Expand Up @@ -400,8 +391,7 @@ def test_validate_travel_times(self):
)
self.assertEqual(self.travel_times_fs.status, FilesetStatus.VALID)

@mock_s3
@mock_sts
@mock_aws
def test_validate_population(self):
population_file = os.path.dirname(__file__) + "/data/population.tif"
population_data = open(population_file, "rb").read()
Expand Down Expand Up @@ -515,8 +505,7 @@ def setUpTestData(cls):
stack_priorities=[1, 2],
)

@mock_s3
@mock_sts
@mock_aws
def test_update_analysis_status(self):
landcover_file = os.path.dirname(__file__) + "/data/landcover.tif"
landcover_data = open(landcover_file, "rb").read()
Expand Down
18 changes: 7 additions & 11 deletions hexa/plugins/connector_s3/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import boto3
from django.test import override_settings
from moto import mock_iam, mock_s3, mock_sts
from moto import mock_aws

from hexa.core.test import TestCase
from hexa.plugins.connector_s3.api import (
Expand All @@ -25,8 +25,7 @@ class ApiTest(TestCase):
def setUp(self):
self.bucket = Bucket.objects.create(name=self.bucket_name)

@mock_s3
@mock_sts
@mock_aws
def test_generate_download_url(self):
s3_client = boto3.client("s3", region_name="us-east-1")
s3_client.create_bucket(Bucket="test-bucket")
Expand All @@ -44,8 +43,7 @@ def test_generate_download_url(self):
str,
)

@mock_s3
@mock_sts
@mock_aws
def test_generate_upload_url(self):
s3_client = boto3.client("s3", region_name="us-east-1")
s3_client.create_bucket(Bucket="test-bucket")
Expand All @@ -57,22 +55,21 @@ def test_generate_upload_url(self):
str,
)

@mock_sts
@mock_aws
def test_generate_sts_app_s3_credentials(self):
credentials = generate_sts_app_s3_credentials()
self.assertIsInstance(credentials, dict)
for key in ["AccessKeyId", "SecretAccessKey", "SessionToken"]:
self.assertIsInstance(credentials[key], str)
self.assertGreater(len(credentials[key]), 0)

@mock_sts
@mock_aws
def test_generate_sts_app_s3_credentials_with_bucket(self):
bucket = Bucket.objects.create(name="hexa-test-bucket")
credentials = generate_sts_app_s3_credentials(bucket=bucket)
self.assertIsInstance(credentials, dict)

@mock_iam
@mock_sts
@mock_aws
@patch("hexa.plugins.connector_s3.api.sleep", return_value=None)
def test_generate_sts_app_team_credentials(self, _):
bucket = Bucket.objects.create(name="hexa-test-bucket")
Expand All @@ -87,8 +84,7 @@ def test_generate_sts_app_team_credentials(self, _):
self.assertIsInstance(credentials[key], str)
self.assertGreater(len(credentials[key]), 0)

@mock_iam
@mock_sts
@mock_aws
@patch("hexa.plugins.connector_s3.api.sleep", return_value=None)
def test_generate_sts_app_team_credentials_long_ident(self, _):
bucket = Bucket.objects.create(name="hexa-test-bucket")
Expand Down
17 changes: 6 additions & 11 deletions hexa/plugins/connector_s3/tests/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import boto3
from django.test import override_settings
from moto import mock_iam, mock_sts
from moto import mock_aws

from hexa.core.test import TestCase
from hexa.notebooks.credentials import NotebooksCredentials
Expand Down Expand Up @@ -83,8 +83,7 @@ def setUpTestData(cls):
bucket=b2, team=cls.TEAM_SECRET, mode=PermissionMode.VIEWER
)

@mock_iam
@mock_sts
@mock_aws
@patch("hexa.plugins.connector_s3.api.sleep", return_value=None)
def test_credentials(self, _):
"""John is a regular user, should have access to 2 buckets"""
Expand Down Expand Up @@ -142,8 +141,7 @@ def test_credentials(self, _):
self.assertEqual(1, len(role_policies_data["PolicyNames"]))
self.assertEqual("s3-access", role_policies_data["PolicyNames"][0])

@mock_iam
@mock_sts
@mock_aws
@patch("hexa.plugins.connector_s3.api.sleep", return_value=None)
def test_credentials_superuser(self, _):
"""Jane is a superuser, should have access to 3 buckets"""
Expand Down Expand Up @@ -177,8 +175,7 @@ def setUpTestData(cls):
cls.CREDENTIALS = _get_app_s3_credentials()
cls.BUCKET = Bucket.objects.create(name="hexa-test-bucket-1")

@mock_iam
@mock_sts
@mock_aws
@patch("hexa.plugins.connector_s3.api.sleep", return_value=None)
def test_new_role(self, _):
iam_client = boto3.client(
Expand Down Expand Up @@ -270,8 +267,7 @@ def test_new_role(self, _):
credentials.env,
)

@mock_iam
@mock_sts
@mock_aws
@patch("hexa.plugins.connector_s3.api.sleep", return_value=None)
def test_existing_role(self, _):
"""
Expand Down Expand Up @@ -337,8 +333,7 @@ def test_existing_role(self, _):
parse_arn(response["Arn"])["resource"].split("/")[0], expected_role_name
)

@mock_iam
@mock_sts
@mock_aws
@patch("hexa.plugins.connector_s3.api.sleep", return_value=None)
def test_slug(self, _):
DAGAuthorizedDatasource.objects.create(
Expand Down
8 changes: 3 additions & 5 deletions hexa/plugins/connector_s3/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import boto3
from django.core.exceptions import ValidationError
from django.test import override_settings
from moto import mock_s3, mock_sts
from moto import mock_aws

from hexa.catalog.models import Index
from hexa.core.test import TestCase
Expand Down Expand Up @@ -153,17 +153,15 @@ def test_bucket_delete(self):
bucket.delete()
self.assertEqual(0, Index.objects.filter(object_id=bucket_id).count())

@mock_s3
@mock_sts
@mock_aws
def test_bucket_clean_ok(self):
s3_client = boto3.client("s3", region_name="us-east-1")
s3_client.create_bucket(Bucket="some-bucket")
bucket = Bucket.objects.create(name="some-bucket")

self.assertIsNone(bucket.clean())

@mock_s3
@mock_sts
@mock_aws
def test_bucket_clean_ko(self):
s3_client = boto3.client("s3", region_name="us-east-1")
s3_client.create_bucket(Bucket="some-bucket")
Expand Down
Loading

0 comments on commit e41e7d6

Please sign in to comment.