'Tests the AlterUniqueTogether operation.'

def test_alter_unique_together(self):

    project_state = self.set_up_test_model('test_alunto')
    operation = migrations.AlterUniqueTogether('Pony', [('pink', 'weight')])
    self.assertEqual(operation.describe(), 'Alter    unique_together    for    Pony    (1    constraint(s))')
    new_state = project_state.clone()
    operation.state_forwards('test_alunto', new_state)
    self.assertEqual(len(project_state.models[('test_alunto', 'pony')].options.get('unique_together', set())), 0)
    self.assertEqual(len(new_state.models[('test_alunto', 'pony')].options.get('unique_together', set())), 1)
    with connection.cursor() as cursor:
        cursor.execute('INSERT    INTO    test_alunto_pony    (pink,    weight)    VALUES    (1,    1)')
        cursor.execute('INSERT    INTO    test_alunto_pony    (pink,    weight)    VALUES    (1,    1)')
        cursor.execute('DELETE    FROM    test_alunto_pony')
        with connection.schema_editor() as editor:
            operation.database_forwards('test_alunto', editor, project_state, new_state)
        cursor.execute('INSERT    INTO    test_alunto_pony    (pink,    weight)    VALUES    (1,    1)')
        with self.assertRaises(IntegrityError):
            with atomic():
                cursor.execute('INSERT    INTO    test_alunto_pony    (pink,    weight)    VALUES    (1,    1)')
        cursor.execute('DELETE    FROM    test_alunto_pony')
        with connection.schema_editor() as editor:
            operation.database_backwards('test_alunto', editor, new_state, project_state)
        cursor.execute('INSERT    INTO    test_alunto_pony    (pink,    weight)    VALUES    (1,    1)')
        cursor.execute('INSERT    INTO    test_alunto_pony    (pink,    weight)    VALUES    (1,    1)')
        cursor.execute('DELETE    FROM    test_alunto_pony')
    operation = migrations.AlterUniqueTogether('Pony', ('pink', 'weight'))
    operation.state_forwards('test_alunto', new_state)
    self.assertEqual(len(new_state.models[('test_alunto', 'pony')].options.get('unique_together', set())), 1)
    definition = operation.deconstruct()
    self.assertEqual(definition[0], 'AlterUniqueTogether')
    self.assertEqual(definition[1], [])
    self.assertEqual(definition[2], {'name': 'Pony', 'unique_together': {('pink', 'weight')}})
