Skip to content

Commit

Permalink
Fix test_permissions_manager_init_user_not_found
Browse files Browse the repository at this point in the history
  • Loading branch information
maxachis committed Dec 11, 2024
1 parent 323fdcc commit 6e674e9
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 105 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flask_cors import CORS

from middleware.util import get_env_variable
from resources.Batch import namespace_batch
from resources.Batch import namespace_bulk
from resources.Callback import namespace_auth
from resources.DataRequests import namespace_data_requests
from resources.GithubDataRequests import namespace_github
Expand Down Expand Up @@ -66,7 +66,7 @@
namespace_notifications,
namespace_map,
namespace_signup,
namespace_batch,
namespace_bulk,
namespace_match,
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
setup_dto_class,
)

from middleware.schema_and_dto_logic.primary_resource_dtos.batch_dtos import (
BatchRequestDTO,
from middleware.schema_and_dto_logic.primary_resource_dtos.bulk_dtos import (
BulkRequestDTO,
)
from csv import DictReader

Expand Down Expand Up @@ -65,7 +65,7 @@ def _abort_if_csv(file):
)


class BatchRequestManager:
class BulkRequestManager:

Check warning on line 68 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L68 <101>

Missing docstring in public class
Raw output
./middleware/primary_resource_logic/bulk_logic.py:68:1: D101 Missing docstring in public class

def __init__(self):
self.requests = []
Expand All @@ -92,7 +92,7 @@ def all_requests_errored_out(self):
return len(self.get_requests_without_error()) == 0


class BatchRowProcessor:
class BulkRowProcessor:

Check warning on line 95 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L95 <101>

Missing docstring in public class
Raw output
./middleware/primary_resource_logic/bulk_logic.py:95:1: D101 Missing docstring in public class

def __init__(self, raw_row: dict, request_id: int):
self.raw_row = raw_row
Expand Down Expand Up @@ -139,7 +139,7 @@ def create_completed_request(self, inner_dto):
)


class AgenciesPostBRP(BatchRowProcessor):
class AgenciesPostBRP(BulkRowProcessor):

Check warning on line 142 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L142 <101>

Missing docstring in public class
Raw output
./middleware/primary_resource_logic/bulk_logic.py:142:1: D101 Missing docstring in public class

def create_completed_request(self, inner_dto):
return AgencyPostRequestInfo(
Expand All @@ -148,10 +148,10 @@ def create_completed_request(self, inner_dto):


@dataclass
class BatchConfig:
dto: BatchRequestDTO
class BulkConfig:

Check warning on line 151 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L151 <101>

Missing docstring in public class
Raw output
./middleware/primary_resource_logic/bulk_logic.py:151:1: D101 Missing docstring in public class
dto: BulkRequestDTO
handler: PostPutHandler
brp_class: type[BatchRowProcessor]
brp_class: type[BulkRowProcessor]
schema: Schema


Expand All @@ -162,32 +162,32 @@ def listify_strings(raw_rows: list[dict]):
raw_row[k] = v.split(",")


def run_batch(
batch_config: BatchConfig,
def run_bulk(

Check warning on line 165 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L165 <103>

Missing docstring in public function
Raw output
./middleware/primary_resource_logic/bulk_logic.py:165:1: D103 Missing docstring in public function
bulk_config: BulkConfig,
):
unflattener = SchemaUnflattener(
flat_schema_class=batch_config.dto.csv_schema.__class__
flat_schema_class=bulk_config.dto.csv_schema.__class__
)
raw_rows = _get_raw_rows_from_csv(file=batch_config.dto.file)
raw_rows = _get_raw_rows_from_csv(file=bulk_config.dto.file)
listify_strings(raw_rows)
schema = batch_config.schema
brm = BatchRequestManager()
schema = bulk_config.schema
brm = BulkRequestManager()
for idx, raw_row in enumerate(raw_rows):
brp = batch_config.brp_class(raw_row=raw_row, request_id=idx)
brp = bulk_config.brp_class(raw_row=raw_row, request_id=idx)
brp.process(
unflattener=unflattener,
inner_dto_class=batch_config.dto.inner_dto_class,
inner_dto_class=bulk_config.dto.inner_dto_class,
schema=schema,
)
brm.add_request(request=brp.request)

handler = batch_config.handler
handler = bulk_config.handler
handler.mass_execute(requests=brm.get_requests_without_error())
return brm


def manage_response(
brm: BatchRequestManager, resource_name: str, verb: str, include_ids: bool = True
brm: BulkRequestManager, resource_name: str, verb: str, include_ids: bool = True
):
errors = brm.get_error_dict()
if brm.all_requests_errored_out():
Expand Down Expand Up @@ -216,9 +216,9 @@ def manage_response(
)


def batch_post_agencies(db_client: DatabaseClient, dto: BatchRequestDTO):
brm = run_batch(
batch_config=BatchConfig(
def bulk_post_agencies(db_client: DatabaseClient, dto: BulkRequestDTO):

Check warning on line 219 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L219 <103>

Missing docstring in public function
Raw output
./middleware/primary_resource_logic/bulk_logic.py:219:1: D103 Missing docstring in public function

Check warning on line 219 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L219 <100>

Unused argument 'db_client'
Raw output
./middleware/primary_resource_logic/bulk_logic.py:219:24: U100 Unused argument 'db_client'
brm = run_bulk(
bulk_config=BulkConfig(
dto=dto,
handler=AgencyPostHandler(),
brp_class=AgenciesPostBRP,
Expand All @@ -228,12 +228,12 @@ def batch_post_agencies(db_client: DatabaseClient, dto: BatchRequestDTO):
return manage_response(brm=brm, resource_name="agencies", verb="created")


def batch_put_agencies(db_client: DatabaseClient, dto: BatchRequestDTO):
brm = run_batch(
batch_config=BatchConfig(
def bulk_put_agencies(db_client: DatabaseClient, dto: BulkRequestDTO):

Check warning on line 231 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L231 <103>

Missing docstring in public function
Raw output
./middleware/primary_resource_logic/bulk_logic.py:231:1: D103 Missing docstring in public function

Check warning on line 231 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L231 <100>

Unused argument 'db_client'
Raw output
./middleware/primary_resource_logic/bulk_logic.py:231:23: U100 Unused argument 'db_client'
brm = run_bulk(
bulk_config=BulkConfig(
dto=dto,
handler=AgencyPutHandler(),
brp_class=BatchRowProcessor,
brp_class=BulkRowProcessor,
schema=dto.csv_schema.__class__(exclude=["file"]),
)
)
Expand All @@ -242,24 +242,24 @@ def batch_put_agencies(db_client: DatabaseClient, dto: BatchRequestDTO):
)


def batch_post_data_sources(db_client: DatabaseClient, dto: BatchRequestDTO):
brm = run_batch(
batch_config=BatchConfig(
def bulk_post_data_sources(db_client: DatabaseClient, dto: BulkRequestDTO):

Check warning on line 245 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L245 <103>

Missing docstring in public function
Raw output
./middleware/primary_resource_logic/bulk_logic.py:245:1: D103 Missing docstring in public function

Check warning on line 245 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L245 <100>

Unused argument 'db_client'
Raw output
./middleware/primary_resource_logic/bulk_logic.py:245:28: U100 Unused argument 'db_client'
brm = run_bulk(
bulk_config=BulkConfig(
dto=dto,
handler=DataSourcesPostHandler(),
brp_class=BatchRowProcessor,
brp_class=BulkRowProcessor,
schema=dto.csv_schema.__class__(exclude=["file"]),
)
)
return manage_response(brm=brm, resource_name="data sources", verb="created")


def batch_put_data_sources(db_client: DatabaseClient, dto: BatchRequestDTO):
brm = run_batch(
batch_config=BatchConfig(
def bulk_put_data_sources(db_client: DatabaseClient, dto: BulkRequestDTO):

Check warning on line 257 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L257 <103>

Missing docstring in public function
Raw output
./middleware/primary_resource_logic/bulk_logic.py:257:1: D103 Missing docstring in public function

Check warning on line 257 in middleware/primary_resource_logic/bulk_logic.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/primary_resource_logic/bulk_logic.py#L257 <100>

Unused argument 'db_client'
Raw output
./middleware/primary_resource_logic/bulk_logic.py:257:27: U100 Unused argument 'db_client'
brm = run_bulk(
bulk_config=BulkConfig(
dto=dto,
handler=DataSourcesPutHandler(),
brp_class=BatchRowProcessor,
brp_class=BulkRowProcessor,
schema=dto.csv_schema.__class__(exclude=["file"]),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from middleware.flask_response_manager import FlaskResponseManager
from middleware.schema_and_dto_logic.custom_types import SchemaTypes, DTOTypes
from middleware.schema_and_dto_logic.primary_resource_dtos.batch_dtos import (
BatchRequestDTO,
from middleware.schema_and_dto_logic.primary_resource_dtos.bulk_dtos import (
BulkRequestDTO,
)
from middleware.schema_and_dto_logic.util import (
_get_required_argument,
Expand Down Expand Up @@ -42,7 +42,7 @@ def populate_schema_with_request_content(
"""
# Get all declared fields from the schema
if load_file:
return BatchRequestDTO(
return BulkRequestDTO(
file=request.files.get("file"), csv_schema=schema, inner_dto_class=dto_class
)
fields = schema.fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@dataclass
class BatchRequestDTO:
class BulkRequestDTO:

Check warning on line 10 in middleware/schema_and_dto_logic/primary_resource_dtos/bulk_dtos.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] middleware/schema_and_dto_logic/primary_resource_dtos/bulk_dtos.py#L10 <101>

Missing docstring in public class
Raw output
./middleware/schema_and_dto_logic/primary_resource_dtos/bulk_dtos.py:10:1: D101 Missing docstring in public class
file: FileStorage
csv_schema: Schema
inner_dto_class: Any
52 changes: 26 additions & 26 deletions resources/Batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
AccessInfoPrimary,
)
from middleware.decorators import endpoint_info
from middleware.primary_resource_logic.batch_logic import (
batch_post_agencies,
batch_post_data_sources,
batch_put_agencies,
batch_put_data_sources,
from middleware.primary_resource_logic.bulk_logic import (
bulk_post_agencies,
bulk_post_data_sources,
bulk_put_agencies,
bulk_put_data_sources,
)
from resources.PsycopgResource import PsycopgResource
from resources.endpoint_schema_config import SchemaConfigs
from resources.resource_helpers import ResponseInfo
from utilities.namespace import create_namespace, AppNamespaces

namespace_batch = create_namespace(AppNamespaces.BATCH)
namespace_bulk = create_namespace(AppNamespaces.BULK)


def add_csv_description(initial_description: str) -> str:
Expand All @@ -28,13 +28,13 @@ def add_csv_description(initial_description: str) -> str:
)


@namespace_batch.route("/agencies")
class AgenciesBatch(PsycopgResource):
@namespace_bulk.route("/agencies")
class AgenciesBulk(PsycopgResource):

Check warning on line 32 in resources/Batch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] resources/Batch.py#L32 <101>

Missing docstring in public class
Raw output
./resources/Batch.py:32:1: D101 Missing docstring in public class

@endpoint_info(
namespace=namespace_batch,
namespace=namespace_bulk,
auth_info=STANDARD_JWT_AUTH_INFO,
schema_config=SchemaConfigs.BATCH_AGENCIES_POST,
schema_config=SchemaConfigs.BULK_AGENCIES_POST,
description=add_csv_description(
initial_description="Adds multiple agencies from a CSV file."
),
Expand All @@ -44,14 +44,14 @@ class AgenciesBatch(PsycopgResource):
)
def post(self, access_info: AccessInfoPrimary) -> Response:
return self.run_endpoint(
wrapper_function=batch_post_agencies,
schema_populate_parameters=SchemaConfigs.BATCH_AGENCIES_POST.value.get_schema_populate_parameters(),
wrapper_function=bulk_post_agencies,
schema_populate_parameters=SchemaConfigs.BULK_AGENCIES_POST.value.get_schema_populate_parameters(),
)

@endpoint_info(
namespace=namespace_batch,
namespace=namespace_bulk,
auth_info=WRITE_ONLY_AUTH_INFO,
schema_config=SchemaConfigs.BATCH_AGENCIES_PUT,
schema_config=SchemaConfigs.BULK_AGENCIES_PUT,
description=add_csv_description(
initial_description="Updates multiple agencies from a CSV file."
),
Expand All @@ -61,18 +61,18 @@ def post(self, access_info: AccessInfoPrimary) -> Response:
)
def put(self, access_info: AccessInfoPrimary):
return self.run_endpoint(
wrapper_function=batch_put_agencies,
schema_populate_parameters=SchemaConfigs.BATCH_AGENCIES_PUT.value.get_schema_populate_parameters(),
wrapper_function=bulk_put_agencies,
schema_populate_parameters=SchemaConfigs.BULK_AGENCIES_PUT.value.get_schema_populate_parameters(),
)


@namespace_batch.route("/data-sources")
class DataSourcesBatch(PsycopgResource):
@namespace_bulk.route("/data-sources")
class DataSourcesBulk(PsycopgResource):

Check warning on line 70 in resources/Batch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] resources/Batch.py#L70 <101>

Missing docstring in public class
Raw output
./resources/Batch.py:70:1: D101 Missing docstring in public class

@endpoint_info(
namespace=namespace_batch,
namespace=namespace_bulk,
auth_info=STANDARD_JWT_AUTH_INFO,
schema_config=SchemaConfigs.BATCH_DATA_SOURCES_POST,
schema_config=SchemaConfigs.BULK_DATA_SOURCES_POST,
description=add_csv_description(
initial_description="Adds multiple data sources from a CSV file."
),
Expand All @@ -82,14 +82,14 @@ class DataSourcesBatch(PsycopgResource):
)
def post(self, access_info: AccessInfoPrimary):
return self.run_endpoint(
wrapper_function=batch_post_data_sources,
schema_populate_parameters=SchemaConfigs.BATCH_DATA_SOURCES_POST.value.get_schema_populate_parameters(),
wrapper_function=bulk_post_data_sources,
schema_populate_parameters=SchemaConfigs.BULK_DATA_SOURCES_POST.value.get_schema_populate_parameters(),
)

@endpoint_info(
namespace=namespace_batch,
namespace=namespace_bulk,
auth_info=WRITE_ONLY_AUTH_INFO,
schema_config=SchemaConfigs.BATCH_DATA_SOURCES_PUT,
schema_config=SchemaConfigs.BULK_DATA_SOURCES_PUT,
description=add_csv_description(
initial_description="Updates multiple data sources from a CSV file."
),
Expand All @@ -100,6 +100,6 @@ def post(self, access_info: AccessInfoPrimary):
def put(self, access_info: AccessInfoPrimary):

return self.run_endpoint(
wrapper_function=batch_put_data_sources,
schema_populate_parameters=SchemaConfigs.BATCH_DATA_SOURCES_PUT.value.get_schema_populate_parameters(),
wrapper_function=bulk_put_data_sources,
schema_populate_parameters=SchemaConfigs.BULK_DATA_SOURCES_PUT.value.get_schema_populate_parameters(),
)
14 changes: 7 additions & 7 deletions resources/endpoint_schema_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
PermissionsRequestDTO,
PermissionsGetRequestSchema,
)
from middleware.schema_and_dto_logic.primary_resource_dtos.batch_dtos import (
BatchRequestDTO,
from middleware.schema_and_dto_logic.primary_resource_dtos.bulk_dtos import (

Check warning on line 15 in resources/endpoint_schema_config.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] resources/endpoint_schema_config.py#L15 <401>

'middleware.schema_and_dto_logic.primary_resource_dtos.bulk_dtos.BulkRequestDTO' imported but unused
Raw output
./resources/endpoint_schema_config.py:15:1: F401 'middleware.schema_and_dto_logic.primary_resource_dtos.bulk_dtos.BulkRequestDTO' imported but unused
BulkRequestDTO,
)
from middleware.schema_and_dto_logic.primary_resource_dtos.match_dtos import AgencyMatchDTO
from middleware.schema_and_dto_logic.primary_resource_dtos.reset_token_dtos import (
Expand All @@ -23,7 +23,7 @@
ArchivesGetResponseSchema,
ArchivesPutRequestSchema,
)
from middleware.schema_and_dto_logic.primary_resource_schemas.batch_schemas import (
from middleware.schema_and_dto_logic.primary_resource_schemas.bulk_schemas import (

Check warning on line 26 in resources/endpoint_schema_config.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] resources/endpoint_schema_config.py#L26 <401>

'middleware.schema_and_dto_logic.primary_resource_schemas.bulk_schemas.BatchRequestSchema' imported but unused
Raw output
./resources/endpoint_schema_config.py:26:1: F401 'middleware.schema_and_dto_logic.primary_resource_schemas.bulk_schemas.BatchRequestSchema' imported but unused
BatchRequestSchema,
BatchPostResponseSchema,
BatchPutResponseSchema,
Expand Down Expand Up @@ -502,22 +502,22 @@ class SchemaConfigs(Enum):
# endregion

# region Batch
BATCH_DATA_SOURCES_POST = EndpointSchemaConfig(
BULK_DATA_SOURCES_POST = EndpointSchemaConfig(
input_schema=DataSourcesPostBatchRequestSchema(),
input_dto_class=DataSourcesPostDTO,
primary_output_schema=BatchPostResponseSchema(),
)
BATCH_DATA_SOURCES_PUT = EndpointSchemaConfig(
BULK_DATA_SOURCES_PUT = EndpointSchemaConfig(
input_schema=DataSourcesPutBatchRequestSchema(),
input_dto_class=DataSourcesPutDTO,
primary_output_schema=BatchPutResponseSchema(),
)
BATCH_AGENCIES_POST = EndpointSchemaConfig(
BULK_AGENCIES_POST = EndpointSchemaConfig(
input_schema=AgenciesPostBatchRequestSchema(),
input_dto_class=AgenciesPostDTO,
primary_output_schema=BatchPostResponseSchema(),
)
BATCH_AGENCIES_PUT = EndpointSchemaConfig(
BULK_AGENCIES_PUT = EndpointSchemaConfig(
input_schema=AgenciesPutBatchRequestSchema(),
input_dto_class=AgenciesPutDTO,
primary_output_schema=BatchPutResponseSchema(),
Expand Down
Loading

0 comments on commit 6e674e9

Please sign in to comment.