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

EMF add subqueries tests #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WaVEV
Copy link
Collaborator

@WaVEV WaVEV commented Jan 18, 2025

No description provided.

@WaVEV WaVEV requested a review from timgraham January 18, 2025 05:23
@WaVEV WaVEV force-pushed the EMF-subquery-tests branch from 27ec33c to 77d6286 Compare January 18, 2025 21:20


class SubqueryExistsTest(TestCase):
def setUp(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

use setUpTestData?

@@ -123,3 +129,62 @@ class MyModel(models.Model):
self.assertEqual(
msg, "Embedded models cannot have relational fields (Target.key is a ForeignKey)."
)


class SubqueryExistsTest(TestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tests

self.assertEqual(queryset.count(), 3)
self.assertQuerySetEqual(queryset, ["Book B", "Book C", "Book D"], lambda book: book.name)

def test_range_query(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why in this class? Is it because the count() does an aggregation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this test could be put in a better place. Will move

author__name=OuterRef("name"), author__address__city="Boston"
)
queryset = Author.objects.filter(Exists(subquery))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please omit the blank lines.


def test_in_subquery(self):
subquery = Author.objects.filter(age__gt=35).values("name")
queryset = Book.objects.filter(author__name__in=Subquery(subquery)).order_by("name")
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I tested, the Subquery wrapping of subquery is unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mmh yes, don't remember why i added that

address2 = Address.objects.create(city="Boston", state="MA", zip_code=20002)
author1 = Author.objects.create(name="Alice", age=30, address=address1)
author2 = Author.objects.create(name="Bob", age=40, address=address2)
book1 = Book.objects.create(name="Book A", author=author1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to title it "Book 1" rather than switching between letters and numbers.

class SubqueryExistsTest(TestCase):
def setUp(self):
# Create test data
address1 = Address.objects.create(city="New York", state="NY", zip_code=10001)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Embedded models should be saved to the database in their own collection (i.e. no create()). #216 will prohibit it.

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.

2 participants