Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix transaction unit tests #425

Merged
merged 9 commits into from
Sep 25, 2024
Merged

Conversation

stephenkilbourn
Copy link
Contributor

I've added a small change in the stac_api/runtime/tests/conftest.py. This gives a similar error on each of the attempts to POST: The error error:

>       response = self.api_client.post(
            collections_endpoint, json=self.invalid_stac_collection
        )
E       AttributeError: 'async_generator' object has no attribute 'post'

stac_api/runtime/tests/test_transactions.py:63: AttributeError

this got past the starlette error that we were seeing in develop:

self = <starlette.datastructures.State object at 0x10bf0b1f0>, key = 'get_connection'

    def __getattr__(self, key: typing.Any) -> typing.Any:
        try:
            return self._state[key]
        except KeyError:
            message = "'{}' object has no attribute '{}'"
>           raise AttributeError(message.format(self.__class__.__name__, key))
E           AttributeError: 'State' object has no attribute 'get_connection'

I'm at a loss on how to get past the new post error, though.

stephenkilbourn

@stephenkilbourn stephenkilbourn added the help wanted Extra attention is needed label Aug 30, 2024
@stephenkilbourn stephenkilbourn changed the title WIP: Fix transaction unit tests test: Fix transaction unit tests Aug 30, 2024
@smohiudd
Copy link
Contributor

@vincentsarago are you able to help us with this PR? I think it's stumped all of Data Services so far 😬

We're mainly seeing a get_connection error when trying POST using the transactions endpoints in stacfastapi-pgstac.

../../../../../.pyenv/versions/veda-backend/lib/python3.11/site-packages/stac_fastapi/pgstac/transactions.py:93: in create_item
    async with request.app.state.get_connection(request, "w") as conn:

Maybe it has something to do with how we're importing the app in our tests.

os.environ["POSTGRES_HOST_READER"] = "database"
os.environ["POSTGRES_HOST_WRITER"] = "database"
os.environ["POSTGRES_HOST_READER"] = "0.0.0.0"
os.environ["POSTGRES_HOST_WRITER"] = "0.0.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we're outside the docker env, we cannot use short name database

if re.match(
f"^{path_prefix}/collections(?:/[^/]+)?$",
"^.*?/collections(?:/[^/]+)?$",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original regex with path_prefix wasn't working with the tests. Do we need path_prefix here or can we just include wildcard? @slesaad

request.url.path,
):
bulk_items = BulkItems(**request_data)
for item_data in bulk_items.items.values():
validate_dict(item_data, STACObjectType.ITEM)
except STACValidationError as e:
except (STACValidationError, STACTypeError) as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included STACTypeError in case someone enters some random dict

@smohiudd smohiudd self-requested a review September 13, 2024 15:16
@smohiudd
Copy link
Contributor

smohiudd commented Sep 25, 2024

I deployed this to https://8ajdmuk7ld.execute-api.us-west-2.amazonaws.com/docs and tested the CREATE, PUT and POST transaction endpoints, and the validation is working.

@smohiudd smohiudd merged commit e53f81b into develop Sep 25, 2024
4 checks passed
anayeaye added a commit that referenced this pull request Oct 15, 2024
…lidation, add nlcd colormap (#434)

**Breaking**
feat(routes)!: remove cloudfront distribution and custom alternate
domain from backend #422

**Added** 
feat(raster-api): added custom NLCD colormap
#433
feat: add ecr endpoint
#432

**Fixed**
fix(tests): #425
fix(ingest): improved datetime validations
#419

**Changed**
ci: remove automated deployments to staging
#438
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants