Fixed #24017 -- Added python_2_unicode_compatible in db/migrations

This commit is contained in:
Josh Schneier 2014-12-17 18:41:36 -05:00 committed by Tim Graham
parent 653a3a4e18
commit 9a23470072
3 changed files with 22 additions and 3 deletions

View File

@ -3,8 +3,10 @@ from collections import deque
from django.db.migrations.state import ProjectState from django.db.migrations.state import ProjectState
from django.utils.datastructures import OrderedSet from django.utils.datastructures import OrderedSet
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class MigrationGraph(object): class MigrationGraph(object):
""" """
Represents the digraph of all migrations in a project. Represents the digraph of all migrations in a project.
@ -178,6 +180,7 @@ class CircularDependencyError(Exception):
pass pass
@python_2_unicode_compatible
class NodeNotFoundError(LookupError): class NodeNotFoundError(LookupError):
""" """
Raised when an attempt on a node is made that is not available in the graph. Raised when an attempt on a node is made that is not available in the graph.
@ -190,7 +193,5 @@ class NodeNotFoundError(LookupError):
def __str__(self): def __str__(self):
return self.message return self.message
__unicode__ = __str__
def __repr__(self): def __repr__(self):
return "NodeNotFoundError(%r)" % self.node return "NodeNotFoundError(%r)" % self.node

View File

@ -1,7 +1,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db.transaction import atomic from django.db.transaction import atomic
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Migration(object): class Migration(object):
""" """
The base class for all migrations. The base class for all migrations.

View File

@ -1,5 +1,6 @@
from django.test import TestCase from django.test import TestCase
from django.db.migrations.graph import CircularDependencyError, MigrationGraph, NodeNotFoundError from django.db.migrations.graph import CircularDependencyError, MigrationGraph, NodeNotFoundError
from django.utils.encoding import force_text
class GraphTests(TestCase): class GraphTests(TestCase):
@ -213,7 +214,7 @@ class GraphTests(TestCase):
/ \ / \
app_c: 0001<- <------------- x 0002 app_c: 0001<- <------------- x 0002
And apply sqashing on app_c. And apply squashing on app_c.
""" """
graph = MigrationGraph() graph = MigrationGraph()
@ -229,3 +230,18 @@ class GraphTests(TestCase):
with self.assertRaises(CircularDependencyError): with self.assertRaises(CircularDependencyError):
graph.forwards_plan(("app_c", "0001_squashed_0002")) graph.forwards_plan(("app_c", "0001_squashed_0002"))
def test_stringify(self):
graph = MigrationGraph()
self.assertEqual(force_text(graph), "Graph: 0 nodes, 0 edges")
graph.add_node(("app_a", "0001"), None)
graph.add_node(("app_a", "0002"), None)
graph.add_node(("app_a", "0003"), None)
graph.add_node(("app_b", "0001"), None)
graph.add_node(("app_b", "0002"), None)
graph.add_dependency("app_a.0002", ("app_a", "0002"), ("app_a", "0001"))
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_a", "0002"))
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_b", "0002"))
self.assertEqual(force_text(graph), "Graph: 5 nodes, 3 edges")