simplify reading of tests
This commit is contained in:
parent
4d0f471cfc
commit
dd07515cbb
@ -6,58 +6,57 @@ class MergeTests(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.a = Person.objects.create(name='alf')
|
self.a = Person.objects.create(name='alf')
|
||||||
self.b = Person.objects.create(name='bee')
|
self.b = Person.objects.create(name='bee')
|
||||||
self.c = Person.objects.create(name='sea')
|
|
||||||
Number.objects.create(person=self.a, number='555-1111')
|
|
||||||
Number.objects.create(person=self.a, number='555-1112')
|
|
||||||
Number.objects.create(person=self.b, number='555-1113')
|
|
||||||
SSN.objects.create(person=self.a, number='1')
|
|
||||||
SSN.objects.create(person=self.b, number='2')
|
|
||||||
self.g = Group.objects.create(name='Team Awesome')
|
self.g = Group.objects.create(name='Team Awesome')
|
||||||
self.g.people.add(self.a)
|
|
||||||
self.g.people.add(self.b)
|
|
||||||
|
|
||||||
def test_fk_simple(self):
|
def test_fk_simple(self):
|
||||||
merge(self.a, self.c)
|
Number.objects.create(person=self.a, number='555-1111')
|
||||||
|
Number.objects.create(person=self.a, number='555-1112')
|
||||||
|
merge(self.a, self.b)
|
||||||
# move FKs pointing at A to C
|
# move FKs pointing at A to C
|
||||||
assert self.a.numbers.count() == 0
|
assert self.a.numbers.count() == 0
|
||||||
assert self.c.numbers.count() == 2
|
assert self.b.numbers.count() == 2
|
||||||
assert Number.objects.count() == 3
|
assert Number.objects.count() == 2
|
||||||
|
|
||||||
def test_fk_existing(self):
|
def test_fk_existing(self):
|
||||||
|
Number.objects.create(person=self.a, number='555-1112')
|
||||||
|
Number.objects.create(person=self.b, number='555-1113')
|
||||||
merge(self.a, self.b)
|
merge(self.a, self.b)
|
||||||
# everything now on b
|
# everything now on B
|
||||||
assert self.a.numbers.count() == 0
|
assert self.a.numbers.count() == 0
|
||||||
assert self.b.numbers.count() == 3
|
assert self.b.numbers.count() == 2
|
||||||
assert Number.objects.count() == 3
|
assert Number.objects.count() == 2
|
||||||
|
|
||||||
def test_one2one_simple(self):
|
def test_one2one_simple(self):
|
||||||
merge(self.a, self.c)
|
SSN.objects.create(person=self.a, number='1')
|
||||||
# move FKs pointing at A to C
|
merge(self.a, self.b)
|
||||||
#assert self.a.ssn is None
|
# move FKs pointing at A to B
|
||||||
c = Person.objects.get(pk=self.c.pk)
|
#TODO: assert self.a.ssn is None
|
||||||
c.ssn.number == 1
|
assert Person.objects.get(pk=self.b.pk).ssn.number == '1'
|
||||||
assert SSN.objects.count() == 2
|
assert SSN.objects.count() == 1
|
||||||
|
|
||||||
# TODO: test one2one when there's a conflict
|
# TODO: test one2one when there's a conflict
|
||||||
|
|
||||||
def test_many2many_simple(self):
|
def test_many2many_simple(self):
|
||||||
merge(self.a, self.c)
|
self.g.people.add(self.a)
|
||||||
# A's membership in G has been moved to C
|
merge(self.a, self.b)
|
||||||
assert self.g.people.all().count() == 2
|
# A's membership in G has been moved to B
|
||||||
|
assert self.g.people.get().name == self.b.name
|
||||||
assert self.a.groups.all().count() == 0
|
assert self.a.groups.all().count() == 0
|
||||||
assert self.c.groups.all().count() == 1
|
assert self.b.groups.all().count() == 1
|
||||||
|
|
||||||
def test_many2many_redundant(self):
|
def test_many2many_redundant(self):
|
||||||
|
self.g.people.add(self.a)
|
||||||
|
self.g.people.add(self.b)
|
||||||
merge(self.a, self.b)
|
merge(self.a, self.b)
|
||||||
# A's membership in G is redundant with B's
|
# A's membership in G is redundant with B's
|
||||||
assert self.g.people.all().count() == 1
|
assert self.g.people.all().count() == 1
|
||||||
assert self.a.groups.all().count() == 0
|
assert self.a.groups.all().count() == 0
|
||||||
assert self.b.groups.all().count() == 1
|
assert self.b.groups.all().count() == 1
|
||||||
|
|
||||||
def test_many2many_self(self):
|
def test_many2many_same_class(self):
|
||||||
self.a.friends.add(self.b)
|
f = Person.objects.create(name='friend')
|
||||||
merge(self.a, self.c)
|
self.a.friends.add(f)
|
||||||
import pdb; pdb.set_trace()
|
merge(self.a, self.b)
|
||||||
assert self.a.friends.all().count() == 0
|
assert self.a.friends.all().count() == 0
|
||||||
assert self.b.friends.get().name == self.c
|
assert self.b.friends.get().name == f.name
|
||||||
assert self.c.friends.get().name == self.b
|
assert f.get().name == self.b.name
|
||||||
|
Loading…
Reference in New Issue
Block a user