Skip to content

adapt raw_query tests for QuerySet.raw_aggregate() #12

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

Closed
wants to merge 1 commit into from
Closed

adapt raw_query tests for QuerySet.raw_aggregate() #12

wants to merge 1 commit into from

Conversation

aclark4life
Copy link
Collaborator

@aclark4life aclark4life commented Nov 11, 2024

feature: mongodb/django-mongodb-backend#183

These tests are incorporated in django-mongodb's tests/raw_query_/test_raw_aggregate.py and this PR shows the diff of how they were adapted.

@aclark4life

This comment was marked as resolved.

Copy link
Collaborator

@Jibola Jibola left a comment

Choose a reason for hiding this comment

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

Will take a look at this shortly!

Comment on lines 252 to 271
query = [{"$match": {"last_name": "%(last)s" % {"last": "foo"}}}]
qset = Author.objects.raw_mql(query)
self.assertEqual(
repr(qset),
"<RawQuerySet: SELECT * FROM raw_query_author WHERE last_name = foo>",
"<MongoRawQuerySet: [{'$match': {'last_name': 'foo'}}]>",
)
self.assertEqual(
repr(qset.query),
"<RawQuery: SELECT * FROM raw_query_author WHERE last_name = foo>",
"<MongoRawQuery: [{'$match': {'last_name': 'foo'}}]>",
)

query = "SELECT * FROM raw_query_author WHERE last_name = %s"
qset = Author.objects.raw(query, {"foo"})
query = [{"$match": {"last_name": "%s" % "foo"}}]
qset = Author.objects.raw_mql(query)
self.assertEqual(
repr(qset),
"<RawQuerySet: SELECT * FROM raw_query_author WHERE last_name = foo>",
"<MongoRawQuerySet: [{'$match': {'last_name': 'foo'}}]>",
)
self.assertEqual(
repr(qset.query),
"<RawQuery: SELECT * FROM raw_query_author WHERE last_name = foo>",
"<MongoRawQuery: [{'$match': {'last_name': 'foo'}}]>",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these tests can be skipped since we ultimately don't support the params field

Copy link
Collaborator

Choose a reason for hiding this comment

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

We do need one test for __repr__() but we don't need to test this redundantly or with a query that uses string interpolation. Let's continue to edit this file here (so we can see the diff against the raw_query tests, but with the ultimate goal of putting this test app in the django-mongodb tests directory rather than merging these changes. So, for example, for tests that aren't applicable, remove them in the PR instead of adding skips.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

E.g. raw_query_ ?

Copy link
Collaborator

@Jibola Jibola left a comment

Choose a reason for hiding this comment

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

Add a skip test to what I talked about before and then everything looks good to me!
The test condition can be "params not supported" or "translations not supported"

@aclark4life
Copy link
Collaborator Author

Add a skip test to what I talked about before and then everything looks good to me! The test condition can be "params not supported" or "translations not supported"

Looks like we're going to move to django_mongodb in raw_query_ … I'll start adding the tests there.

@timgraham timgraham changed the title Update raw_query tests for raw_mql Update raw_query tests for QuerySet.raw_aggregate() Nov 19, 2024
@timgraham timgraham changed the title Update raw_query tests for QuerySet.raw_aggregate() adapt raw_query tests for QuerySet.raw_aggregate() Nov 21, 2024
@timgraham
Copy link
Collaborator

These tests are incorporated in django-mongodb's tests/raw_query_/test_raw_aggregate.py and this PR shows the diff of how they were adapted.

@timgraham timgraham closed this Nov 21, 2024
@aclark4life aclark4life deleted the mongodb-5.0.x branch November 21, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants