2022-07-28 12:28:33 +02:00
|
|
|
import os
|
2022-09-09 11:46:28 +02:00
|
|
|
import unittest
|
2022-07-28 12:28:33 +02:00
|
|
|
|
2022-09-09 11:46:28 +02:00
|
|
|
import osc.conf
|
2010-10-09 16:25:44 +02:00
|
|
|
import osc.core
|
|
|
|
import osc.oscerr
|
2022-07-28 12:28:33 +02:00
|
|
|
|
2022-02-17 13:28:47 +01:00
|
|
|
from .common import GET, OscTestCase
|
2022-07-28 12:28:33 +02:00
|
|
|
|
|
|
|
|
2022-02-17 13:28:47 +01:00
|
|
|
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'init_project_fixtures')
|
2010-10-09 16:25:44 +02:00
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-10-09 16:25:44 +02:00
|
|
|
def suite():
|
2022-07-28 19:11:29 +02:00
|
|
|
return unittest.defaultTestLoader.loadTestsFromTestCase(TestInitProject)
|
2010-10-09 16:25:44 +02:00
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-10-09 16:25:44 +02:00
|
|
|
class TestInitProject(OscTestCase):
|
|
|
|
def _get_fixtures_dir(self):
|
|
|
|
# workaround for git because it doesn't allow empty dirs
|
|
|
|
if not os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')):
|
|
|
|
os.mkdir(os.path.join(FIXTURES_DIR, 'osctest'))
|
|
|
|
return FIXTURES_DIR
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
if os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')):
|
|
|
|
os.rmdir(os.path.join(FIXTURES_DIR, 'osctest'))
|
2022-08-31 11:46:12 +02:00
|
|
|
super().tearDown()
|
2010-10-09 16:25:44 +02:00
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
"""initialize a project dir"""
|
|
|
|
prj_dir = os.path.join(self.tmpdir, 'testprj')
|
2010-12-23 02:15:58 +01:00
|
|
|
prj = osc.core.Project.init_project('http://localhost', prj_dir, 'testprj', getPackageList=False)
|
|
|
|
self.assertTrue(isinstance(prj, osc.core.Project))
|
2010-10-09 16:25:44 +02:00
|
|
|
storedir = os.path.join(prj_dir, osc.core.store)
|
|
|
|
self._check_list(os.path.join(storedir, '_project'), 'testprj\n')
|
|
|
|
self._check_list(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
|
|
|
|
self._check_list(os.path.join(storedir, '_packages'), '<project name="testprj" />')
|
|
|
|
|
|
|
|
def test_dirExists(self):
|
|
|
|
"""initialize a project dir but the dir already exists"""
|
|
|
|
prj_dir = os.path.join(self.tmpdir, 'testprj')
|
|
|
|
os.mkdir(prj_dir)
|
2010-12-23 02:15:58 +01:00
|
|
|
prj = osc.core.Project.init_project('http://localhost', prj_dir, 'testprj', getPackageList=False)
|
|
|
|
self.assertTrue(isinstance(prj, osc.core.Project))
|
2010-10-09 16:25:44 +02:00
|
|
|
storedir = os.path.join(prj_dir, osc.core.store)
|
|
|
|
self._check_list(os.path.join(storedir, '_project'), 'testprj\n')
|
|
|
|
self._check_list(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
|
|
|
|
self._check_list(os.path.join(storedir, '_packages'), '<project name="testprj" />')
|
|
|
|
|
|
|
|
def test_storedirExists(self):
|
|
|
|
"""initialize a project dir but the storedir already exists"""
|
|
|
|
prj_dir = os.path.join(self.tmpdir, 'testprj')
|
|
|
|
os.mkdir(prj_dir)
|
|
|
|
os.mkdir(os.path.join(prj_dir, osc.core.store))
|
|
|
|
self.assertRaises(osc.oscerr.OscIOError, osc.core.Project.init_project, 'http://localhost', prj_dir, 'testprj')
|
|
|
|
|
2010-12-23 02:15:58 +01:00
|
|
|
@GET('http://localhost/source/testprj', text='<directory count="0" />')
|
2010-10-09 16:25:44 +02:00
|
|
|
def test_no_package_tracking(self):
|
2010-12-23 02:15:58 +01:00
|
|
|
"""initialize a project dir but disable package tracking; enable getPackageList=True;
|
|
|
|
disable wc_check (because we didn't disable the package tracking before the Project class
|
|
|
|
was imported therefore REQ_STOREFILES contains '_packages')
|
|
|
|
"""
|
|
|
|
# disable package tracking
|
|
|
|
osc.conf.config['do_package_tracking'] = False
|
2010-10-09 16:25:44 +02:00
|
|
|
prj_dir = os.path.join(self.tmpdir, 'testprj')
|
|
|
|
os.mkdir(prj_dir)
|
2010-12-23 02:15:58 +01:00
|
|
|
prj = osc.core.Project.init_project('http://localhost', prj_dir, 'testprj', False, wc_check=False)
|
|
|
|
self.assertTrue(isinstance(prj, osc.core.Project))
|
2010-10-09 16:25:44 +02:00
|
|
|
storedir = os.path.join(prj_dir, osc.core.store)
|
|
|
|
self._check_list(os.path.join(storedir, '_project'), 'testprj\n')
|
|
|
|
self._check_list(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
|
|
|
|
self.assertFalse(os.path.exists(os.path.join(storedir, '_packages')))
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-10-09 16:25:44 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|