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