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
103 changes: 28 additions & 75 deletions tests/migrations/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,44 +860,30 @@ def test_sqlmigrate_forwards(self):
lines[:3],
[
"--",
"-- Create model Author",
"-- Create model Tribble",
"--",
],
)
self.assertIn(
"create table %s" % connection.ops.quote_name("migrations_author").lower(),
"create table %s" % connection.ops.quote_name("migrations_tribble").lower(),
lines[3].lower(),
)
pos = lines.index("--", 3)
self.assertEqual(
lines[pos : pos + 3],
[
"--",
"-- Create model Tribble",
"-- Create model Author",
"--",
],
)
self.assertIn(
"create table %s" % connection.ops.quote_name("migrations_tribble").lower(),
"create rowstore reference table %s" % connection.ops.quote_name("migrations_author").lower(),
lines[pos + 3].lower(),
)
pos = lines.index("--", pos + 3)
self.assertEqual(
lines[pos : pos + 3],
[
"--",
"-- Add field bool to tribble",
"--",
],
)
pos = lines.index("--", pos + 3)
self.assertEqual(
lines[pos : pos + 3],
[
"--",
"-- Alter unique_together for author (1 constraint(s))",
"--",
],
self.assertIn(
"create index",
lines[pos + 4].lower(),
)

@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
Expand All @@ -922,20 +908,13 @@ def test_sqlmigrate_backwards(self):
lines[:3],
[
"--",
"-- Alter unique_together for author (1 constraint(s))",
"--",
],
)
pos = lines.index("--", 3)
self.assertEqual(
lines[pos : pos + 3],
[
"--",
"-- Add field bool to tribble",
"-- Create model Author",
"--",
],
)
pos = lines.index("--", pos + 3)
self.assertIn("DROP TABLE `migrations_author`;", lines[3])

pos = lines.index("--", 4)
self.assertEqual(
lines[pos : pos + 3],
[
Expand All @@ -944,33 +923,7 @@ def test_sqlmigrate_backwards(self):
"--",
],
)
next_pos = lines.index("--", pos + 3)
drop_table_sql = (
"drop table %s"
% connection.ops.quote_name("migrations_tribble").lower()
)
for line in lines[pos + 3 : next_pos]:
if drop_table_sql in line.lower():
break
else:
self.fail("DROP TABLE (tribble) not found.")
pos = next_pos
self.assertEqual(
lines[pos : pos + 3],
[
"--",
"-- Create model Author",
"--",
],
)
drop_table_sql = (
"drop table %s" % connection.ops.quote_name("migrations_author").lower()
)
for line in lines[pos + 3 :]:
if drop_table_sql in line.lower():
break
else:
self.fail("DROP TABLE (author) not found.")
self.assertIn("DROP TABLE `migrations_tribble`;", lines[pos + 3])
finally:
# Unmigrate everything.
call_command("migrate", "migrations", "zero", verbosity=0)
Expand Down Expand Up @@ -1127,7 +1080,7 @@ def test_migrate_syncdb_deferred_sql_executed_with_schemaeditor(self):
"migrate", run_syncdb=True, verbosity=1, stdout=stdout, no_color=True
)
create_table_count = len(
[call for call in execute.mock_calls if "CREATE TABLE" in str(call)]
[call for call in execute.mock_calls if "CREATE TABLE" in str(call)] #There is extra space in Create table sql query
)
self.assertEqual(create_table_count, 2)
# There's at least one deferred SQL for creating the foreign key
Expand Down Expand Up @@ -1164,7 +1117,7 @@ def test_migrate_syncdb_app_label(self):
"migrate", "unmigrated_app_syncdb", run_syncdb=True, stdout=stdout
)
create_table_count = len(
[call for call in execute.mock_calls if "CREATE TABLE" in str(call)]
[call for call in execute.mock_calls if "CREATE TABLE" in str(call)]
)
self.assertEqual(create_table_count, 2)
self.assertGreater(len(execute.mock_calls), 2)
Expand Down Expand Up @@ -1986,7 +1939,8 @@ class Meta:
):
with captured_stdout() as out:
call_command("makemigrations", "migrations", interactive=True)
self.assertIn("Rename model SillyModel to RenamedModel", out.getvalue())
self.assertIn("Create model RenamedModel", out.getvalue())
self.assertIn("Delete model SillyModel", out.getvalue())

@mock.patch("builtins.input", return_value="Y")
def test_makemigrations_field_rename_interactive(self, mock_input):
Expand Down Expand Up @@ -2775,13 +2729,14 @@ def test_squashmigrations_squashes(self):
migration_dir, "0001_squashed_0002_second.py"
)
self.assertTrue(os.path.exists(squashed_migration_file))
#As modifications have been made to the migration file we're squashing.
self.assertEqual(
out.getvalue(),
"Will squash the following migrations:\n"
" - 0001_initial\n"
" - 0002_second\n"
"Optimizing...\n"
" Optimized from 8 operations to 2 operations.\n"
" Optimized from 6 operations to 2 operations.\n"
"Created new squashed migration %s\n"
" You should commit this migration but leave the old ones in place;\n"
" the new migration will be used for new installs. Once you are sure\n"
Expand Down Expand Up @@ -2819,7 +2774,8 @@ def test_squashmigrations_optimizes(self):
verbosity=1,
stdout=out,
)
self.assertIn("Optimized from 8 operations to 2 operations.", out.getvalue())
#As modifications have been made to the migration file we're squashing.
self.assertIn("Optimized from 6 operations to 2 operations.", out.getvalue())

def test_ticket_23799_squashmigrations_no_optimize(self):
"""
Expand Down Expand Up @@ -3093,18 +3049,18 @@ def test_optimization(self):
)
initial_migration_file = os.path.join(migration_dir, "0001_initial.py")
self.assertTrue(os.path.exists(initial_migration_file))
#As modifications have been made to the migration file we're using here.
with open(initial_migration_file) as fp:
content = fp.read()
self.assertIn(
'("bool", models.BooleanField'
"('bool', models.BooleanField"
if HAS_BLACK
else "('bool', models.BooleanField",
else '("bool", models.BooleanField',
content,
)
self.assertEqual(
out.getvalue(),
f"Optimizing from 4 operations to 2 operations.\n"
f"Optimized migration {initial_migration_file}\n",
f"No optimizations possible.\n",
)

def test_optimization_no_verbosity(self):
Expand All @@ -3125,9 +3081,9 @@ def test_optimization_no_verbosity(self):
with open(initial_migration_file) as fp:
content = fp.read()
self.assertIn(
'("bool", models.BooleanField'
"('bool', models.BooleanField"
if HAS_BLACK
else "('bool', models.BooleanField",
else '("bool", models.BooleanField',
content,
)
self.assertEqual(out.getvalue(), "")
Expand Down Expand Up @@ -3188,11 +3144,8 @@ def test_fails_squash_migration_manual_porting(self):

@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_optimizemigration_check(self):
with self.assertRaises(SystemExit):
call_command(
"optimizemigration", "--check", "migrations", "0001", verbosity=0
)

# Expect no error for optimized migration
call_command("optimizemigration", "--check", "migrations", "0001", verbosity=0)
call_command("optimizemigration", "--check", "migrations", "0002", verbosity=0)

@override_settings(
Expand Down
40 changes: 20 additions & 20 deletions tests/migrations/test_migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from django.db import migrations, models
import django_singlestore.schema


class Migration(migrations.Migration):
initial = True

operations = [
migrations.CreateModel(
"Author",
[
("id", models.AutoField(primary_key=True)),
("name", models.CharField(max_length=255)),
("slug", models.SlugField(null=True)),
("age", models.IntegerField(default=0)),
("silly_field", models.BooleanField(default=False)),
name='Tribble',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('fluffy', models.BooleanField(default=True)),
('bool', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
"Tribble",
[
("id", models.AutoField(primary_key=True)),
("fluffy", models.BooleanField(default=True)),
name='Author',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('slug', models.SlugField(null=True)),
('age', models.IntegerField(default=0)),
('silly_field', models.BooleanField(default=False)),
],
options={
'unique_together': {('name', 'slug')},
},
managers=[
('objects', django_singlestore.schema.ModelStorageManager('ROWSTORE REFERENCE')),
],
),
migrations.AddField(
model_name="tribble",
name="bool",
field=models.BooleanField(default=False),
),
migrations.AlterUniqueTogether(
name="author",
unique_together={("name", "slug")},
),
]

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: new line. Same in other files

35 changes: 20 additions & 15 deletions tests/migrations/test_migrations_fake_split_initial/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
from django.db import migrations, models
import django_singlestore.schema


class Migration(migrations.Migration):
initial = True

operations = [
migrations.CreateModel(
"Author",
[
("id", models.AutoField(primary_key=True)),
("name", models.CharField(max_length=255)),
("slug", models.SlugField(null=True)),
("age", models.IntegerField(default=0)),
("silly_field", models.BooleanField(default=False)),
name='Tribble',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('fluffy', models.BooleanField(default=True)),
('bool', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
"Tribble",
[
("id", models.AutoField(primary_key=True)),
("fluffy", models.BooleanField(default=True)),
name='Author',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('slug', models.SlugField(null=True)),
('age', models.IntegerField(default=0)),
('silly_field', models.BooleanField(default=False)),
],
options={
'unique_together': {('name', 'slug')},
},
managers=[
('objects', django_singlestore.schema.ModelStorageManager('ROWSTORE REFERENCE')),
],
),
migrations.AlterUniqueTogether(
name="author",
unique_together={("name", "slug")},
),
]

35 changes: 20 additions & 15 deletions tests/migrations/test_migrations_initial_false/0001_not_initial.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
from django.db import migrations, models
import django_singlestore.schema


class Migration(migrations.Migration):
initial = False

operations = [
migrations.CreateModel(
"Author",
[
("id", models.AutoField(primary_key=True)),
("name", models.CharField(max_length=255)),
("slug", models.SlugField(null=True)),
("age", models.IntegerField(default=0)),
("silly_field", models.BooleanField(default=False)),
name='Tribble',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('fluffy', models.BooleanField(default=True)),
('bool', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
"Tribble",
[
("id", models.AutoField(primary_key=True)),
("fluffy", models.BooleanField(default=True)),
name='Author',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('slug', models.SlugField(null=True)),
('age', models.IntegerField(default=0)),
('silly_field', models.BooleanField(default=False)),
],
options={
'unique_together': {('name', 'slug')},
},
managers=[
('objects', django_singlestore.schema.ModelStorageManager('ROWSTORE REFERENCE')),
],
),
migrations.AlterUniqueTogether(
name="author",
unique_together={("name", "slug")},
),
]

4 changes: 2 additions & 2 deletions tests/migrations/test_migrations_no_changes/0003_third.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.AutoField(
models.BigAutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
Expand All @@ -28,7 +28,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.AutoField(
models.BigAutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
Expand Down
Loading
Loading