def test_new_actor(repository_dir): # We need the model to be created already if not repository_dir.join('models/testmodel.py').check(file=True): test_new_model(repository_dir) with repository_dir.as_cwd(): check_call(['snactor', 'new-actor', 'Test']) assert repository_dir.join('actors/test/actor.py').check(file=True) with pytest.raises(CalledProcessError): check_call(['snactor', 'discover']) repository_dir.join('actors/test/actor.py').write(''' from leapp.actors import Actor from leapp.models import TestModel from leapp.tags import TestTag class Test(Actor): name = 'test' description = 'No description has been provided for the test actor.' consumes = () produces = (TestModel,) tags = (TestTag.Common,) def process(self): pass ''') check_call(['snactor', 'discover'])
def test_new_topic(repository_dir): with repository_dir.as_cwd(): # We need the topic to be created already for the model # So we have to check if it wasn't already created if not repository_dir.join('topics/test.py').check(file=True): check_call(['snactor', 'new-topic', 'Test']) assert repository_dir.join('topics/test.py').check(file=True) check_call(['snactor', 'discover'])
def test_new_workflow(repository_dir): if repository_dir.join('workflows/test.py').check(file=True): # Test must have been run already return with repository_dir.as_cwd(): check_call(['snactor', 'workflow', 'new', 'Test']) assert repository_dir.join('workflows/test.py').check(file=True) check_call(['snactor', 'discover']) content = repository_dir.join('workflows/test.py').read() repository_dir.join('workflows/test.py').write('from leapp.tags import TestTag\n' + content + ''' class TestPhase(Phase): name = 'unit-test-workflow-phase' filter = TagFilter(TestTag) policies = Policies(Policies.Errors.FailPhase, Policies.Retry.Phase) flags = Flags() ''') check_call(['snactor', 'discover'])
def test_run_workflow(repository_dir): # We need the workflow to be created already if not repository_dir.join('workflows/test.py').check(file=True): test_new_workflow(repository_dir) with pytest.raises(CalledProcessError): check_call(['snactor', 'workflow', 'run', 'Test']) with repository_dir.as_cwd(): check_call(['snactor', 'workflow', 'run', 'Test']) check_call(['snactor', '--debug', 'workflow', 'run', 'Test']) check_call(['snactor', 'workflow', '--debug', 'run', 'Test']) check_call(['snactor', 'workflow', 'run', '--debug', 'Test'])
def test_ref_model(repository_dir): # We need the topic to be created already if not repository_dir.join('topics/test.py').check(file=True): test_new_topic(repository_dir) with repository_dir.as_cwd(): # We need the model to be created already for the actor # So we have to check if it wasn't already created if not repository_dir.join('models/a.py').check(file=True): check_call(['snactor', 'new-model', 'A']) assert repository_dir.join('models/a.py').check(file=True) with pytest.raises(CalledProcessError): # Now discover should fail due to the missing topic check_call(['snactor', 'discover']) repository_dir.join('models/a.py').write(''' from leapp.models import Model, fields, TestModel from leapp.topics import TestTopic class A(Model): topic = TestTopic referenced = fields.Model(TestModel) ''') check_call(['snactor', 'discover'])
def test_different_objects_same_name_discover(repository_dir): with repository_dir.as_cwd(): check_call(['snactor', 'new-tag', 'winteriscoming']) check_call(['snactor', 'new-topic', 'winteriscoming']) check_call([ 'snactor', 'new-model', 'winteriscoming', '--topic', 'WinteriscomingTopic' ]) objs = [ 'tags/winteriscoming.py', 'topics/winteriscoming.py', 'models/winteriscoming.py' ] for obj in objs: assert repository_dir.join(obj).check(file=True) out = check_output(['snactor', 'discover']) for obj in objs: assert obj.encode('utf-8') in out
def test_run_workflow(repository_dir): # We need the workflow to be created already if not repository_dir.join('workflows/test.py').check(file=True): test_new_workflow(repository_dir) with pytest.raises(CalledProcessError): check_call(['snactor', 'workflow', 'run', 'Test']) with repository_dir.as_cwd(): check_call(['snactor', 'workflow', 'run', 'Test']) check_call(['snactor', '--debug', 'workflow', 'run', 'Test']) check_call(['snactor', 'workflow', '--debug', 'run', 'Test']) check_call(['snactor', 'workflow', 'run', '--debug', 'Test']) test_clear_messages(repository_dir) connection = audit.create_connection('.leapp/leapp.db') assert len( audit.get_messages( names=('TestModel', ), context=context.last_snactor_context(connection), connection=connection)) == 0 check_call( ['snactor', 'workflow', 'run', '--debug', '--save-output', 'Test']) assert len( audit.get_messages( names=('TestModel', ), context=context.last_snactor_context(connection), connection=connection)) == 1 check_call(['snactor', 'workflow', 'run', 'Test']) assert len( audit.get_messages( names=('TestModel', ), context=context.last_snactor_context(connection), connection=connection)) == 1 check_call(['snactor', 'workflow', 'run', '--save-output', 'Test']) assert len( audit.get_messages( names=('TestModel', ), context=context.last_snactor_context(connection), connection=connection)) == 2
def test_new_tag(repository_dir): with repository_dir.as_cwd(): check_call(['snactor', 'new-tag', 'Test']) assert repository_dir.join('tags/test.py').check(file=True) check_call(['snactor', 'discover'])