-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Conversation
27ec33c
to
77d6286
Compare
|
||
|
||
class SubqueryExistsTest(TestCase): | ||
def setUp(self): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) | ||
|
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
No description provided.