1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 22:56:15 +01:00
github.com_openSUSE_osc/tests/test_init_package.py

82 lines
4.1 KiB
Python
Raw Normal View History

import osc.core
import osc.oscerr
import os
import sys
from common import GET, OscTestCase
FIXTURES_DIR = os.path.join(os.getcwd(), 'init_package_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestInitPackage)
class TestInitPackage(OscTestCase):
def _get_fixtures_dir(self):
return FIXTURES_DIR
def test_simple(self):
"""initialize a package dir"""
pac_dir = os.path.join(self.tmpdir, 'testpkg')
osc.core.Package.init_package('http://localhost', 'osctest', 'testpkg', pac_dir)
storedir = os.path.join(pac_dir, osc.core.store)
self.assertFalse(os.path.exists(os.path.join(storedir, '_meta_mode')))
self.assertFalse(os.path.exists(os.path.join(storedir, '_size_limit')))
self._check_list(os.path.join(storedir, '_project'), 'osctest\n')
self._check_list(os.path.join(storedir, '_package'), 'testpkg\n')
self._check_list(os.path.join(storedir, '_files'), '<directory />\n')
self._check_list(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
def test_limit_size(self):
"""initialize a package dir with limit_size parameter"""
pac_dir = os.path.join(self.tmpdir, 'testpkg')
osc.core.Package.init_package('http://localhost', 'osctest', 'testpkg', pac_dir, limit_size=42)
storedir = os.path.join(pac_dir, osc.core.store)
self.assertFalse(os.path.exists(os.path.join(storedir, '_meta_mode')))
self._check_list(os.path.join(storedir, '_size_limit'), '42\n')
self._check_list(os.path.join(storedir, '_project'), 'osctest\n')
self._check_list(os.path.join(storedir, '_package'), 'testpkg\n')
self._check_list(os.path.join(storedir, '_files'), '<directory />\n')
self._check_list(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
def test_meta_mode(self):
"""initialize a package dir with meta paramter"""
pac_dir = os.path.join(self.tmpdir, 'testpkg')
osc.core.Package.init_package('http://localhost', 'osctest', 'testpkg', pac_dir, meta=True)
storedir = os.path.join(pac_dir, osc.core.store)
self.assertFalse(os.path.exists(os.path.join(storedir, '_size_limit')))
self._check_list(os.path.join(storedir, '_meta_mode'), '')
self._check_list(os.path.join(storedir, '_project'), 'osctest\n')
self._check_list(os.path.join(storedir, '_package'), 'testpkg\n')
self._check_list(os.path.join(storedir, '_files'), '<directory />\n')
self._check_list(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
def test_dirExists(self):
"""initialize a package dir (dir already exists)"""
pac_dir = os.path.join(self.tmpdir, 'testpkg')
os.mkdir(pac_dir)
osc.core.Package.init_package('http://localhost', 'osctest', 'testpkg', pac_dir)
storedir = os.path.join(pac_dir, osc.core.store)
self.assertFalse(os.path.exists(os.path.join(storedir, '_meta_mode')))
self.assertFalse(os.path.exists(os.path.join(storedir, '_size_limit')))
self._check_list(os.path.join(storedir, '_project'), 'osctest\n')
self._check_list(os.path.join(storedir, '_package'), 'testpkg\n')
self._check_list(os.path.join(storedir, '_files'), '<directory />\n')
self._check_list(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
def test_storedirExists(self):
"""initialize a package dir (dir+storedir already exists)"""
pac_dir = os.path.join(self.tmpdir, 'testpkg')
os.mkdir(pac_dir)
os.mkdir(os.path.join(pac_dir, osc.core.store))
self.assertRaises(IOError, osc.core.Package.init_package, 'http://localhost', 'osctest', 'testpkg', pac_dir)
def test_dirIsFile(self):
"""initialize a package dir (dir is a file)"""
pac_dir = os.path.join(self.tmpdir, 'testpkg')
os.mkdir(pac_dir)
open(os.path.join(pac_dir, osc.core.store), 'w').write('foo\n')
self.assertRaises(IOError, osc.core.Package.init_package, 'http://localhost', 'osctest', 'testpkg', pac_dir)
if __name__ == '__main__':
import unittest
unittest.main()