Beispiel #1
0
def test_builder_raises_on_bad_action_name():
    # Does it throw an exception on a bad action name?
    with pytest.raises(AssertionError) as assertion_info:
        xml.WorkflowBuilder(
            name='descriptive-name'
        ).add_action(
            name='Action name with invalid characters',
            action=tags.Shell(exec_command='echo "test"'),
            action_on_error=tags.Email(to='*****@*****.**', subject='Error', body='A bad thing happened'),
            kill_on_error='Failure message',
        )
    assert "Identifier must match " in str(assertion_info.value) and \
        "Action name with invalid characters" in str(assertion_info.value)

    # Does it throw an exception on an action name that's too long?
    with pytest.raises(AssertionError) as assertion_info:
        xml.WorkflowBuilder(
            name='descriptive-name'
        ).add_action(
            name='l' * (tags.MAX_IDENTIFIER_LENGTH + 1),
            action=tags.Shell(exec_command='echo "test"'),
            action_on_error=tags.Email(to='*****@*****.**', subject='Error', body='A bad thing happened'),
            kill_on_error='Failure message',
        )
    assert "Identifier must be less than " in str(assertion_info.value)
Beispiel #2
0
def test_email():
    actual = tags.Email(
        to='*****@*****.**',
        subject='Chains',
        body='Do you need more?',
    ).xml(indent=True)
    assert tests.utils.xml_to_comparable_dict('''
    <email xmlns="uri:oozie:email-action:0.2">
        <to>[email protected]</to>
        <subject>Chains</subject>
        <body>Do you need more?</body>
    </email>
    ''') == tests.utils.xml_to_comparable_dict(actual)

    actual = tags.Email(
        to='*****@*****.**',
        subject='Chains',
        body='Do you need more?',
        cc='*****@*****.**',
        bcc='*****@*****.**',
        content_type='text/plain',
        attachments='/path/to/attachment/on/hdfs.txt',
    ).xml(indent=True)
    assert tests.utils.xml_to_comparable_dict('''
    <email xmlns="uri:oozie:email-action:0.2">
        <to>[email protected]</to>
        <subject>Chains</subject>
        <body>Do you need more?</body>
        <cc>[email protected]</cc>
        <bcc>[email protected]</bcc>
        <content_type>text/plain</content_type>
        <attachment>/path/to/attachment/on/hdfs.txt</attachment>
    </email>
    ''') == tests.utils.xml_to_comparable_dict(actual)

    actual = tags.Email(
        to=['*****@*****.**', '*****@*****.**'],
        subject='Chains',
        body='Do you need more?',
        cc=('*****@*****.**', '*****@*****.**'),
        bcc=set(['*****@*****.**', '*****@*****.**']),
        content_type='text/plain',
        attachments=['/path/on/hdfs.txt',
                     '/another/path/on/hdfs.txt'],
    ).xml(indent=True)
    assert tests.utils.xml_to_comparable_dict('''
    <email xmlns="uri:oozie:email-action:0.2">
        <to>[email protected],[email protected]</to>
        <subject>Chains</subject>
        <body>Do you need more?</body>
        <cc>[email protected],[email protected]</cc>
        <bcc>[email protected],[email protected]</bcc>
        <content_type>text/plain</content_type>
        <attachment>/another/path/on/hdfs.txt,/path/on/hdfs.txt</attachment>
    </email>
    ''') == tests.utils.xml_to_comparable_dict(actual)
Beispiel #3
0
def workflow_builder():
    return xml.WorkflowBuilder(
        name='descriptive-name'
    ).add_action(
        name='payload',
        action=tags.Shell(exec_command='echo "test"'),
        action_on_error=tags.Email(to='*****@*****.**', subject='Error', body='A bad thing happened'),
        kill_on_error='Failure message 😢',
    )
Beispiel #4
0
def test_builder_raises_on_multiple_actions(workflow_builder):
    # Does it raise an exception when you try to add multiple actions?
    with pytest.raises(NotImplementedError) as assertion_info:
        workflow_builder.add_action(
            name='payload',
            action=tags.Shell(exec_command='echo "test"'),
            action_on_error=tags.Email(to='*****@*****.**', subject='Error', body='A bad thing happened'),
            kill_on_error='Failure message',
        )
    assert str(assertion_info.value) == 'Can only add one action in this version'
Beispiel #5
0
def test_builder_raises_on_bad_workflow_name():
    # Does it throw an exception on a bad workflow name?
    with pytest.raises(AssertionError) as assertion_info:
        xml.WorkflowBuilder(
            name='l' * (tags.MAX_NAME_LENGTH + 1)
        ).add_action(
            name='payload',
            action=tags.Shell(exec_command='echo "test"'),
            action_on_error=tags.Email(to='*****@*****.**', subject='Error', body='A bad thing happened'),
            kill_on_error='Failure message',
        )
    assert "Name must be less than " in str(assertion_info.value)