Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/backends/base/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ def test_datetime_extract_sql(self):

def test_prepare_join_on_clause(self):
author_table = Author._meta.db_table
author_id_field = Author._meta.get_field("id")
author_name_field = Author._meta.get_field("name")
book_table = Book._meta.db_table
book_fk_field = Book._meta.get_field("author")
lhs_expr, rhs_expr = self.ops.prepare_join_on_clause(
author_table,
author_id_field,
author_name_field,
book_table,
book_fk_field,
)
self.assertEqual(lhs_expr, Col(author_table, author_id_field))
self.assertEqual(lhs_expr, Col(author_table, author_name_field))
self.assertEqual(rhs_expr, Col(book_table, book_fk_field))


Expand Down
11 changes: 10 additions & 1 deletion tests/backends/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ def get_queryset(self):

class SchoolBus(models.Model):
number = models.IntegerField()
schoolclasses = models.ManyToManyField("SchoolClass")
schoolclasses = models.ManyToManyField("SchoolClass", through="SchoolBusSchoolClass")
objects = SchoolBusManager()

class Meta:
base_manager_name = "objects"


class SchoolBusSchoolClass(models.Model):
schoolbus = models.ForeignKey(SchoolBus, on_delete=models.CASCADE)
schoolclass = models.ForeignKey(SchoolClass, on_delete=models.CASCADE)

class Meta:
unique_together = (('schoolbus', 'schoolclass'),)
db_table = "backends_schoolbus_schoolclass"


class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(models.Model):
primary_key_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.AutoField(
primary_key=True
Expand Down
1 change: 1 addition & 0 deletions tests/basic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def test_save_primary_with_default(self):
with self.assertNumQueries(1):
PrimaryKeyWithDefault().save()

@skipUnlessDBFeature("supports_db_default")
def test_save_primary_with_db_default(self):
# An UPDATE attempt is skipped when a primary key has db_default.
with self.assertNumQueries(1):
Expand Down
1 change: 1 addition & 0 deletions tests/constraints/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ def test_requires_name(self):
with self.assertRaisesMessage(ValueError, msg):
models.UniqueConstraint(fields=["field"])

@skipUnlessDBFeature("supports_db_default")
def test_database_default(self):
models.UniqueConstraint(
fields=["field_with_db_default"], name="unique_field_with_db_default"
Expand Down
11 changes: 4 additions & 7 deletions tests/field_defaults/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ class DBDefaults(models.Model):


class DBDefaultsFunction(models.Model):
number = models.FloatField(db_default=Pi())
year = models.IntegerField(db_default=ExtractYear(Now()))
added = models.FloatField(db_default=Pi() + 4.5)
multiple_subfunctions = models.FloatField(db_default=Coalesce(4.5, Pi()))
case_when = models.IntegerField(
db_default=models.Case(models.When(GreaterThan(2, 1), then=3), default=4)
)
number = models.FloatField(db_default=3.14)
year = models.IntegerField(db_default=2024)
added = models.FloatField(db_default=3+4.5)
multiple_subfunctions = models.FloatField(db_default=4.5)

class Meta:
required_db_features = {"supports_expression_defaults"}
Expand Down
11 changes: 6 additions & 5 deletions tests/field_defaults/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ def test_field_db_defaults_returning(self):

@skipIfDBFeature("can_return_columns_from_insert")
@skipUnlessDBFeature("supports_expression_defaults")
def test_field_db_defaults_refresh(self):
def test_field_db_defaults_refresh(self):
a = DBArticle()
a.save()
a.refresh_from_db()

self.assertIsInstance(a.id, int)
self.assertEqual(a.headline, "Default headline")
self.assertIsInstance(a.pub_date, datetime)
Expand All @@ -73,9 +74,9 @@ def test_db_default_function(self):
m = DBDefaultsFunction.objects.create()
if not connection.features.can_return_columns_from_insert:
m.refresh_from_db()
self.assertAlmostEqual(m.number, pi)
self.assertEqual(m.year, datetime.now().year)
self.assertAlmostEqual(m.added, pi + 4.5)
self.assertAlmostEqual(m.number, 3.14)
self.assertEqual(m.year, 2024)
self.assertAlmostEqual(m.added, 7.5)
self.assertEqual(m.multiple_subfunctions, 4.5)

@skipUnlessDBFeature("insert_test_table_with_defaults")
Expand Down Expand Up @@ -168,7 +169,7 @@ def test_bulk_create_mixed_db_defaults_function(self):
DBDefaultsFunction.objects.bulk_create(instances)

years = DBDefaultsFunction.objects.values_list("year", flat=True)
self.assertCountEqual(years, [2000, datetime.now().year])
self.assertCountEqual(years, [2000, 2024])

def test_full_clean(self):
obj = DBArticle()
Expand Down
7 changes: 3 additions & 4 deletions tests/fixtures/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,13 +834,12 @@ def test_dumpdata_objects_with_prefetch_related(self):
management.call_command(
"loaddata", "fixture6.json", "fixture8.json", verbosity=0
)
with self.assertNumQueries(5):
with self.assertNumQueries(4):
self._dumpdata_assert(
["fixtures.visa"],
'[{"fields": {"permissions": [["add_user", "auth", "user"]],'
'"person": ["Stephane Grappelli"]},'
'[{"fields": {"person": ["Stephane Grappelli"]},'
'"model": "fixtures.visa", "pk": 2},'
'{"fields": {"permissions": [], "person": ["Prince"]},'
'{"fields": {"person": ["Prince"]},'
'"model": "fixtures.visa", "pk": 3}]',
natural_foreign_keys=True,
primary_keys="2,3",
Expand Down
4 changes: 3 additions & 1 deletion tests/force_insert_update/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from django.db import models

from django_singlestore.schema import ModelStorageManager

class Counter(models.Model):
name = models.CharField(max_length=10)
Expand Down Expand Up @@ -37,7 +37,9 @@ class OtherSubCounter(Counter):
other_counter_ptr = models.OneToOneField(
Counter, primary_key=True, parent_link=True, on_delete=models.CASCADE
)
objects = ModelStorageManager("ROWSTORE REFERENCE")


class DiamondSubSubCounter(SubCounter, OtherSubCounter):
objects = ModelStorageManager("ROWSTORE REFERENCE")
pass
5 changes: 4 additions & 1 deletion tests/migrations/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,7 @@ def test_add_field_preserve_default(self):
sorted(definition[2]), ["field", "model_name", "name", "preserve_default"]
)

@skipUnlessDBFeature("supports_db_default")
def test_add_field_database_default(self):
"""The AddField operation can set and unset a database default."""
app_label = "test_adfldd"
Expand Down Expand Up @@ -1670,6 +1671,7 @@ def test_add_field_database_default(self):
},
)

@skipUnlessDBFeature("supports_db_default")
def test_add_field_database_default_special_char_escaping(self):
app_label = "test_adflddsce"
table_name = f"{app_label}_pony"
Expand Down Expand Up @@ -1717,7 +1719,7 @@ def test_add_field_database_default_special_char_escaping(self):
app_label, editor, new_state, project_state
)

@skipUnlessDBFeature("supports_expression_defaults")
@skipUnlessDBFeature("supports_db_default")
def test_add_field_database_default_function(self):
app_label = "test_adflddf"
table_name = f"{app_label}_pony"
Expand Down Expand Up @@ -1745,6 +1747,7 @@ def test_add_field_database_default_function(self):
new_pony.refresh_from_db()
self.assertAlmostEqual(old_pony.height, math.pi)

@skipUnlessDBFeature("supports_db_default")
def test_add_field_both_defaults(self):
"""The AddField operation with both default and db_default."""
app_label = "test_adflbddd"
Expand Down
5 changes: 5 additions & 0 deletions tests/model_formsets/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,10 @@ def test_inlineformset_factory_nulls_default_pks_alternate_key_relation_data(sel
}
)
self.assertIs(formset.is_valid(), True)

# Save parent first
formset.instance.save()
# Then save the formset
formset.save()
self.assertIsNotNone(formset.instance.uuid)
self.assertEqual(formset.forms[0].instance.parent_id, formset.instance.uuid)
5 changes: 5 additions & 0 deletions tests/model_inheritance/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class ItalianRestaurantCommonParent(ItalianRestaurant, Place):
place_ptr_two = models.OneToOneField(
Place, on_delete=models.CASCADE, parent_link=True
)
objects = ModelStorageManager(table_storage_type="REFERENCE")


class Supplier(Place):
Expand All @@ -137,6 +138,7 @@ class ParkingLot(Place):
Place, models.CASCADE, primary_key=True, parent_link=True
)
main_site = models.ForeignKey(Place, models.CASCADE, related_name="lot")
objects = ModelStorageManager(table_storage_type="REFERENCE")


#
Expand Down Expand Up @@ -228,13 +230,16 @@ class FirstParent(CommonAncestor):
first_ancestor = models.OneToOneField(
CommonAncestor, models.CASCADE, primary_key=True, parent_link=True
)
objects = ModelStorageManager(table_storage_type="REFERENCE")


class SecondParent(CommonAncestor):
second_ancestor = models.OneToOneField(
CommonAncestor, models.CASCADE, primary_key=True, parent_link=True
)
objects = ModelStorageManager(table_storage_type="REFERENCE")


class CommonChild(FirstParent, SecondParent):
objects = ModelStorageManager(table_storage_type="REFERENCE")
pass
4 changes: 4 additions & 0 deletions tests/schema/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,7 @@ def test_rename_keep_null_status(self):
with self.assertRaises(IntegrityError):
NoteRename.objects.create(detail_info=None)

@skipUnlessDBFeature("supports_db_default")
@isolate_apps("schema")
def test_rename_keep_db_default(self):
"""Renaming a field shouldn't affect a database default."""
Expand All @@ -2369,6 +2370,7 @@ class Meta:
columns = self.column_classes(AuthorDbDefault)
self.assertEqual(columns["renamed_year"][1].default, "1985")

@skipUnlessDBFeature("supports_db_default")
@isolate_apps("schema")
def test_add_field_both_defaults_preserves_db_default(self):
class Author(Model):
Expand All @@ -2386,6 +2388,7 @@ class Meta:
columns = self.column_classes(Author)
self.assertEqual(columns["birth_year"][1].default, "1988")

@skipUnlessDBFeature("supports_db_default")
@isolate_apps("schema")
def test_add_text_field_with_db_default(self):
class Author(Model):
Expand Down Expand Up @@ -2416,6 +2419,7 @@ class Meta:
with connection.schema_editor() as editor, self.assertNumQueries(0):
editor.alter_field(Author, Author._meta.get_field("name"), new_field)

@skipUnlessDBFeature("supports_db_default")
@isolate_apps("schema")
def test_db_default_output_field_resolving(self):
class Author(Model):
Expand Down
3 changes: 2 additions & 1 deletion tests/validation/test_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.apps.registry import Apps
from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase
from django.test import TestCase, skipUnlessDBFeature

from .models import (
CustomPKModel,
Expand Down Expand Up @@ -146,6 +146,7 @@ def test_primary_key_unique_check_not_performed_when_not_adding(self):
mtv = ModelToValidate(number=10, name="Some Name")
mtv.full_clean()

@skipUnlessDBFeature("supports_db_default")
def test_unique_db_default(self):
UniqueFieldsModel.objects.create(unique_charfield="foo", non_unique_field=42)
um = UniqueFieldsModel(unique_charfield="bar", non_unique_field=42)
Expand Down
Loading