Beispiel #1
0
...     int_field = models.IntegerField()
...     # Plus a generic foreign key - the Generic itself should be ignored
...     content_type = models.ForeignKey(ContentType)
...     object_id = models.PositiveIntegerField(db_index=True)
...     content_object = generic.GenericForeignKey('content_type','object_id')
...     # Plus a generic relation, which should be ignored
...     generic = generic.GenericRelation(GenericAnchor)

>>> end = register_models(('TestModel', DeleteColumnModel), anchor)
>>> end_sig = test_proj_sig(('TestModel', DeleteColumnModel), content_type, anchor)
>>> d = Diff(start_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']]
["DeleteField('TestModel', 'char_field')"]

>>> test_sig = copy.deepcopy(start_sig)
>>> test_sql = []
>>> for mutation in d.evolution()['tests']:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(start, end, test_sql) #DeleteColumnModel
%(DeleteColumnModel)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('generics')
Beispiel #2
0
>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(start, end, test_sql) #CustomTableModel
%(CustomTableModel)s

# Delete a model with a custom table name and an m2m field
>>> end_sig = copy.deepcopy(start_sig)
>>> _ = end_sig['tests'].pop('CustomTableWithM2MModel')

>>> d = Diff(start_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']]
["DeleteModel('CustomTableWithM2MModel')"]

>>> test_sig = copy.deepcopy(start_sig)
>>> test_sql = []
>>> for mutation in d.evolution()['tests']:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(start, end, test_sql) #CustomTableWithM2MModel
%(CustomTableWithM2MModel)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('delete_model')
Beispiel #3
0
# Change field type to another type with same internal_type
>>> class MyIntegerField(models.IntegerField):
...     def get_internal_type(self):
...         return 'IntegerField'

>>> class MinorFieldTypeChangeModel(models.Model):
...     my_id = models.AutoField(primary_key=True)
...     alt_pk = models.IntegerField()
...     int_field = models.IntegerField(db_column='custom_db_column')
...     int_field1 = models.IntegerField(db_index=True)
...     int_field2 = models.IntegerField(db_index=False)
...     int_field3 = models.IntegerField(unique=True)
...     int_field4 = MyIntegerField(unique=False)
...     char_field = models.CharField(max_length=20)
...     char_field1 = models.CharField(max_length=25, null=True)
...     char_field2 = models.CharField(max_length=30, null=False)
...     m2m_field1 = models.ManyToManyField(ChangeAnchor1, db_table='change_field_non-default_m2m_table')

>>> end = register_models(('TestModel', MinorFieldTypeChangeModel), *anchors)
>>> end_sig = test_proj_sig(('TestModel', MinorFieldTypeChangeModel), *anchors)
>>> d = Diff(start_sig, end_sig)

>>> d.is_empty()
True

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('change_field')
Beispiel #4
0
>>> execute_test_sql(start, end, test_sql) # AddToChildModel
%(AddToChildModel)s

# Delete field from child model
>>> class AddToChildModel(models.Model):
...     char_field = models.CharField(max_length=20)

>>> end = register_models(('ChildModel', AddToChildModel), parent_model)
>>> end_sig = test_proj_sig(('ChildModel',AddToChildModel), parent_model)
>>> d = Diff(start_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']] # DeleteFromChildModel
["DeleteField('ChildModel', 'int_field')"]

>>> test_sig = copy.deepcopy(start_sig)
>>> test_sql = []
>>> for mutation in d.evolution()['tests']:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(start, end, test_sql) # DeleteFromChildModel
%(DeleteFromChildModel)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('inheritance')
Beispiel #5
0
%(DeleteForeignKeyModel)s

# Deleting a column from a non-default table
>>> class DeleteColumnCustomTableModel(models.Model):
...     alt_value = models.CharField(max_length=20)
...     class Meta:
...         db_table = 'custom_table_name'

>>> end = register_models(('CustomTableModel', DeleteColumnCustomTableModel))
>>> end_sig = test_proj_sig(('CustomTableModel', DeleteColumnCustomTableModel))
>>> d = Diff(custom_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']]
["DeleteField('CustomTableModel', 'value')"]

>>> test_sig = copy.deepcopy(custom_sig)
>>> test_sql = []
>>> for mutation in d.evolution()['tests']:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(custom, end, test_sql) #DeleteColumnCustomTableModel
%(DeleteColumnCustomTableModel)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('delete_field')
Beispiel #6
0
True

>>> execute_test_sql(start, end, test_sql) #AddManyToManyNonDefaultDatabaseTableModel
%(AddManyToManyNonDefaultDatabaseTableModel)s

# M2M field between self
# Need to find a better way to do this.
>>> end_sig = copy.deepcopy(start_sig)
>>> end_sig['tests']['TestModel']['fields']['added_field'] = {'field_type': models.ManyToManyField,'related_model': 'tests.TestModel'}

>>> d = Diff(start_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']]
["AddField('TestModel', 'added_field', models.ManyToManyField, related_model='tests.TestModel')"]

>>> test_sig = copy.deepcopy(start_sig)
>>> test_sql = []
>>> for mutation in d.evolution()['tests']:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(start, end, test_sql) #AddManyToManySelf
%(AddManyToManySelf)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('add_field')
Beispiel #7
0
%(DeleteForeignKeyModel)s

# Deleting a column from a non-default table
>>> class DeleteColumnCustomTableModel(models.Model):
...     alt_value = models.CharField(max_length=20)
...     class Meta:
...         db_table = 'custom_table_name'

>>> end = register_models(('CustomTableModel', DeleteColumnCustomTableModel))
>>> end_sig = test_proj_sig(('CustomTableModel', DeleteColumnCustomTableModel))
>>> d = Diff(custom_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']]
["DeleteField('CustomTableModel', 'value')"]

>>> test_sig = copy.deepcopy(custom_sig)
>>> test_sql = []
>>> for mutation in d.evolution()['tests']:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(custom, end, test_sql) #DeleteColumnCustomTableModel
%(DeleteColumnCustomTableModel)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('delete_field')
Beispiel #8
0
...     int_field_named_indexed = models.IntegerField(db_column='custom_db_col_name_indexed', db_index=True)
...     fk_field = models.ForeignKey(RenameAnchor1)
...     m2m_field = models.ManyToManyField(RenameAnchor2)
...     renamed_field = models.ManyToManyField(RenameAnchor3, db_table='non-default_db_table')

>>> end = register_models(('TestModel', RenameNonDefaultM2MTableModel), *anchors)
>>> end_sig = test_proj_sig(('TestModel',RenameNonDefaultM2MTableModel), *anchors)
>>> start_sig = copy.deepcopy(start_sig)
>>> d = Diff(start_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']]
["AddField('TestModel', 'renamed_field', models.ManyToManyField, db_table='non-default_db_table', related_model='tests.RenameAnchor3')", "DeleteField('TestModel', 'm2m_field_named')"]

>>> evolution = [RenameField('TestModel', 'm2m_field_named', 'renamed_field')]
>>> test_sig = copy.deepcopy(start_sig)
>>> test_sql = []
>>> for mutation in evolution:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
False

# FIXME!! This test fails under Postgres
#>>> execute_test_sql(start, end, test_sql) #RenameNonDefaultManyToManyTableModel
#%(RenameNonDefaultManyToManyTableModel)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('rename_field')
    def get_sql_mapping(self, name, db_name=None):
        db_name = db_name or self.default_database_name

        return test_sql_mapping(self.sql_mapping_key, db_name)[name]
>>> start_sig = test_proj_sig(*all_models)

# Copy the base signature, and delete the tests app.
>>> deleted_app_sig = copy.deepcopy(start_sig)
>>> deleted_app_sig = deleted_app_sig.pop('tests')

>>> d = Diff(start_sig, deleted_app_sig)
>>> print d.deleted
{'tests': ['AppDeleteAnchor1', 'AppDeleteAnchor2', 'TestModel', 'CustomTestModel']}

>>> test_sig = copy.deepcopy(start_sig)

>>> test_sql = []
>>> delete_app = DeleteApplication()
>>> for app_label in d.deleted.keys():
...     test_sql.append(delete_app.mutate(app_label, test_sig))
...     delete_app.simulate(app_label, test_sig)

>>> Diff(test_sig, deleted_app_sig).is_empty(ignore_apps=True)
True

>>> for sql_list in test_sql:
...     for sql in sql_list:
...         print sql
%(DeleteApplication)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('delete_application')
    def get_sql_mapping(self, name, db_name=None):
        db_name = db_name or self.default_database_name

        return test_sql_mapping(self.sql_mapping_key, db_name)[name]
Beispiel #12
0
# Change field type to another type with same internal_type
>>> class MyIntegerField(models.IntegerField):
...     def get_internal_type(self):
...         return 'IntegerField'

>>> class MinorFieldTypeChangeModel(models.Model):
...     my_id = models.AutoField(primary_key=True)
...     alt_pk = models.IntegerField()
...     int_field = models.IntegerField(db_column='custom_db_column')
...     int_field1 = models.IntegerField(db_index=True)
...     int_field2 = models.IntegerField(db_index=False)
...     int_field3 = models.IntegerField(unique=True)
...     int_field4 = MyIntegerField(unique=False)
...     char_field = models.CharField(max_length=20)
...     char_field1 = models.CharField(max_length=25, null=True)
...     char_field2 = models.CharField(max_length=30, null=False)
...     m2m_field1 = models.ManyToManyField(ChangeAnchor1, db_table='multi_db_non-default_m2m_table')

>>> end = register_models_multi('tests', 'db_multi', ('TestModel', MinorFieldTypeChangeModel), *anchors)
>>> end_sig = test_proj_sig_multi('tests', ('TestModel', MinorFieldTypeChangeModel), *anchors)
>>> d = Diff(start_sig, end_sig)

>>> d.is_empty()
True

# Clean up after the applications that were installed
>>> deregister_models('tests')

""" % test_sql_mapping('multi_db', db_name='db_multi')
Beispiel #13
0
...         'field_type': models.IntegerField,
...         'null': True
...     }

>>> def update_third(app_label, proj_sig):
...     app_sig = proj_sig[app_label]
...     model_sig = app_sig['TestModel']
...     model_sig['fields']['added_field3'] = {
...         'field_type': models.IntegerField,
...         'null': True
...     }

>>> sequence = %(SQLMutationSequence)s

>>> test_sig = copy.deepcopy(start_sig)
>>> test_sql = []
>>> for mutation in sequence:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(start, end, test_sql) #SQLMutationOutput
%(SQLMutationOutput)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('sql_mutation')
Beispiel #14
0
>>> for app_label in d.deleted.keys():
...     test_sql.append(delete_app.mutate(app_label, test_sig))
...     delete_app.simulate(app_label, test_sig)

>>> Diff(test_sig, deleted_app_sig).is_empty(ignore_apps=True)
True

>>> for sql_list in test_sql:
...     for sql in sql_list:
...         print sql
%(DeleteApplicationWithoutDatabase)s

>>> test_sql = []
>>> delete_app = DeleteApplication()
>>> for app_label in d.deleted.keys():
...     test_sql.append(delete_app.mutate(app_label, test_sig, 'default'))
...     delete_app.simulate(app_label, test_sig)

>>> Diff(test_sig, deleted_app_sig).is_empty(ignore_apps=True)
True

>>> for sql_list in test_sql:
...     for sql in sql_list:
...         print sql
%(DeleteApplication)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping('delete_application')
Beispiel #15
0
...     content_type = models.ForeignKey(ContentType)
...     object_id = models.PositiveIntegerField(db_index=True)
...     content_object = generic.GenericForeignKey('content_type','object_id')
...     # Plus a generic relation, which should be ignored
...     generic = generic.GenericRelation(GenericAnchor)

>>> end = register_models(('TestModel', DeleteColumnModel), anchor)
>>> end_sig = test_proj_sig(('TestModel', DeleteColumnModel), content_type, anchor)
>>> d = Diff(start_sig, end_sig)
>>> print [str(e) for e in d.evolution()['tests']]
["DeleteField('TestModel', 'char_field')"]

>>> test_sig = copy.deepcopy(start_sig)
>>> test_sql = []
>>> for mutation in d.evolution()['tests']:
...     test_sql.extend(mutation.mutate('tests', test_sig))
...     mutation.simulate('tests', test_sig)

>>> Diff(test_sig, end_sig).is_empty()
True

>>> execute_test_sql(start, end, test_sql) #DeleteColumnModel
%(DeleteColumnModel)s

# Clean up after the applications that were installed
>>> deregister_models()

""" % test_sql_mapping(
    "generics"
)