2010-08-24 18:06:47 +02:00
|
|
|
import osc.core
|
|
|
|
import osc.oscerr
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from common import GET, OscTestCase
|
|
|
|
|
|
|
|
FIXTURES_DIR = os.path.join(os.getcwd(), 'addfile_fixtures')
|
|
|
|
|
2010-08-24 18:59:31 +02:00
|
|
|
def suite():
|
|
|
|
import unittest
|
|
|
|
return unittest.makeSuite(TestAddFiles)
|
|
|
|
|
2010-08-24 18:06:47 +02:00
|
|
|
class TestAddFiles(OscTestCase):
|
|
|
|
def _get_fixtures_dir(self):
|
|
|
|
return FIXTURES_DIR
|
|
|
|
|
|
|
|
def testSimpleAdd(self):
|
|
|
|
"""add one file ('toadd1') to the wc"""
|
|
|
|
self._change_to_pkg('simple')
|
|
|
|
p = osc.core.Package('.')
|
|
|
|
p.addfile('toadd1')
|
|
|
|
exp = 'A toadd1\n'
|
|
|
|
self.assertEqual(sys.stdout.getvalue(), exp)
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
|
|
|
|
self._check_status(p, 'toadd1', 'A')
|
2010-08-25 11:20:25 +02:00
|
|
|
self._check_addlist('toadd1\n')
|
2010-08-24 18:06:47 +02:00
|
|
|
|
|
|
|
def testSimpleMultipleAdd(self):
|
|
|
|
"""add multiple files ('toadd1', 'toadd2') to the wc"""
|
|
|
|
self._change_to_pkg('simple')
|
|
|
|
p = osc.core.Package('.')
|
|
|
|
p.addfile('toadd1')
|
|
|
|
p.addfile('toadd2')
|
|
|
|
exp = 'A toadd1\nA toadd2\n'
|
|
|
|
self.assertEqual(sys.stdout.getvalue(), exp)
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd2')))
|
|
|
|
self._check_status(p, 'toadd1', 'A')
|
|
|
|
self._check_status(p, 'toadd2', 'A')
|
2010-08-25 11:20:25 +02:00
|
|
|
self._check_addlist('toadd1\ntoadd2\n')
|
2010-08-24 18:06:47 +02:00
|
|
|
|
|
|
|
def testAddVersionedFile(self):
|
|
|
|
"""add a versioned file"""
|
|
|
|
self._change_to_pkg('simple')
|
|
|
|
p = osc.core.Package('.')
|
|
|
|
self.assertRaises(osc.oscerr.PackageFileConflict, p.addfile, 'merge')
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
|
|
|
|
self._check_status(p, 'merge', ' ')
|
|
|
|
|
|
|
|
def testAddUnversionedFileTwice(self):
|
|
|
|
"""add the same file twice"""
|
|
|
|
self._change_to_pkg('simple')
|
|
|
|
p = osc.core.Package('.')
|
|
|
|
p.addfile('toadd1')
|
|
|
|
self.assertRaises(osc.oscerr.PackageFileConflict, p.addfile, 'toadd1')
|
|
|
|
exp = 'A toadd1\n'
|
|
|
|
self.assertEqual(sys.stdout.getvalue(), exp)
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
|
|
|
|
self._check_status(p, 'toadd1', 'A')
|
2010-08-25 11:20:25 +02:00
|
|
|
self._check_addlist('toadd1\n')
|
2010-08-24 18:06:47 +02:00
|
|
|
|
|
|
|
def testReplace(self):
|
|
|
|
"""replace a deleted file ('foo')"""
|
|
|
|
self._change_to_pkg('simple')
|
|
|
|
p = osc.core.Package('.')
|
|
|
|
open('foo', 'w').write('replaced file\n')
|
|
|
|
p.addfile('foo')
|
|
|
|
exp = 'A foo\n'
|
|
|
|
self.assertEqual(sys.stdout.getvalue(), exp)
|
|
|
|
self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
|
|
|
|
self.assertNotEqual(open(os.path.join('.osc', 'foo'), 'r').read(), 'replaced file\n')
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
|
|
|
|
self._check_status(p, 'foo', 'R')
|
2010-08-25 11:20:25 +02:00
|
|
|
self._check_addlist('foo\n')
|
2010-08-24 18:06:47 +02:00
|
|
|
|
|
|
|
def testAddNonExistentFile(self):
|
|
|
|
"""add a non existent file"""
|
|
|
|
self._change_to_pkg('simple')
|
|
|
|
p = osc.core.Package('.')
|
2010-09-02 10:23:37 +02:00
|
|
|
self.assertRaises(osc.oscerr.OscIOError, p.addfile, 'doesnotexist')
|
2010-08-24 18:06:47 +02:00
|
|
|
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import unittest
|
|
|
|
unittest.main()
|