mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-12-14 07:42:24 +03:00
Added tests for custom db-backend
This commit is contained in:
@@ -1,38 +1,46 @@
|
||||
from django.db import connection, migrations
|
||||
from localized_fields import LocalizedModel
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
from django.contrib.postgres.operations import HStoreExtension
|
||||
|
||||
from localized_fields import LocalizedModel
|
||||
|
||||
def get_fake_model(name='TestModel', fields={}):
|
||||
"""Creates a fake model to use during unit tests."""
|
||||
|
||||
def define_fake_model(name='TestModel', fields=None):
|
||||
attributes = {
|
||||
'app_label': 'localized_fields',
|
||||
'__module__': __name__,
|
||||
'__name__': name
|
||||
}
|
||||
|
||||
attributes.update(fields)
|
||||
TestModel = type(name, (LocalizedModel,), attributes)
|
||||
if fields:
|
||||
attributes.update(fields)
|
||||
model = type(name, (LocalizedModel,), attributes)
|
||||
|
||||
return model
|
||||
|
||||
|
||||
def get_fake_model(name='TestModel', fields=None):
|
||||
"""Creates a fake model to use during unit tests."""
|
||||
|
||||
model = define_fake_model(name, fields)
|
||||
|
||||
class TestProject:
|
||||
|
||||
def clone(self, *args, **kwargs):
|
||||
def clone(self, *_args, **_kwargs):
|
||||
return self
|
||||
|
||||
@property
|
||||
def apps(self):
|
||||
return self
|
||||
|
||||
class TestMigration(migrations.Migration):
|
||||
operations = [
|
||||
HStoreExtension()
|
||||
]
|
||||
operations = [HStoreExtension()]
|
||||
|
||||
with connection.schema_editor() as schema_editor:
|
||||
migration_executor = MigrationExecutor(schema_editor.connection)
|
||||
migration_executor.apply_migration(
|
||||
TestProject(),
|
||||
TestMigration('eh', 'localized_fields')
|
||||
)
|
||||
TestProject(), TestMigration('eh', 'localized_fields'))
|
||||
|
||||
schema_editor.create_model(TestModel)
|
||||
schema_editor.create_model(model)
|
||||
|
||||
return TestModel
|
||||
return model
|
||||
|
||||
Reference in New Issue
Block a user