1 from nose.tools import *
2 from django.test import TestCase
3 from dvcs.models import Document
6 class ADocument(Document):
11 class DocumentModelTests(TestCase):
13 def assertTextEqual(self, given, expected):
14 return self.assertEqual(given, expected,
15 "Expected '''%s'''\n differs from text: '''%s'''" % (expected, given)
18 def test_empty_file(self):
19 doc = ADocument.objects.create()
20 self.assertTextEqual(doc.materialize(), u"")
22 def test_single_commit(self):
23 doc = ADocument.objects.create()
24 doc.commit(text=u"Ala ma kota", description="Commit #1")
25 self.assertTextEqual(doc.materialize(), u"Ala ma kota")
27 def test_chained_commits(self):
28 doc = ADocument.objects.create()
43 c1 = doc.commit(description="Commit #1", text=text1)
44 c2 = doc.commit(description="Commit #2", text=text2)
45 c3 = doc.commit(description="Commit #3", text=text3)
47 self.assertTextEqual(doc.materialize(), text3)
48 self.assertTextEqual(doc.materialize(change=c3), text3)
49 self.assertTextEqual(doc.materialize(change=c2), text2)
50 self.assertTextEqual(doc.materialize(change=c1), text1)
52 def test_parallel_commit_noconflict(self):
53 doc = ADocument.objects.create()
73 base = doc.commit(description="Commit #1", text=text1)
74 c1 = doc.commit(description="Commit #2", text=text2)
75 commits = doc.change_set.count()
76 c2 = doc.commit(description="Commit #3", text=text3, parent=base)
77 self.assertEqual(doc.change_set.count(), commits + 2,
78 u"Parallel commits should create an additional merge commit")
79 self.assertTextEqual(doc.materialize(), text_merged)
81 def test_parallel_commit_conflict(self):
82 doc = ADocument.objects.create()
107 base = doc.commit(description="Commit #1", text=text1)
108 c1 = doc.commit(description="Commit #2", text=text2)
109 commits = doc.change_set.count()
110 c2 = doc.commit(description="Commit #3", text=text3, parent=base)
111 self.assertEqual(doc.change_set.count(), commits + 2,
112 u"Parallel commits should create an additional merge commit")
113 self.assertTextEqual(doc.materialize(), text_merged)
116 def test_multiple_parallel_commits(self):
154 doc = ADocument.objects.create()
155 c1 = doc.commit(description="Commit A1", text=text_a1)
156 c2 = doc.commit(description="Commit A2", text=text_a2, parent=c1)
157 c3 = doc.commit(description="Commit B1", text=text_b1, parent=c1)
158 c4 = doc.commit(description="Commit C1", text=text_c1, parent=c1)
159 self.assertTextEqual(doc.materialize(), text_merged)