- added testsuite module which aggregates all testcases
[opensuse:osc.git] / tests / test_addfiles.py
1 import osc.core
2 import osc.oscerr
3 import os
4 import sys
5 from common import GET, OscTestCase
6
7 FIXTURES_DIR = os.path.join(os.getcwd(), 'addfile_fixtures')
8
9 def suite():
10     import unittest
11     return unittest.makeSuite(TestAddFiles)
12
13 class TestAddFiles(OscTestCase):
14     def _get_fixtures_dir(self):
15         return FIXTURES_DIR
16
17     def testSimpleAdd(self):
18         """add one file ('toadd1') to the wc"""
19         self._change_to_pkg('simple')
20         p = osc.core.Package('.')
21         p.addfile('toadd1')
22         exp = 'A    toadd1\n'
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')
27
28     def testSimpleMultipleAdd(self):
29         """add multiple files ('toadd1', 'toadd2') to the wc"""
30         self._change_to_pkg('simple')
31         p = osc.core.Package('.')
32         p.addfile('toadd1')
33         p.addfile('toadd2')
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')
41
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', ' ')
49
50     def testAddUnversionedFileTwice(self):
51         """add the same file twice"""
52         self._change_to_pkg('simple')
53         p = osc.core.Package('.')
54         p.addfile('toadd1')
55         self.assertRaises(osc.oscerr.PackageFileConflict, p.addfile, 'toadd1')
56         exp = 'A    toadd1\n'
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')
61
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')
67         p.addfile('foo')
68         exp = 'A    foo\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')
75
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')))
82
83     def __check_addlist(self, exp):
84         self._check_list('_to_be_added', exp)
85
86 if __name__ == '__main__':
87     import unittest
88     unittest.main()