ness.tests

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import unittest
from ness.models import Foo
import ness
class NessTestCase(unittest.TestCase):
def setUp(self):
Foo.objects.all().delete()
def testAdd(self):
foo = Foo(name='first')
foo.save()
self.assert_(1 == Foo.objects.all().count())
foo = Foo.objects.get(name='first')
self.assertEqual(0,foo.ness_level)
self.assertEqual(0,foo.ness_left)
self.assertEqual(0,foo.ness_right)
foo = ness.add(foo)
self.assertEqual(1,foo.ness_left)
self.assertEqual(2,foo.ness_right)
self.assertEqual(1,foo.ness_level)
foo2 = Foo(name='second',parent=foo)
foo2.save()
foo2 = ness.add(foo2)
foo = Foo.objects.get(pk=foo.id)
self.assertEqual(1,foo.ness_left)
self.assertEqual(4,foo.ness_right)
self.assertEqual(1,foo.ness_level)
self.assertEqual(2,foo2.ness_left)
self.assertEqual(3,foo2.ness_right)
self.assertEqual(2,foo2.ness_level)
self.assertEqual(True,ness.test1(Foo))
self.assertEqual(True,ness.test2(Foo))
self.assertEqual(True,ness.test3(Foo))
self.assertEqual(True,ness.test4(Foo))
def testDelete(self):
foo = Foo(name='first')
foo.save()
foo = ness.add(foo)
foo2 = Foo(name='second',parent=foo)
foo2.save()
foo2 = ness.add(foo2)
foo3 = Foo(name='fird',parent=foo2)
foo3.save()
foo3 = ness.add(foo3)
foo4 = Foo(name='fourth',parent=foo)
foo4.save()
foo4 = ness.add(foo4)
ness.delete(foo2)
foo = Foo.objects.get(pk=foo.id)
foo4 = Foo.objects.get(pk=foo4.id)
self.assertEqual(2,Foo.objects.all().count())
self.assertEqual(1,foo.ness_left)
self.assertEqual(4,foo.ness_right)
self.assertEqual(2,foo4.ness_left)
self.assertEqual(3,foo4.ness_right)
self.assertEqual(True,ness.test1(Foo))
self.assertEqual(True,ness.test2(Foo))
self.assertEqual(True,ness.test3(Foo))
self.assertEqual(True,ness.test4(Foo))
def testChilds(self):
foo = Foo(name='first')
foo.save()
foo = ness.add(foo)
foo2 = Foo(name='second',parent=foo)
foo2.save()
foo2 = ness.add(foo2)
foo3 = Foo(name='fird',parent=foo2)
foo3.save()
foo3 = ness.add(foo3)
ids = [x.id for x in ness.childs(foo3)]
self.assertTrue(foo3.id not in ids)
self.assertTrue(foo2.id not in ids)
self.assertTrue(foo.id not in ids)
foo2 = Foo.objects.get(pk=foo2.id)
ids = [x.id for x in ness.childs(foo2)]
self.assertTrue(foo3.id in ids)
self.assertTrue(foo2.id not in ids)
self.assertTrue(foo.id not in ids)
foo = Foo.objects.get(pk=foo.id)
ids = [x.id for x in ness.childs(foo)]
self.assertTrue(foo3.id in ids)
self.assertTrue(foo2.id in ids)
self.assertTrue(foo.id not in ids)
def testChilds(self):
foo = Foo(name='first')
foo.save()
foo = ness.add(foo)
foo2 = Foo(name='second',parent=foo)
foo2.save()
foo2 = ness.add(foo2)
foo3 = Foo(name='fird',parent=foo2)
foo3.save()
foo3 = ness.add(foo3)
ids = [x.id for x in ness.parents(foo3)]
self.assertTrue(foo3.id not in ids)
self.assertTrue(foo2.id in ids)
self.assertTrue(foo.id in ids)
foo2 = Foo.objects.get(pk=foo2.id)
ids = [x.id for x in ness.parents(foo2)]
self.assertTrue(foo3.id not in ids)
self.assertTrue(foo2.id not in ids)
self.assertTrue(foo.id in ids)
foo = Foo.objects.get(pk=foo.id)
ids = [x.id for x in ness.parents(foo)]
self.assertTrue(foo3.id not in ids)
self.assertTrue(foo2.id not in ids)
self.assertTrue(foo.id not in ids)