5 from common import GET, OscTestCase
7 FIXTURES_DIR = os.path.join(os.getcwd(), 'addfile_fixtures')
11 return unittest.makeSuite(TestAddFiles)
13 class TestAddFiles(OscTestCase):
14 def _get_fixtures_dir(self):
17 def testSimpleAdd(self):
18 """add one file ('toadd1') to the wc"""
19 self._change_to_pkg('simple')
20 p = osc.core.Package('.')
23 self.assertEqual(sys.stdout.getvalue(), exp)
24 self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
25 self._check_status(p, 'toadd1', 'A')
26 self.__check_addlist('toadd1\n')
28 def testSimpleMultipleAdd(self):
29 """add multiple files ('toadd1', 'toadd2') to the wc"""
30 self._change_to_pkg('simple')
31 p = osc.core.Package('.')
34 exp = 'A toadd1\nA toadd2\n'
35 self.assertEqual(sys.stdout.getvalue(), exp)
36 self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
37 self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd2')))
38 self._check_status(p, 'toadd1', 'A')
39 self._check_status(p, 'toadd2', 'A')
40 self.__check_addlist('toadd1\ntoadd2\n')
42 def testAddVersionedFile(self):
43 """add a versioned file"""
44 self._change_to_pkg('simple')
45 p = osc.core.Package('.')
46 self.assertRaises(osc.oscerr.PackageFileConflict, p.addfile, 'merge')
47 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
48 self._check_status(p, 'merge', ' ')
50 def testAddUnversionedFileTwice(self):
51 """add the same file twice"""
52 self._change_to_pkg('simple')
53 p = osc.core.Package('.')
55 self.assertRaises(osc.oscerr.PackageFileConflict, p.addfile, 'toadd1')
57 self.assertEqual(sys.stdout.getvalue(), exp)
58 self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
59 self._check_status(p, 'toadd1', 'A')
60 self.__check_addlist('toadd1\n')
62 def testReplace(self):
63 """replace a deleted file ('foo')"""
64 self._change_to_pkg('simple')
65 p = osc.core.Package('.')
66 open('foo', 'w').write('replaced file\n')
69 self.assertEqual(sys.stdout.getvalue(), exp)
70 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
71 self.assertNotEqual(open(os.path.join('.osc', 'foo'), 'r').read(), 'replaced file\n')
72 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
73 self._check_status(p, 'foo', 'R')
74 self.__check_addlist('foo\n')
76 def testAddNonExistentFile(self):
77 """add a non existent file"""
78 self._change_to_pkg('simple')
79 p = osc.core.Package('.')
80 self.assertRaises(IOError, p.addfile, 'doesnotexist')
81 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
83 def __check_addlist(self, exp):
84 self._check_list('_to_be_added', exp)
86 if __name__ == '__main__':