1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
import osc.core
import osc.oscerr
import os
import sys
import urllib2
from common import GET, PUT, POST, DELETE, OscTestCase
from xml.etree import cElementTree as ET
#FIXTURES_DIR = os.path.join(os.getcwd(), 'commit_fixtures')
FIXTURES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'commit_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestCommit)
rev_dummy = '<revision rev="repository">\n <srcmd5>empty</srcmd5>\n</revision>'
class TestCommit(OscTestCase):
def _get_fixtures_dir(self):
return FIXTURES_DIR
@GET('http://localhost/source/osctest/simple?rev=latest', file='testSimple_filesremote')
@POST('http://localhost/source/osctest/simple?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
file='testSimple_missingfilelist', expfile='testSimple_lfilelist')
@PUT('http://localhost/source/osctest/simple/nochange?rev=repository',
exp='This file didn\'t change but\nis modified.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
file='testSimple_cfilesremote', expfile='testSimple_lfilelist')
def test_simple(self):
"""a simple commit (only one modified file)"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.commit()
exp = 'Sending nochange\nTransmitting file data .\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testSimple_cfilesremote')
self.assertTrue(os.path.exists('nochange'))
self.assertEqual(open('nochange', 'r').read(), open(os.path.join('.osc', 'nochange'), 'r').read())
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
@GET('http://localhost/source/osctest/add?rev=latest', file='testAddfile_filesremote')
@POST('http://localhost/source/osctest/add?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/add?comment=&cmd=commitfilelist&user=Admin',
file='testAddfile_missingfilelist', expfile='testAddfile_lfilelist')
@PUT('http://localhost/source/osctest/add/add?rev=repository',
exp='added file\n', text=rev_dummy)
@POST('http://localhost/source/osctest/add?comment=&cmd=commitfilelist&user=Admin',
file='testAddfile_cfilesremote', expfile='testAddfile_lfilelist')
def test_addfile(self):
"""commit a new file"""
self._change_to_pkg('add')
p = osc.core.Package('.')
p.commit()
exp = 'Sending add\nTransmitting file data .\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAddfile_cfilesremote')
self.assertTrue(os.path.exists('add'))
self.assertEqual(open('add', 'r').read(), open(os.path.join('.osc', 'add'), 'r').read())
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/delete?rev=latest', file='testDeletefile_filesremote')
@POST('http://localhost/source/osctest/delete?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/delete?comment=&cmd=commitfilelist&user=Admin',
file='testDeletefile_cfilesremote', expfile='testDeletefile_lfilelist')
def test_deletefile(self):
"""delete a file"""
self._change_to_pkg('delete')
p = osc.core.Package('.')
p.commit()
exp = 'Deleting nochange\nTransmitting file data \nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testDeletefile_cfilesremote')
self.assertFalse(os.path.exists('nochange'))
self.assertFalse(os.path.exists(os.path.join('.osc', 'nochange')))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
@GET('http://localhost/source/osctest/conflict?rev=latest', file='testConflictfile_filesremote')
@POST('http://localhost/source/osctest/conflict?cmd=getprojectservices',
exp='', text='<services />')
def test_conflictfile(self):
"""package has a file which is in conflict state"""
self._change_to_pkg('conflict')
ret = osc.core.Package('.').commit()
self.assertTrue(ret == 1)
exp = 'Please resolve all conflicts before committing using "osc resolved FILE"!\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testConflictfile_filesremote')
self._check_conflictlist('merge\n')
@GET('http://localhost/source/osctest/nochanges?rev=latest', file='testNoChanges_filesremote')
@POST('http://localhost/source/osctest/nochanges?cmd=getprojectservices',
exp='', text='<services />')
def test_nochanges(self):
"""package has no changes (which can be committed)"""
self._change_to_pkg('nochanges')
p = osc.core.Package('.')
ret = p.commit()
self.assertTrue(ret == 1)
exp = 'nothing to do for package nochanges\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_status(p, 'foo', 'S')
self._check_status(p, 'merge', '!')
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/multiple?rev=latest', file='testMultiple_filesremote')
@POST('http://localhost/source/osctest/multiple?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testMultiple_missingfilelist', expfile='testMultiple_lfilelist')
@PUT('http://localhost/source/osctest/multiple/nochange?rev=repository', exp='This file did change.\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/add?rev=repository', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/add2?rev=repository', exp='add2\n', text=rev_dummy)
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testMultiple_cfilesremote', expfile='testMultiple_lfilelist')
def test_multiple(self):
"""a simple commit (only one modified file)"""
self._change_to_pkg('multiple')
p = osc.core.Package('.')
p.commit()
exp = 'Deleting foo\nDeleting merge\nSending nochange\n' \
'Sending add\nSending add2\nTransmitting file data ...\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testMultiple_cfilesremote')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self.assertFalse(os.path.exists(os.path.join('.osc', 'foo')))
self.assertFalse(os.path.exists(os.path.join('.osc', 'merge')))
self.assertRaises(osc.oscerr.OscIOError, p.status, 'foo')
self.assertRaises(osc.oscerr.OscIOError, p.status, 'merge')
self._check_status(p, 'add', ' ')
self._check_status(p, 'add2', ' ')
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/multiple?rev=latest', file='testPartial_filesremote')
@POST('http://localhost/source/osctest/multiple?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testPartial_missingfilelist', expfile='testPartial_lfilelist')
@PUT('http://localhost/source/osctest/multiple/add?rev=repository', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/nochange?rev=repository', exp='This file did change.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testPartial_cfilesremote', expfile='testPartial_lfilelist')
def test_partial(self):
"""commit only some files"""
self._change_to_pkg('multiple')
p = osc.core.Package('.')
p.todo = ['foo', 'add', 'nochange']
p.commit()
exp = 'Deleting foo\nSending nochange\n' \
'Sending add\nTransmitting file data ..\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testPartial_cfilesremote')
self._check_addlist('add2\n')
self._check_deletelist('merge\n')
self._check_status(p, 'add2', 'A')
self._check_status(p, 'merge', 'D')
self._check_status(p, 'add', ' ')
self._check_status(p, 'nochange', ' ')
self.assertRaises(osc.oscerr.OscIOError, p.status, 'foo')
@GET('http://localhost/source/osctest/simple?rev=latest', file='testSimple_filesremote')
@POST('http://localhost/source/osctest/simple?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
file='testSimple_missingfilelist', expfile='testSimple_lfilelist')
@PUT('http://localhost/source/osctest/simple/nochange?rev=repository', exp='This file didn\'t change but\nis modified.\n',
exception=IOError('test exception'), text=rev_dummy)
def test_interrupt(self):
"""interrupt a commit"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
self.assertRaises(IOError, p.commit)
exp = 'Sending nochange\nTransmitting file data .'
self.assertTrue(sys.stdout.getvalue(), exp)
self._check_digests('testSimple_filesremote')
self.assertTrue(os.path.exists('nochange'))
self._check_status(p, 'nochange', 'M')
@GET('http://localhost/source/osctest/allstates?rev=latest', file='testPartial_filesremote')
@POST('http://localhost/source/osctest/allstates?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/allstates?comment=&cmd=commitfilelist&user=Admin',
file='testAllStates_missingfilelist', expfile='testAllStates_lfilelist')
@PUT('http://localhost/source/osctest/allstates/add?rev=repository', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/allstates/missing?rev=repository', exp='replaced\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/allstates/nochange?rev=repository', exp='This file did change.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/allstates?comment=&cmd=commitfilelist&user=Admin',
file='testAllStates_cfilesremote', expfile='testAllStates_lfilelist')
def test_allstates(self):
"""commit all files (all states are available except 'C')"""
self._change_to_pkg('allstates')
p = osc.core.Package('.')
p.commit()
exp = 'Deleting foo\nSending missing\nSending nochange\n' \
'Sending add\nTransmitting file data ...\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAllStates_expfiles', 'skipped')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self.assertFalse(os.path.exists('foo'))
self.assertFalse(os.path.exists(os.path.join('.osc', 'foo')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'merge', '!')
self._check_status(p, 'missing', ' ')
self._check_status(p, 'skipped', 'S')
self._check_status(p, 'test', ' ')
@GET('http://localhost/source/osctest/add?rev=latest', file='testAddfile_filesremote')
@POST('http://localhost/source/osctest/add?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/add?comment=&cmd=commitfilelist&user=Admin',
file='testAddfile_cfilesremote', expfile='testAddfile_lfilelist')
def test_remoteexists(self):
"""file 'add' should be committed but already exists on the server"""
self._change_to_pkg('add')
p = osc.core.Package('.')
p.commit()
exp = 'Sending add\nTransmitting file data \nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAddfile_cfilesremote')
self.assertTrue(os.path.exists('add'))
self.assertEqual(open('add', 'r').read(), open(os.path.join('.osc', 'add'), 'r').read())
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/branch?rev=latest', file='testExpand_filesremote')
@POST('http://localhost/source/osctest/branch?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/branch?comment=&cmd=commitfilelist&user=Admin&keeplink=1',
file='testExpand_missingfilelist', expfile='testExpand_lfilelist')
@PUT('http://localhost/source/osctest/branch/simple?rev=repository', exp='simple modified file.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/branch?comment=&cmd=commitfilelist&user=Admin&keeplink=1',
file='testExpand_cfilesremote', expfile='testExpand_lfilelist')
@GET('http://localhost/source/osctest/branch?rev=87ea02aede261b0267aabaa97c756e7a', file='testExpand_expandedfilesremote')
def test_expand(self):
"""commit an expanded package"""
self._change_to_pkg('branch')
p = osc.core.Package('.')
p.commit()
exp = 'Sending simple\nTransmitting file data .\nCommitted revision 7.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testExpand_expandedfilesremote')
self._check_status(p, 'simple', ' ')
@GET('http://localhost/source/osctest/added_missing?rev=latest', file='testAddedMissing_filesremote')
@POST('http://localhost/source/osctest/added_missing?cmd=getprojectservices',
exp='', text='<services />')
def test_added_missing(self):
"""commit an added file which is missing"""
self._change_to_pkg('added_missing')
p = osc.core.Package('.')
ret = p.commit()
self.assertTrue(ret == 1)
exp = 'file \'add\' is marked as \'A\' but does not exist\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_status(p, 'add', '!')
@GET('http://localhost/source/osctest/added_missing?rev=latest', file='testAddedMissing_filesremote')
@POST('http://localhost/source/osctest/added_missing?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/added_missing?comment=&cmd=commitfilelist&user=Admin',
file='testAddedMissing_missingfilelist', expfile='testAddedMissing_lfilelist')
@PUT('http://localhost/source/osctest/added_missing/bar?rev=repository', exp='foobar\n', text=rev_dummy)
@POST('http://localhost/source/osctest/added_missing?comment=&cmd=commitfilelist&user=Admin',
file='testAddedMissing_cfilesremote', expfile='testAddedMissing_lfilelist')
def test_added_missing2(self):
"""commit an added file, another added file missing (but it's not part of the commit)"""
self._change_to_pkg('added_missing')
p = osc.core.Package('.')
p.todo = ['bar']
p.commit()
exp = 'Sending bar\nTransmitting file data .\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_status(p, 'add', '!')
self._check_status(p, 'bar', ' ')
@GET('http://localhost/source/osctest/simple?rev=latest', file='testSimple_filesremote')
@POST('http://localhost/source/osctest/simple?cmd=getprojectservices',
exp='', text='<services />')
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
file='testSimple_missingfilelist', expfile='testSimple_lfilelist')
@PUT('http://localhost/source/osctest/simple/nochange?rev=repository',
exp='This file didn\'t change but\nis modified.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
expfile='testSimple_lfilelist', text='an error occured', code=500)
def test_commitfilelist_error(self):
"""commit modified file but when committing the filelist the server returns status 500 (see ticket #65)"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
self._check_status(p, 'nochange', 'M')
self.assertRaises(urllib2.HTTPError, p.commit)
exp = 'Sending nochange\nTransmitting file data .'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_status(p, 'nochange', 'M')
if __name__ == '__main__':
import unittest
unittest.main()
|