5 from common import GET, PUT, POST, DELETE, OscTestCase
6 from xml.etree import cElementTree as ET
7 FIXTURES_DIR = os.path.join(os.getcwd(), 'repairwc_fixtures')
11 return unittest.makeSuite(TestRepairWC)
13 class TestRepairWC(OscTestCase):
14 def _get_fixtures_dir(self):
17 def __assertNotRaises(self, exception, meth, *args, **kwargs):
21 self.fail('%s raised' % exception.__name__)
23 def test_working_empty(self):
24 """consistent, empty working copy"""
25 self._change_to_pkg('working_empty')
26 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
28 def test_working_nonempty(self):
30 consistent, non-empty working copy. One file is in conflict,
31 one file is marked for deletion and one file has state 'A'
33 self._change_to_pkg('working_nonempty')
34 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
36 def test_buildfiles(self):
38 wc has a _buildconfig_prj_arch and a _buildinfo_prj_arch.xml in the storedir
40 self._change_to_pkg('buildfiles')
41 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
43 @GET('http://localhost/source/osctest/simple1/foo?rev=1', text='This is a simple test.\n')
44 def test_simple1(self):
45 """a file is marked for deletion but storefile doesn't exist"""
46 self._change_to_pkg('simple1')
47 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
48 p = osc.core.Package('.', wc_check=False)
50 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
51 self._check_deletelist('foo\n')
52 self._check_status(p, 'foo', 'D')
53 self._check_status(p, 'nochange', 'M')
54 self._check_status(p, 'merge', ' ')
55 self._check_status(p, 'toadd1', '?')
56 # additional cleanup check
57 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
59 def test_simple2(self):
60 """a file "somefile" exists in the storedir which isn't tracked"""
61 self._change_to_pkg('simple2')
62 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
63 p = osc.core.Package('.', wc_check=False)
65 self.assertFalse(os.path.exists(os.path.join('.osc', 'somefile')))
66 self._check_deletelist('foo\n')
67 self._check_status(p, 'foo', 'D')
68 self._check_status(p, 'nochange', 'M')
69 self._check_status(p, 'merge', ' ')
70 self._check_status(p, 'toadd1', '?')
71 # additional cleanup check
72 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
74 def test_simple3(self):
75 """toadd1 has state 'A' and a file .osc/toadd1 exists"""
76 self._change_to_pkg('simple3')
77 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
78 p = osc.core.Package('.', wc_check=False)
80 self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
81 self._check_deletelist('foo\n')
82 self._check_status(p, 'foo', 'D')
83 self._check_status(p, 'nochange', 'M')
84 self._check_status(p, 'merge', ' ')
85 self._check_addlist('toadd1\n')
86 self._check_status(p, 'toadd1', 'A')
87 # additional cleanup check
88 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
90 def test_simple4(self):
91 """a file is listed in _to_be_deleted but isn't present in _files"""
92 self._change_to_pkg('simple4')
93 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
94 p = osc.core.Package('.', wc_check=False)
96 self._check_deletelist('foo\n')
97 self._check_status(p, 'foo', 'D')
98 self._check_status(p, 'nochange', 'M')
99 self._check_status(p, 'merge', ' ')
100 self._check_status(p, 'toadd1', '?')
101 # additional cleanup check
102 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
104 def test_simple5(self):
105 """a file is listed in _in_conflict but isn't present in _files"""
106 self._change_to_pkg('simple5')
107 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
108 p = osc.core.Package('.', wc_check=False)
110 self.assertFalse(os.path.exists(os.path.join('.osc', '_in_conflict')))
111 self._check_deletelist('foo\n')
112 self._check_status(p, 'foo', 'D')
113 self._check_status(p, 'nochange', 'M')
114 self._check_status(p, 'merge', ' ')
115 self._check_status(p, 'toadd1', '?')
116 # additional cleanup check
117 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
119 @GET('http://localhost/source/osctest/simple6/foo?rev=1', text='This is a simple test.\n')
120 def test_simple6(self):
122 a file is listed in _to_be_deleted and is present
123 in _files but the storefile is missing
125 self._change_to_pkg('simple6')
126 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
127 p = osc.core.Package('.', wc_check=False)
129 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
130 self._check_deletelist('foo\n')
131 self._check_status(p, 'foo', 'D')
132 self._check_status(p, 'nochange', 'M')
133 self._check_status(p, 'merge', ' ')
134 self._check_status(p, 'toadd1', '?')
135 # additional cleanup check
136 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
138 def test_simple7(self):
139 """files marked as skipped don't exist in the storedir"""
140 self._change_to_pkg('simple7')
141 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
143 def test_simple8(self):
145 a file is marked as skipped but the skipped file exists in the storedir
147 self._change_to_pkg('simple8')
148 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
149 p = osc.core.Package('.', wc_check=False)
151 self.assertFalse(os.path.exists(os.path.join('.osc', 'skipped')))
152 self._check_deletelist('foo\n')
153 self._check_status(p, 'foo', 'D')
154 self._check_status(p, 'nochange', 'M')
155 self._check_status(p, 'merge', ' ')
156 self._check_status(p, 'toadd1', '?')
157 self._check_status(p, 'skipped', 'S')
158 # additional cleanup check
159 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
161 @GET('http://localhost/source/osctest/multiple/merge?rev=1', text='Is it\npossible to\nmerge this file?I hope so...\n')
162 @GET('http://localhost/source/osctest/multiple/nochange?rev=1', text='This file didn\'t change.\n')
163 def test_multiple(self):
165 a storefile is missing, a file is listed in _to_be_deleted
166 but is not present in _files, a file is listed in _in_conflict
167 but the storefile is missing and a file exists in the storedir
168 but is not present in _files
170 self._change_to_pkg('multiple')
171 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
172 p = osc.core.Package('.', wc_check=False)
174 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
175 self.assertFalse(os.path.exists(os.path.join('.osc', 'unknown_file')))
176 self._check_deletelist('foo\n')
177 self._check_status(p, 'foo', 'D')
178 self._check_status(p, 'nochange', 'C')
179 self._check_status(p, 'merge', ' ')
180 self._check_status(p, 'foobar', 'A')
181 self._check_status(p, 'toadd1', '?')
182 # additional cleanup check
183 self.__assertNotRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
185 def test_noapiurl(self):
186 """the package wc has no _apiurl file"""
187 self._change_to_pkg('noapiurl')
188 p = osc.core.Package('.', wc_check=False)
189 p.wc_repair('http://localhost')
190 self.assertTrue(os.path.exists(os.path.join('.osc', '_apiurl')))
191 self.assertEqual(open(os.path.join('.osc', '_apiurl')).read(), 'http://localhost\n')
192 self.assertEqual(p.apiurl, 'http://localhost')
194 def test_noapiurlNotExistingApiurl(self):
195 """the package wc has no _apiurl file and no apiurl is passed to repairwc"""
196 self._change_to_pkg('noapiurl')
197 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, osc.core.Package, '.')
198 p = osc.core.Package('.', wc_check=False)
199 self.assertRaises(osc.oscerr.WorkingCopyInconsistent, p.wc_repair)
200 self.assertFalse(os.path.exists(os.path.join('.osc', '_apiurl')))
202 if __name__ == '__main__':