Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 39 additions & 34 deletions lib/rift/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,44 @@ def action_sync(args, config):
)
synchronizer.run()

def action_create_import(args, config):
"""Action for 'create', 'import' and 'reimport' commands."""
if args.command == 'create':
pkgname = args.name
elif args.command in ('import', 'reimport'):
rpm = RPM(args.file, config)
if not rpm.is_source:
raise RiftError(f"{args.file} is not a source RPM")
pkgname = rpm.name

if args.maintainer is None:
raise RiftError("You must specify a maintainer")

pkg = Package(pkgname, config, *staff_modules(config))
if args.command == 'reimport':
pkg.load()

if args.module:
pkg.module = args.module
if args.maintainer not in pkg.maintainers:
pkg.maintainers.append(args.maintainer)
if args.reason:
pkg.reason = args.reason
if args.origin:
pkg.origin = args.origin

pkg.check_info()
pkg.write()

if args.command in ('create', 'import'):
message(f"Package '{pkg.name}' has been created")

if args.command in ('import', 'reimport'):
rpm.extract_srpm(pkg.dir, pkg.sourcesdir)
message(f"Package '{pkg.name}' has been {args.command}ed")

return 0

def create_staging_repo(config):
"""
Create and return staging temporary repository with a 2-tuple containing
Expand Down Expand Up @@ -1049,40 +1087,7 @@ def action(config, args):

# CREATE/IMPORT/REIMPORT
if args.command in ['create', 'import', 'reimport']:

if args.command == 'create':
pkgname = args.name
elif args.command in ('import', 'reimport'):
rpm = RPM(args.file, config)
if not rpm.is_source:
raise RiftError(f"{args.file} is not a source RPM")
pkgname = rpm.name

if args.maintainer is None:
raise RiftError("You must specify a maintainer")

pkg = Package(pkgname, config, *staff_modules(config))
if args.command == 'reimport':
pkg.load()

if args.module:
pkg.module = args.module
if args.maintainer not in pkg.maintainers:
pkg.maintainers.append(args.maintainer)
if args.reason:
pkg.reason = args.reason
if args.origin:
pkg.origin = args.origin

pkg.check_info()
pkg.write()

if args.command in ('create', 'import'):
message(f"Package '{pkg.name}' has been created")

if args.command in ('import', 'reimport'):
rpm.extract_srpm(pkg.dir, pkg.sourcesdir)
message(f"Package '{pkg.name}' has been {args.command}ed")
return action_create_import(args, config)

# BUILD
elif args.command == 'build':
Expand Down
141 changes: 140 additions & 1 deletion tests/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
make_parser,
)
from rift.Package import Package
from rift.RPM import RPM
from rift.RPM import RPM, Spec
from rift.run import RunResult
from rift import RiftError

Expand All @@ -44,6 +44,145 @@ def test_main_version(self):
self.assert_except(SystemExit, "0", main, ['--version'])


class ControllerProjectActionCreateTest(RiftProjectTestCase):
"""
Tests class for Controller action create
"""

def test_create_missing_pkg_module_reason(self):
"""create without package, module or reason fails"""
for cmd in (['create', '-m', 'Great module', '-r', 'Good reason'],
['create', 'pkg', '-r', 'Good reason'],
['create', 'pkg', '-m', 'Great module']):
with self.assertRaisesRegex(SystemExit, "2"):
main(cmd)

def test_create_missing_maintainer(self):
"""create without maintainer"""
with self.assertRaisesRegex(RiftError, "You must specify a maintainer"):
main(['create', 'pkg', '-m', 'Great module', '-r', 'Good reason'])

def test_create(self):
"""simple create"""
main(['create', 'pkg', '-m', 'Great module', '-r', 'Good reason',
'--maintainer', 'Myself'])
pkg = Package('pkg', self.config, self.staff, self.modules)
pkg.load()
self.assertEqual(pkg.module, 'Great module')
self.assertEqual(pkg.reason, 'Good reason')
self.assertCountEqual(pkg.maintainers, ['Myself'])
os.unlink(pkg.metafile)
os.rmdir(os.path.dirname(pkg.metafile))

def test_create_unknown_maintainer(self):
"""create with unknown maintainer fails"""
with self.assertRaisesRegex(
RiftError, "Maintainer 'Fail' is not defined"):
main(['create', 'pkg', '-m', 'Great module', '-r', 'Good reason',
'--maintainer', 'Fail'])


class ControllerProjectActionImportTest(RiftProjectTestCase):
"""
Tests class for Controller action import
"""
@property
def src_rpm(self):
return os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'materials', 'pkg-1.0-1.src.rpm'
)

@property
def bin_rpm(self):
return os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'materials', 'pkg-1.0-1.noarch.rpm'
)

def test_import_missing_pkg_module_reason(self):
"""import without package, module or reason fails"""
for cmd in (['import', '-m', 'Great module', '-r', 'Good reason'],
['import', 'pkg.src.rpm', '-r', 'Good reason'],
['import', 'pkg.src.rpm', '-m', 'Great module']):
with self.assertRaisesRegex(SystemExit, "2"):
main(cmd)

def test_import_missing_maintainer(self):
"""import without maintainer"""
with self.assertRaisesRegex(RiftError, "You must specify a maintainer"):
main(['import', self.src_rpm, '-m', 'Great module', '-r', 'Good reason'])

def test_import_bin_rpm(self):
"""import binary rpm"""
with self.assertRaisesRegex(
RiftError,
".*pkg-1.0-1.noarch.rpm is not a source RPM$"):
main(['import', self.bin_rpm, '-m', 'Great module',
'-r', 'Good reason', '--maintainer', 'Myself'])

def test_import(self):
"""simple import"""
main(['import', self.src_rpm, '-m', 'Great module', '-r', 'Good reason',
'--maintainer', 'Myself'])
pkg = Package('pkg', self.config, self.staff, self.modules)
pkg.load()
self.assertEqual(pkg.module, 'Great module')
self.assertEqual(pkg.reason, 'Good reason')
self.assertCountEqual(pkg.maintainers, ['Myself'])
spec = Spec(filepath=pkg.specfile)
spec.load()
self.assertEqual(spec.changelog_name, 'Myself <[email protected]> - 1.0-1')
self.assertEqual(spec.version, '1.0')
self.assertEqual(spec.release, '1')
self.assertTrue(os.path.exists(f"{pkg.specfile}.orig"))
shutil.rmtree(os.path.dirname(pkg.metafile))

def test_import_unknown_maintainer(self):
"""import with unknown maintainer fails"""
with self.assertRaisesRegex(
RiftError, "Maintainer 'Fail' is not defined"):
main(['import', self.src_rpm, '-m', 'Great module',
'-r', 'Good reason', '--maintainer', 'Fail'])


class ControllerProjectActionReimportTest(RiftProjectTestCase):
"""
Tests class for Controller actionre import
"""
@property
def src_rpm(self):
return os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'materials', 'pkg-1.0-1.src.rpm'
)

@property
def bin_rpm(self):
return os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'materials', 'pkg-1.0-1.noarch.rpm'
)

def test_reimport_missing_maintainer(self):
"""reimport without maintainer"""
with self.assertRaisesRegex(RiftError, "You must specify a maintainer"):
main(['reimport', self.src_rpm, '-m', 'Great module', '-r', 'Good reason'])

def test_reimport(self):
"""simple reimport"""
self.make_pkg(name='pkg')
main(['reimport', self.src_rpm, '--maintainer', 'Myself'])
pkg = Package('pkg', self.config, self.staff, self.modules)
pkg.load()
self.assertEqual(pkg.module, 'Great module')
self.assertEqual(pkg.reason, 'Missing feature')
self.assertCountEqual(pkg.maintainers, ['Myself'])
spec = Spec(filepath=pkg.specfile)
spec.load()
self.assertEqual(spec.changelog_name, 'Myself <[email protected]> - 1.0-1')
self.assertEqual(spec.version, '1.0')
self.assertEqual(spec.release, '1')
self.assertTrue(os.path.exists(f"{pkg.specfile}.orig"))
os.unlink(f"{pkg.specfile}.orig")


class ControllerProjectTest(RiftProjectTestCase):
"""
Tests class for Controller
Expand Down