1 from django.test import TestCase
2 from dvcs.models import Change, Document
3 from django.contrib.auth.models import User
5 class DocumentModelTests(TestCase):
8 self.user = User.objects.create_user("tester", "tester@localhost.local")
10 def assertTextEqual(self, given, expected):
11 return self.assertEqual(given, expected,
12 "Expected '''%s'''\n differs from text: '''%s'''" % (expected, given)
15 def test_empty_file(self):
16 doc = Document.objects.create(name=u"Sample Document", creator=self.user)
17 self.assert_(doc.head is not None)
18 self.assertEqual(doc.materialize(), u"")
20 def test_single_commit(self):
21 doc = Document.objects.create(name=u"Sample Document", creator=self.user)
22 doc.commit(text=u"Ala ma kota", description="Commit #1", author=self.user)
23 self.assert_(doc.head is not None)
24 self.assertEqual(doc.change_set.count(), 2)
25 self.assertEqual(doc.materialize(), u"Ala ma kota")
27 def test_chained_commits(self):
28 doc = Document.objects.create(name=u"Sample Document", creator=self.user)
29 c1 = doc.commit(description="Commit #1", text=u"""
32 """, author=self.user)
33 c2 = doc.commit(description="Commit #2", text=u"""
36 """, author=self.user)
37 c3 = doc.commit(description="Commit #3", text=u"""
41 """, author=self.user)
42 self.assert_(doc.head is not None)
43 self.assertEqual(doc.change_set.count(), 4)
45 self.assertEqual(doc.materialize(), u"""
50 self.assertEqual(doc.materialize(version=c3), u"""
55 self.assertEqual(doc.materialize(version=c2), u"""
59 self.assertEqual(doc.materialize(version=c1), """
65 def test_parallel_commit_noconflict(self):
66 doc = Document.objects.create(name=u"Sample Document", creator=self.user)
67 self.assert_(doc.head is not None)
69 base = doc.commit(description="Commit #1", text=u"""
72 """, author=self.user)
74 c1 = doc.commit(description="Commit #2", text=u"""
77 """, parent=base, author=self.user)
78 self.assertTextEqual(c1.materialize(), u"""
82 c2 = doc.commit(description="Commit #3", text=u"""
86 """, parent=base, author=self.user)
87 self.assertEqual(doc.change_set.count(), 5)
88 self.assertTextEqual(doc.materialize(), u"""
94 def test_parallel_commit_conflict(self):
95 doc = Document.objects.create(name=u"Sample Document", creator=self.user)
96 self.assert_(doc.head is not None)
98 base = doc.commit(description="Commit #1", text=u"""
102 """, author=self.user)
104 c1 = doc.commit(description="Commit #2", text=u"""
108 """, parent=base, author=self.user)
109 c2 = doc.commit(description="Commit #3", text=u"""
113 """, parent=base, author=self.user)
114 self.assertEqual(doc.change_set.count(), 5)
115 self.assertTextEqual(doc.materialize(), u"""
125 def test_multiply_parallel_commits(self):
126 doc = Document.objects.create(name=u"Sample Document", creator=self.user)
127 self.assert_(doc.head is not None)
128 c1 = doc.commit(description="Commit A1", text=u"""
134 """, author=self.user)
135 c2 = doc.commit(description="Commit A2", text=u"""
141 """, author=self.user)
142 c3 = doc.commit(description="Commit B1", text=u"""
148 """, parent=c1, author=self.user)
149 c4 = doc.commit(description="Commit C1", text=u"""
155 """, parent=c2, author=self.user)
156 self.assertEqual(doc.change_set.count(), 7)
157 self.assertTextEqual(doc.materialize(), u"""