"Try again" button in error panel.
[redakcja.git] / lib / wlrepo / tests / test_mercurial.py
1 # -*- encoding: utf-8 -*-
2
3 __author__= "Łukasz Rekucki"
4 __date__ = "$2009-09-18 14:43:27$"
5 __doc__ = "Tests for RAL mercurial backend."
6
7 from nose.tools import *
8
9 import wlrepo
10 from wlrepo import MercurialLibrary
11 from wlrepo.backend_mercurial import *
12
13 import os, os.path, tempfile
14 import shutil
15
16 REPO_TEMPLATES = os.path.join( os.path.dirname(__file__), 'data/repos')
17 ROOT_PATH = None
18
19 class testBasicLibrary(object):
20
21     def setUp(self):
22         self.path = tempfile.mkdtemp("", "testdir_" )
23         print self.path
24         for subdir in os.listdir(REPO_TEMPLATES):
25             shutil.copytree(REPO_TEMPLATES + '/' + subdir, self.path + '/' + subdir, False)
26
27     def tearDown(self):        
28         if self.path is not None:
29             shutil.rmtree(self.path, True)
30         pass
31    
32     def testOpening(self):
33         library = MercurialLibrary(self.path + '/cleanrepo')
34
35     def testMainCabinet(self):
36         library = MercurialLibrary(self.path + '/cleanrepo')
37
38         mcab = library.main_cabinet
39         assert_equal(mcab.maindoc_name(), '')
40
41         # @type mcab MercurialCabinet
42         doclist = mcab.documents()
43         assert_equal( list(doclist), ['valid_file'])
44
45
46     def testReadDocument(self):
47         library = MercurialLibrary(self.path + '/testrepoI')
48         doc = library.main_cabinet.retrieve('valid_file')
49         
50         assert_equal(doc.read().strip(), 'Ala ma kota')
51
52     def testReadUTF8Document(self):
53         library = MercurialLibrary(self.path + '/testrepoI')
54         doc = library.main_cabinet.retrieve('polish_file')
55
56         assert_equal(doc.read().strip(), u'Gąska!'.encode('utf-8'))
57
58     def testWriteDocument(self):
59         library = MercurialLibrary(self.path + '/testrepoI')
60         doc = library.main_cabinet.retrieve('valid_file')
61
62         assert_equal(doc.read().strip(), 'Ala ma kota')
63         
64         STRING = u'Gąski lubią pływać!\n'.encode('utf-8')
65         doc.write(STRING)       
66         
67         assert_equal(doc.read(), STRING)
68
69     def testCreateDocument(self):
70         repopath = os.path.join(self.path, 'testrepoI')
71
72         library = MercurialLibrary(repopath)
73         doc = library.main_cabinet.create("another_file")
74         doc.write("Some text")
75         assert_equal( doc.read(), "Some text")
76         assert_true( os.path.isfile( os.path.join(repopath, "pub_another_file.xml")) )
77         
78     def testSwitchBranch(self):
79         library = MercurialLibrary(self.path + '/testrepoII')
80
81         tester_cab = library.cabinet("valid_file", "tester", create=False)
82         assert_equal( list(tester_cab.documents()), ['valid_file'])
83
84     @raises(wlrepo.CabinetNotFound)
85     def testNoBranch(self):
86         library = MercurialLibrary(self.path + '/testrepoII')
87         tester_cab = library.cabinet("ugh", "tester", create=False)
88
89
90     def testCreateBranch(self):
91         repopath = os.path.join(self.path, 'testrepoII')
92         library = MercurialLibrary(repopath)
93
94         tester_cab = library.cabinet("anotherone", "tester", create=True)       
95         assert_equal( list(tester_cab.documents()), ['anotherone'])
96
97         
98
99